3 ms·
If language has primitives for some concepts then people tend to use those because they have special syntax that makes using them more convenient. For example
by scotty79 11y ago
If language has primitives for some concepts then people tend to use those because they have special syntax that makes using them more convenient.
For example if language has special syntax for numbers people tend to use number as type of account (or string for contact person). Then when software evolves and new information needs to be kept for account and new operations performed the shorthand syntax stands in the way. You can't easily change the type of account from number to complex object without refactoring all of the places in your code where account was used as number. (I'm ignoring languages with overridable operators to make the point).
People tend to obsessively stick to built in stuff (anti-pattern Primitive Obsession) because swapping for what they need now is excessive burden.
What I would very much like to see in languages development is that whenever the syntax gets introduced programmer should be able to use it on more complex things then the syntax was primarily designed for.
If you introduce syntax for operators don't make them work just for few built in types. If you introduce async/await don't make them just work on promises (especially not just built ins) but anything that is shaped like a promise. If you introduce generators make sure that they programmer can implement persistable version of them with the same syntax.
- esailija 11y agoAsync/await doesn't only work on promises, it works on any object that has a method named `then`. What's problematic is that you have no control or extension points in the runner so you cannot implement something like Go's defer statement. With generators (which can be made work like async/await, only you say yield instead of await) you can implement the defer statement and more.
- scotty79 11y agoGood that it works on any object with then. Shame that it's not more flexible. What I said was more general argument about what each new syntax should support at minimum. What you are saying is like having operator overload, but not ability to define new custom operators, or not being able to define 3 or more arguments operators or default arguments for operators, or quoted arguments for operators. Or regretting that C# foreach works on every Enumerable but takes every item one after another (preventing from implementing collection that would have parallel behaviour with foreach) It's good if you can do a lot with new syntax but that's nice to have and case by case. What I was talking about I consider general and pretty much mandatory. Lots of people feel that if you look at the piece of code you should be immediately be able to tell what it's doing without any context. It's intuitively attractive goal but I think that most measures that achieve that also result in putting obstacles in software usual evolution making people do very contorted things when they need to add yet another feature with limited time.