Hacker News new | past | comments | ask | show | jobs | submit login

I really wish this book used something other than Java. Nothing against Java - just that I don't know it and don't feel excited about learning it.



For what it's worth, these days you could use an LLM to turn each code snippet into many other languages.

Or just focus on his words and use the snippets like generic code and figure out how to do it in whatever language of choice.

You don't need to "learn java" to become conversant or read it as pseudocode.


That's great advice. Thank you!


The Java it uses is basically understandable regardless of what language you're used to.

I guess if you're extremely early in your career and have never written anything but Python, it might not be, but if you've ever touched any statically-typed language and a language with a somewhat C-like syntax, you should be fine.


Lots of people have done implementations in other languages: https://github.com/munificent/craftinginterpreters/wiki/Lox-...

I did the first half in Clojure (in order to teach myself Clojure), worked just fine. I had to do a bit of translation but it's really not a lot.


I find it’s the best way to work through these types of books - otherwise I tend to just copy the code mindlessly. Doing the exercises from a book in another language forces you to consume the semantics of it better.

I did the Torsten Ball books in Kotlin rather than Go and learned a lot


I’m glad it used Java. I wound up rewriting the code in Python and it really helped me understand the concepts a lot better.


What other languages do you know? If you know something with similar enough syntax (C++, C#, Javascript, etc.), even if the semantics aren't the same, you should be ok getting the basic idea of the Java code in the book, especially considering how he explains things as you go.

Then just write it in whatever language you want. When I went through the first half of the book back in 2017, I wrote it in Scala. (I did know Java, too, though, so certainly I had an easier time understanding the code examples in the book.)


I started reading the book after reading similar suggestions in the thread.

I know JavaScript and a bit of C and I'm not having much trouble understanding the Java code.


Don't use Java then. The Java bits are just an example, you can write it in any language you want.


Java is pretty readable, as long as your familiar with C-style languages you shouldn't have too many problems rewriting this in another language.


When Java gets pattern matching, it will become a more reasonable choice to write an interpreter in.


+1. When I was following along in the book I wrote the interpeter in C#, and pattern matching allowed me to basically skip needing the code generator and the visitor pattern. YMMV but its great. Essentials of Compilation by Siek does a similar trick with python.


It’s had pattern matching since 16, it’s been expanded since with some syntactic sugar and more recently the introduction of sum types and exhaustiveness to go along with pattern matching.


IMO Java's pattern matching is still fairly primitive. Not even up to the level of usefulness of Scala 2.13.


Interesting - what specifically is missing? I’m thinking we’ve got all of scala’s pattern matching since JEP 406 (2021) but I don’t write Scala so there’s maybe a feature i don’t know. Would be interested to know.

    switch (thing) {
        case Integer i when i > 0 -> println(“Positive…”);
        case …
    }


I think there should be a second edition of this book then :)


It does. The second half is written in C. Java is just used for the simplified first part.


Java is incredibly readable. I don't care for writing Java either but reading the first part but implementing it in c# was incredibly easy (and also ensured no copy/pasting).


You can do the second part that is C!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: