4 ms·
> It's the same with a programming language: if it's designed too spartan, I have to write too much code that is always similar, which causes effort and obscure
by ebingdom 4y ago
> It's the same with a programming language: if it's designed too spartan, I have to write too much code that is always similar, which causes effort and obscures the real intention of the code.
I think Go is the perfect example of this. On paper, it's a simple language. But:
- Not having sum types means it's awkward and unsafe to express concepts such as "X or Y". This is a big deal, because "Result or Error" is one of the most common ideas we have to deal with in programming. I think this tweet visually captures the awkwardness: https://twitter.com/GabriellaG439/status/1521860707444133888 https://twitter.com/GabriellaG439/status/1521860707444133888. Another place this shows up is pointers: in Go, since there is no way to represent "present or missing" at the type level, Go has to bake that possibility into the semantics of pointers. The billion dollar mistake.
- Every type in Go has a "zero" value. On the surface, this seems simple: when you declare a variable, you get a predictable value without having to explicitly initialize it. But this prevents you from implementing abstract data types which are guaranteed to be constructed by a smart constructor that establishes all the relevant invariants. Now you always have to worry about this zero value, since it might not satisfy the invariants of your data structure (consider the simplest data structure with an invariant: a pointer which is non-null!). Also, you can easily forget to set a field in a struct, which means the zero value will show up in unexpected places (resulting in subtle bugs that might go undetected even at runtime).
- Until recently, Go didn't have generics. Simpler, right? But that means if you want to build a reusable data type, you needed to either (a) make N copies of it, being careful to keep them in sync, with no help from the compiler, or (b) sacrifice type safety and represent data as interface{} (essentially a void* pointer), adding dangerous casts all over the place.
Languages like Haskell and Rust are more complicated than Go. But once you've paid the upfront cost of learning them, common programming patterns actually become simpler.
Of course, there's a flip side to this. Most languages have a lot of accidental complexity too, which isn't what my argument is about. So I almost hesitate to make this comment, fearing that it will be quoted out of context to justify adding badly designed features to programming languages.
- Rochus 4y agoIn this case, you will not enjoy Oberon+, although it supports (lean) generics. This shows that the view of what is minimal and optimal is ultimately also strongly subjective, which is actually not surprising.
- loup-vaillant 4y agoOberon was designed in a very different context though: its goal was not to have a gazillion users, it was to build one system, that by the way happens to fit in 10,000 lines of code, compiler included. In such a small system, the benefits of any feature are much smaller. Let's say you have some feature that could simplify your program by 1%. Over 10,000 lines of code that means save 100 lines of "complexity". If implementing that feature takes more than 100 lines, your small 10K lines system will end up more complex, not less. Go however is fairly widely used. Simplifying by 1% on average is huge, and likely worth it even if it requires 10,000 lines of code all by itself.
- Rochus 4y agoNote that I'm talking about Oberon+ (see http://oberon-lang.ch http://oberon-lang.ch), not the good old Oberon (which has no generics at all); but also the latter was conceived as a general purpose programming language; it was its fate that Wirth and Gutknecht built an operating system with it first and there was a compiler only for that operating system, which was not ideal for the spread of the language. Go is the most famous offspring of Oberon so far.
- michaelcampbell 4y agoThis is a good overview of my thoughts on it. A few years ago I had a number of colleagues flogging the "I love Go, the code flies from my fingers!" drum, but I didn't get it. Yeah, you know what you have to type but in a more expressive language you don't have to type it at all! It felt like they were making the "Don't mistake motion with action" mistake. But, people can like what they like, it's all good.