3 ms·
I've always taken a particular joy in "Writing code like Language A in Language B" I like Java as a host language to do things like: Write numerical codes in
by PaulHoule 2y ago
I've always taken a particular joy in "Writing code like Language A in Language B"
I like Java as a host language to do things like:
Write numerical codes in FORTRAN style, allocating a few big arrays at the beginning and not pressuring the garbage collector. This is how I'd write an FFT, matrix inversion, or something like that.
Write programs with very few class definitions but a large number of static methods. (Like any non-OO languages, but static methods can go nicely with a few well chosen classes you make instances of)
Write static methods that take instances of "Object" as a parameter that are inspired by an algebra like that for a language like Python (of course a Collection is treated special, etc...)
Use static methods to build up structures like LISP's S-expressions.
These tactics can be used, for better or worse, to write Java DSLs that appear to describe "business rules" in plain English with the caveat that things like that are never as easy for muggles to maintain as you wish they were.
- devin 2y agoI also find that it's a nice exercise on the way to learning a new language. I spend a lot of time in Clojure, so I'll ask and answer "okay where are the lambda-like things, how do I apply them over collections" and then write up something I know is not at all what the language designer intended for kicks. As an added bonus, it is fun to show your work to a coworker proficient in the target language and watch the blood drain from their face.