5 ms·
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.
by alabhyajindal 2y ago
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.
- snats 2y agoYou can do the second part that is C!
- jasonjmcghee 2y agoFor 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.
- alabhyajindal 2y agoThat's great advice. Thank you!
- bluedays 2y agoI’m glad it used Java. I wound up rewriting the code in Python and it really helped me understand the concepts a lot better.
- grumpyprole 2y agoWhen Java gets pattern matching, it will become a more reasonable choice to write an interpreter in.
- CraigJPerry 2y agoIt’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.
- grumpyprole 2y agoI think there should be a second edition of this book then :)
- kelnos 2y agoIMO Java's pattern matching is still fairly primitive. Not even up to the level of usefulness of Scala 2.13.
- CraigJPerry 2y agoInteresting - 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 … }
- zengid 2y ago+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.
- Derbasti 2y agoIt does. The second half is written in C. Java is just used for the simplified first part.
- miki123211 2y agoThe 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.
- dukeyukey 2y agoJava is pretty readable, as long as your familiar with C-style languages you shouldn't have too many problems rewriting this in another language.
- WJW 2y agoDon't use Java then. The Java bits are just an example, you can write it in any language you want.
- SatvikBeri 2y agoLots of people have done implementations in other languages: https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations 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.
- wuiheerfoj 2y agoI 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
- deleted 2y ago[deleted]
- runevault 2y agoJava 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).
- kelnos 2y agoWhat 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.)
- alabhyajindal 2y agoI 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.