4 ms·
> fn add(x: Int, y: Int) -> Int Why do language authors insist the majority of programmers want to type this way? Meaningless arrows and redundant colons. Is
by pipeline_peak 2y ago
> fn add(x: Int, y: Int) -> Int
Why do language authors insist the majority of programmers want to type this way? Meaningless arrows and redundant colons.
Is it constructive, like it will lead us to think differently? It feels more like a contest in overcomplicating something as innocent as:
int add(int x, int y)
- mkehrt 2y agoThe answer is this is how theoretical programming languages have done it since the 1920s, borrowing from the mathematical notation of the time. As programming language theory has made more inroads into practical programming languages in the last 10-20 years, newer languages have borrowed the notation. I'm biased, having been immersed in PL thoery for a while, but I prefer the colon notation. It works better with type inference, for example. Consider declaring a variable in two ways: var x: int = 3; // Now add type inference var x = 3; Vs int x = 3; // Now add type inference var x = 3; // We've just changed the type to a keyword and that's weird. But that's just a personal preference.
- bmacho 2y agoI don't like how symmetrical the type theoretical colon denotation is, compared to the regular "element" notation. (They are more or less the same.) If instead of F : A -> B we wrote F ∈ A -> B (or any other not symmetrical character) then we could flip it, and use A -> B ϶ F, and B <- A ϶ F too.
- deleted 2y ago[deleted]
- giraffe_lady 2y agoI think there's a pretty good case for the arrow being easier to reason about especially with anonymous functions or if currying gets involved. The other way is lacking a "verb" and it becomes harder to keep track of what's going on in some cases. The arrow is also conventional in ML family languages, which are a venerable branch of programming whose traditions I respect and enjoy. That's not enough reason alone to keep it maybe but it's not nothing either. The colon thing whatever, I truly just can't bring myself to care about such fine-grained specifics of syntax. It sounds like a rough life honestly.
- mcintyre1994 2y agoI think it’s because generally the type annotations are optional and it’s much easier to parse that version. Typescript uses a colon instead of arrow for the return type so I think that’s just preference though. In particular if you removed the types from yours it’d be add(x, y) and the parser wouldn’t be able to distinguish that from a function call. I think that’s why the fn keyword is really useful for the parser.
- lpil 2y agoIt’s so they are readable left to right, which is typically easier. The difference can be seen most clearly with writing the type of functions as arguments.
- bmacho 2y agoNo, they both read equally "left to right". What GP asks, why "a : A" instead of "A a" and "fn -> A" instead of "A fn" has billions of right answers, but "readable left to right" is not one of them.