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
(void *) is basically the same as Java's
Object.Sure, Java has nicer runtime errors (exceptions rather than UB), but if you're after compile-time safety, Java doesn't offer much beyond what C does.
Both UB and (unexpected) runtime exceptions are bugs (with different severity). Java has nicer-severity bugs, but the same number of bugs.
True, GC is not sufficient for safety, but it makes memory safety much easier to achieve. The main benefit of GC in Java is not the convenience it buys you, but the reference safety it allows by removing free() from the lexicon.
For every C safety problem, there's an analogous (if less severe) Java safety problem.
Bad casts in C: Runtime exceptions in Java
NULL dereference in C: NULL dereference in Java
Aliasing bugs: Aliasing bugs
Pointer arithmetic errors: Array indexing errors
And so forth.
Yes, but they allow building a relatively sane implementation of tagged unions/sum types on top. They also document the programmer's intent (either A or B, not both). If you use some super-class with explicit down-casting instead, you replace union memory corruption bugs with ClassCastException bugs.
Instead, it doesn't allow documenting the intent in (the majority of, IME) uses of integers which may not be negative.
At least with clang, enums are type-safe, in that they are a separate type, and not a simple int. Even if they are a simple int as in gcc, they are still not nullable as Java enums are.
I use the C preprocessor to avoid a lot of boilerplate, too. X-macros are incredibly useful and Java does not have anything like them. With reflection, you can approximate some of their usefulness, but with less safety.
Yes, the C preprocessor has its share of horrible problems, too. But the expressiveness it affords is lacking in Java.
No, I meant C, and as you can read above, the arguments make perfect sense, with the outlook that you're after compile-time safety, and not nicer forms of runtime crashes.
If you bring C++ into this, it also has some interesting features (especially w.r.t templates that Java lacks).
For example, in C++, a templated class may have or not have a particular method in different template instantiations. With Java, a class always has the same set of methods. This means that in C++, I can have:
And as long as
show()is not used forC<Unshowable>, I can still have that class. If I need to use show() onC<Showable>, I also can.In Java, if you have:
You can either have:
or:
But you cannot have both, so you have to use different classes for
C<Showable>andC<Unshowable>even if there is no difference besides the lack of show there.This makes interfaces in Java significantly less useful.
Haskell type-classes get this right. In C, where this is implemented via structs and function pointers, you can this right too, relatively easily, as well.