The conditions you are asserting must be tested as rigorously. You are picking up where the compiler leaves off.
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
You're right, you're using runtime safety where compile-time type safety cannot be used. I use the term "cannot" here because the language does not allow it, or if it does, it is so vastly misunderstood, that most developers don't know how to apply it. For example, the very existence of 'null' violates the very fundamental objectives of the Java programming language; that is, compile-time type safety. What do you do if you're passed a null reference to a public API? You're forced to handle it at runtime, optimally, with immediate failure (e.g. NullPointerException).
(While on the topic, and to answer Ilja's question on another forum regarding the language... without going into too much detail, it is a type-safe object oriented language specification and API specification that doesn't have a primary agenda of repairing the thousands of mistakes of Java/C#/LISP/Smalltalk/Scheme, but does so as a mere consequence. To fully answer your question, I'd prefer to present you with the API specification, which is incomplete (to be honest, is mere scratch notes in a friend's SVN repos). The language and API specification are bound (dependent) at well-defined points, but there is no dependency on a bytecode representation specification. This means that the language can compile to JVM bytecode, .NET bytecode, native bytecode, etc.). The language is vastly different to Java, much simpler, and I predict much easier to learn and use. I theorise in this way because most of the Java that I write is working around its brokenness, which is extremely annoying.)
In any case, that Java is an extremely suboptimal example of a type safe language aside, the very existence of the assert keyword again violates the same objective.
It makes no sense to have "fail early, but only when I switch it on". The optimal place to fail is at compile/build time. If you cannot do that for whatever (and it better be good) reason, you fail *immediately* at runtime.
I hope this is enough explanation to satisfy those requesting it.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Rick O'Shay:
>> Anyway, I don't think that having bugs being concealed and hoping for the best is very professional.
In addition to the mountain of best practices I am adding asserts with rigorous unit tests. What you are suggesting is that regardless of how well you build your system and how rigorous your testing, if you turn off asserts it's unprofessional.
In fact disabling is the recommended practice.
You can do that without killing a user's thread when a constraint violation slips through the cracks. I think that is the point of contention. Is it better to crash the thread or continue on? In the case of assertions (keeping in mind we still have all of the business logic and exceptions) the consensus appears to be continue. I agree it is not a cut and dried issue.
>> When when disabling the assert, the problem is still there, it's just not as visible.
Of course. Nobody disputes that. See previous paragraph.
You have to have your business logic to take care of expected "errors" and exceptions for unexpected environmental errors. The assertions test errors that the programmer makes that are outside the scope of the compiler. If the unit test fails the build fails just as hard as some source not compiling.
>> Yes. My argument is that disabling asserts doesn't make a product more robust. It just conceals problems
If you fail to adequately test then we agree. Testing and asserts are inextricably bound.
>> It still seems to me that "turn all on" could be the default without affecting the other two use cases at all.
Agreed, as long as you have the option of turning them all off, too.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ernest Friedman-Hill:
Not to hijack too much, but Tony, tell us what language (real or imaginary!) you'd program in, given a perfect world? Of all the Java experts I know, you seem to be the one that likes Java the least...
Tony Morris
Java Q&A (FAQ, Trivia)
Tony Morris
Java Q&A (FAQ, Trivia)
Tony Morris
Java Q&A (FAQ, Trivia)
I have read many of your posts and yet to find a concrete example of a flaw and its coresponding drawbacks. All I see is 'philosophizing.'
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Rick O'Shay:
Perhaps consensus is the wrong word but the recommended practice is to turn off in production. I agree with that recommendation.
I see a danger of using them like exceptions when they are not. I see a danger of side effects bleeding through assert statements and changing runtime behavior.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Rick O'Shay:
Back up to 1.3 when you didn't have asserts. How would this issue manifest? How would it be handled?
Your strategy will toast threads at runtime if an assertion fails, mine will yield the natural production result, whatever that may be, and be handled or not.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Rick O'Shay:
>> ensureNotNull(message, object)
If you are littering your code to check whether Colin Coder or Penelope Programmer made a mistake then this is inappropriate. Ultimately you are creating a mountain of dead code that simply takes up space and time.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Rick O'Shay:
>> we were rather successful...
I'm guessing the bulk the success attributed to contract enforcement were realized during testing not in the field. Not entirely but mostly. Turning them off in production might have been less rewarding but not significantly assuming you have solid testing.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Rick O'Shay:
The difference is they were applied at very specific interface points since performance was a consideration. What was the cost of a given condition expression? Was it called in a loop? Was the same value being checked at several different location before mine was tested? If so why add another?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Originally posted by Rick O'Shay:
OK, let's say you have a system that has little unit testing and you sprinkle it with assertions. I can see how leaving those assertions on would be a very tempting strategy. You are actually relying on the customers for part of your testing. Shocking!
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Tim Holloway:
For me, the benefit of assertions is that I can load up lots of antibugging information, ship a product, and if the thing misbehaves, have the user switch on assertions to get a clearer picture of what went wrong without suffering the overhead that such a fine-grained level of checking would otherwise impose. Before I had that ability (and, more recently, selectable logging levels), I'd have to build a special version of the app with extra checking code and ship it to the user (pre-Internet).
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Mr. C Lamont Gilbert:
Ilja, I would argue that what you are doing is not a candidate for assert. Assert should only be used if you intend to turn if off at runtime as I have stated.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Well THAT's new! Comfort me, reliable tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|