4 ms·
> A static type system has one purpose: to prevent you from running unsafe code. Every type error is just the compiler telling you "what you wrote isn't going t
by bmacho 4y ago
> A static type system has one purpose: to prevent you from running unsafe code. Every type error is just the compiler telling you "what you wrote isn't going to work". This isn't a fight; it's a conversation. You write some code, run the compiler, get back some errors, fix them, and run the compiler again. This process is repeated until your mental model of how the code should work is properly reflect in the code, as determined by the success of your compiler's type-checking.
That's not true. Java or C++ force you to type out the types every time to
- place constrains inside your program (both the caller and the called side)
- be explicit about it (if anyone else wants to read your code later)
E.g x = 5, y = 6, x+y does work in many languages. (Untyped languages, or languages with type inference.)
It is an unambiguous command, and many languages would just do what you say, instead of forcing you to write code in a particular way that has absolutely no use for you.
Being said, I absolutely love Haskell's function type notation ( f :: A->B f x = doSomeThing x ), its type inference, and how easy it is to alias types. I want this notation in every other languages please.
- jjnoakes 4y ago> E.g x = 5, y = 6, x+y does work in many languages. (Untyped languages, or languages with type inference.) > It is an unambiguous command, and many languages would just do what you say It isn't so unambiguous when you use x = 230 and y = 30 for example...
- BeetleB 4y ago> That's not true. Java or C++ force you to type out the types every time to That's not true for C++, with the auto keyword, which was a God send and made the code a lot more readable. Strongly static languages like the ML ones are like having auto on drugs. If you like auto in C++, you'll like these languages. If not, you won't.
- DonaldPShimoda 4y ago> That's not true. It is unclear to me which part of my comment is "not true". Could you elaborate? > E.g x = 5, y = 6, x+y does work in many languages. > [...] > It is an unambiguous command It is absolutely not unambiguous; you only think it is because it happens to work the same way in most languages.