3 ms·
I did some hacking on a "Homoiconic Java", enough to generate stubs for Java's standard library. Some tests are here https://github.com/paulhoule/ferocity/bl
by PaulHoule 3y ago
I did some hacking on a "Homoiconic Java", enough to generate stubs for Java's standard library. Some tests are here
https://github.com/paulhoule/ferocity/blob/main/ferocity-stdlib/src/test/java/com/ontology2/ferocity/stdlib/TestStreams.java https://github.com/paulhoule/ferocity/blob/main/ferocity-std...
The idea is you can build up an AST with a DSL and then either generate Java code that gets fed to Javac or execute the code with a tree-walking interpreter. One thing I discovered was that there is quote and eval so an interpreter has an extended type system over Java because it is possible to construct an Expression<T> (always immutable) and then eval it.
The plan was to use ferocity0 as a library to support the stub generator, then use the generated stubs to write ferocity1 in ferocity0 and possibly a ferocity2 in ferocity1. The idea is that the code would be awkward to write without templating because you have to repeat a lot of things for 8 primitive types so I want to write as much of ferocity as I can in ferocity. (My analysis is that some recent features that involve type inference such as switch expressions would run into problems w/ type erasure that I don't know how to solve but it ought to be possible to implement a "complete" set of operations and apply syntactic sugar of various types on the ferocity side.)
I also made a functional programming library which is greatly simplified compared to streams which would really benefit from code generation, for instance
https://paulhoule.github.io/pidove/apidocs/com/ontology2/pidove/util/Curry.html https://paulhoule.github.io/pidove/apidocs/com/ontology2/pid...
could be extended with higher-arity methods than it has but I am not writing them by hand so if I ever finish ferocity I plan to write a new version of pidove.
- kagakuninja 3y agoOr you could use Scala
- PaulHoule 3y agoI did a couple of projects where I'd pick up a broken Scala system and fix it, it was usually "screw around for a week in Scala and it (1) still has race conditions and doesn't give the same answer every time, (2) has totally busted error handling (they seemed to think saying the word 'monad' meant you didn't have to think about error handling) and (3) used at most 2 CPUs out of 8." Rewriting it in Java with ExecutorService would solve all those problems in like... 20 minutes. But yeah, I think a lot of people would think Ferocity combines all the awful things about Java (verbosity) and Common Lisp (the "write once never edit" problem of metaprogramming)
- kagakuninja 3y agoThat's funny, because I've been taking servers full of large blocking thread pools, rewriting them to be non-blocking, idiomatic Scala, Cats Effect 3 and get +50% throughout. Blocked threads are seriously bad for performance. Yes, Java 21 project Loom will help with that (finally), if people get with the program. There aren't any race conditions, because our classes and data model are fully immutable. The problem with our legacy servers was that the original devs didn't know what monads were, and decided not to use them. Error handling is now great, by using... you guessed it, monads.