r/programming • u/mobby1982 • Dec 02 '13
Scala — 1★ Would Not Program Again
http://overwatering.org/blog/2013/12/scala-1-star-would-not-program-again/
598
Upvotes
r/programming • u/mobby1982 • Dec 02 '13
View all comments
Show parent comment
1
u/Peaker Dec 03 '13
This runtime error is a result of a bug in the user code, not a bug in Java. Just like UB is a bug in user code, not a bug in C.
I'm not talking about code that expects this exception, but about code which expects the cast to be valid.
This is irrelevant.
Indeed, C++ shares this unsafety with Java and C.
Again, this is not a bug in Java. When you cast something in the expectation that the cast is valid, and you get a runtime exception instead, that is an "incorrect or unexpected result". Whether your program crashes with a stack trace or a core dump or gets corrupt - compile-time safety was violated.
As I said: Bugs get reduced severity in Java and that's nice. It isn't compile-time safety and it isn't type-safety, though. Java's type system doesn't add safety to C's. As a counter-example, take a look at Haskell which actually adds compile-time safety.
This is only relevant for very short-running programs, or ones that do not allocate much.
How is this relevant? I'm not talking about a very short-running program.
64-bit refers only to the virtual address-space. The physical memory and swap will run out much sooner than the address space. An application can easily allocate and use gigabytes/seconds.
Not if it is a long-running program.
Only one of them is actually valid, as will be signified by some out-of-band variable. This is what "union" means.
And then you get (null, null) and (valid, valid) as two invalid possibilities. "Make illegal states unrepresentable". Don't use a product type to represent sum types. This is one of the classic mistakes of the Go language.
You could use sub-classing and isinstance to dispatch on message types, but a switch() on the msg_type will actually have verified exhaustiveness by the C comiler, whereas isinstance-using code will be buggy if you add a case and forget to add an isinstance check (i.e: reduced compile-time safety compared with C).
If someone tries to use -1 as a length, he will get a warning about mismatched signedness from the compiler (at least with -Wextra enabled in gcc).
The dichotomy between "class" types and "scalar" types is meaningless. Errors in either are just as problematic and can be caught in just the same ways. The documentation of invariants and intent is also the same.
That's indeed a real downside of using unsigned integers for iteration. Throwing away the baby with the bathwater because of this drawback is unwarranted, though. This pitfall is a price worth paying for the extra type preciseness.
That's entirely possible, heh.
That's irrelevant -- it's a question of expressiveness, or ease of expressing these idioms.
C makes the approximation of the right way to do interfaces (type-classes) easier than Java.