Hacker News new | ask | show | jobs
by andrewchambers 4254 days ago
The value of static typing is more and more apparent. Recently I've played with ocaml and F# and it felt great compared to Java or C++.
3 comments

C++ and Java are statically typed. If you're referring to dynamic polymorphism, then yes, it can be a pain in the ass.
I'm aware they are statically typed, I meant it in reference to people who hate static typing based on their opinions of Java and its relatives.
Aren't Java and C++ statically-typed as well?
> Aren't Java and C++ statically-typed as well?

Yeah, but not so you'd notice, coming from an ML or Haskell background. /sarcasm

More seriously, Java and C++ (and C and Algol before them) fell into the trap of defining "data size specifications" as types: The discontinuity between "long long int" and "int" is one, as is the discontinuity between "float" and "double".

The real type difference is between things which are semantically different, like "numeric value used to represent age in years, rounded to integral value", "numeric value used to represent age in days, rounded to integral value", and "numeric value used to represent weight in pounds, rounded to nearest hundredth". Foogol (Algol-derived) languages largely only got this when they embraced Smalltalk-style OO, and they kept their size specification pseudo-types, just to muddy the issue.

Size specifications are useful when defining a wire protocol where the overhead of reading and writing an ASCII format with non-trivial syntax would kill your application, such that you need network-header style bits-on-the-wire protocol, and in file formats with similar constraints, but they're ultimately a low-level implementation detail.

The way this interacts with tooling like editor autocomplete is that editors can do more for you when they know what kind of data you're passing around, as opposed to just how big it is and other trivialities.

It is not a "trap". In "C" it is required to generate fast machine code. It's a trade-off, not a "trap".
C (note lack of quotes) and Haskell regularly trade off "Fastest language in the world" spots on shootouts. Maybe "C" (with quotes), which is obviously a different language, is faster; I doubt it.
No they don't, Haskell is anywhere from 2-6x slower at the same problems. http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?t...
... until you start trying to make your app testable.

(I say this as a developer of primarily statically typed languages.)

Try using a good type-inferred statically-typed language. Hint: this rules out Java, C# etc.
Could you elaborate?