4 ms·
Syntax and sugar is subjective, right? Instead, easier to discuss the layer beneath syntax, and that’s to compare the type systems. Java now has some version of
by belmont_sup 3y ago
Syntax and sugar is subjective, right? Instead, easier to discuss the layer beneath syntax, and that’s to compare the type systems. Java now has some version of sum types aka algebraic data types, but because of its beginnings, it may never feel as easy to use. And ease of use is important, as is evident from discussions here.
Had to look up to see where Java is at for sum types. First link I found.
https://sfietkonstantin.github.io/2021/09/03/Java-sum-type.html https://sfietkonstantin.github.io/2021/09/03/Java-sum-type.h...
- riku_iki 3y agosum types is not something supercritical, it saves few lines of code. Also, somehow I rarely have need to use something like that personally. > And ease of use is important the question is if insignificant syntax sugar worths switching to unpopular platform with undeveloped toolings and uncertain support.
- yawaramin 3y agoSum types save more than a few lines of code, they can save you from nasty bugs thanks to exhaustiveness checking in pattern matches. Once you get used to this you will be hard pressed to go back to prehistoric times.
- riku_iki 3y ago> Sum types save more than a few lines of code, they can save you from nasty bugs thanks to exhaustiveness checking in pattern matches. do you have specific example?
- yawaramin 3y agoLook at this code which prints out an HTML tag: https://github.com/yawaramin/dream-html/blob/main/lib/dream_html.ml#L39 https://github.com/yawaramin/dream-html/blob/main/lib/dream_... Initially you might think generating HTML tags from data structures in code should be a simple matter. But there are complexities--some tags are defined as having no child tags, others do. Some tags are purely character data (unstructured text), not structured data. Some are just comments. We need a way to compose multiple tags together into a single 'virtual' tag for flexible HTML generation. All these conditions can be pretty hard to keep track of--unless your compiler does exhaustiveness checking. Then the compiler will tell you if you missed any cases. In the example above I didn't make any manual effort to cover all the cases, I simple listed out the cases I wanted to handle in order. The compiler made sure that I didn't miss any.
- never_inline 3y agoThis is very specific case though. Many times compiler tooling will do just fine with good old visitor patterns, enums etc.. Sure there may be small amount of errors missed, but that's not always as critical as availability of libraries and integration.