4 ms·
Rust has strong static typing but it also has very powerful type inference, I think it fails to fit in your dichotomy.
by MiguelX413 4y ago
Rust has strong static typing but it also has very powerful type inference, I think it fails to fit in your dichotomy.
- galangalalgol 4y agoAgreed, and Julia is in an odd spot as well. The type inference combined with JIT and dispatch act make for strong dynamic optional typing vs rusts strong static inferred typing.
- josephg 4y agoRust’s type inference still requires you to manually specify the input and output types of every function. I think it’s clearly in the camp of “all types must be specified by the programmer / you get compiler errors”. The GP asked what’s the point of languages like this. The two massive advantages in my mind are that compiled programs are usually correct, and compiled programs run really fast. I often have the experience in rust of writing hundreds of lines of new code, and my program works perfectly the first time I run it. That’s a delight.
- masklinn 4y agoThe decision to require explicit global type annotation in Rust has nothing to do with "compiled programs are usually correct, and compiled programs run really fast", you can do that with global type inference. It has to do with documentation, intent, and clarity. Also clarity of error messages, compilation errors with generic functions under GTI are as bad as C++ template errors.
- CoastalCoder 4y ago> It has to do with documentation, intent, and clarity. I wish it were common [0] for source code to show a combination of programmer-specified and compiler-deduced details. Seems like we could get the best of both worlds. [0] I know some IDEs show e.g. type information as mouse-over text. I'm talking about something that integrates more cleanly into the actual source-code text. So, e.g., it would show up when diff'ing the source code.
- cxr 4y agoSee <http://cr.yp.to/qhasm/literature.html http://cr.yp.to/qhasm/literature.html>
- lisper 4y ago> compiled programs are usually correct This is absolutely false. Compiled programs might be correct with respect to type safety, but that is very different from being correct. There are all kinds of ways that programs can fail besides type errors. In fact, this widespread false belief is IMHO one of the strongest arguments against using enforced-compile-time-strong-typing because it lulls you into a false sense of security. I have a long list of war stories where this led to problems that ranged from annoying to very nearly catastrophic.
- josephg 4y agoOf course there’s lots of ways a compiled program could still be incorrect. But in my experience (having spent years with both languages) the practical per-line error rate of rust code I write is many times lower than my per-line error rate in javascript. (And typescript is somewhere in the middle for me). Yes, you still need tests. But testing is never perfect. Bugs still slip through. I like not needing to be as paranoid in rust as I am in other languages.
- masklinn 4y agoThey cite haskell which, if anything, has even stronger static typing and more powerful type inference (because the rust devs decided to favour explicit clarity and removed global type inference). And as GHC actually has a compilation mode where it only warns about compilation errors: https://gitlab.haskell.org/ghc/ghc/-/wikis/defer-errors-to-runtime https://gitlab.haskell.org/ghc/ghc/-/wikis/defer-errors-to-r... So they're 0/2, on the subject they're espousing upon, through a language they mentioned.