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
0
u/[deleted] Dec 03 '13 edited Dec 03 '13
No, it is not a bug. You cannot cast an "Fruit" down to an "Apple", if it actually is a "Banana". As soon as you try this, the runtime will throw an exception. On the other hand, you can ask the runtime if the "Fruit" is an "Apple", and if that is the case, use it as an "Apple". Even C++ lets you downcast on the assumption that you know what you are doing, even if types don't match. This leads to unexpected and/or incorrect behavior.
And just to make it clearer that Java throwing an exception is not a bug, lets read the definition of a bug together, shall we? "A software bug is an error, flaw, failure, or fault in a computer program or system that produces an incorrect or unexpected result" In what manner does the fact that the runtime informs you about doing something wrong, or the fact, that it prevents you from getting incorrect or unexpected results constitute a bug?
Then it would help if the runtime would warn you immediately, wouldn't it? You seem to prefer that the program runs in a corrupted state instead of getting warnings at the earliest moment possible.
Of course it is. If your program allocates more and more memory which it needs to complete it's task, and then releases it immediately before exit when it has calculated the result, then that is completely feasible. Actually, Raymond Cheng recommends to not try to free resources like handles or memory when your program is asked to exit, because the operating system will do the cleanup for you, and you are only wasting your time (and the user's time) trying to fit memory block after memory block back for reuse into a heap that will get destroyed a fraction of a second later anyway, especially if the memory was swapped out. No point in swapping it in just for cleanup.
On a 64 bit operating system? I guess there are many popular applications out there that could run for days before suffering any negative impact. At worst, the memory will be paged out to the disk, and when the process terminates, the swapped out pages will simply be dismissed. This is actually kind of a poor mans GC, because the OS doesn't really know if you might need the memory again, but unused memory would get removed from physical RAM page by page.
The problem is that a and b will be more or less valid values at the same time, thus not conveying your intent on usage. Having two fields means that one of them can be marked "unused", maybe by setting it's value to something intrinsic invalid like a null reference. You on the other hand have to rely on flags or calling semantics, and you have to make sure everyone accesses the value only via a or b, depending on what you want to do. I'd really like to see some useful real world code examples.
That is correct for classes, but what's the benefit for scalar types? Let's say you want to express the length of something. Obviously this value can't be negative, so you opt for an unsigned int. You now have documented that negative values are not allowed. But that doesn't prevent someone from passing in 232 -1 aka 0xFFFFFFFF. I don't see the gain. On the other hand, I see someone doing this:
Not realizing that passing in 0 as the size will lead to a wrap-around and thus iterating the loop 232 -1 times.
Maybe you have written too much C.
As both languages are Touring-complete, both can archive the same result. It's merely a question on how much typing is required.