SCJP 1.4, www.gsi3d.org.uk
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
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
ms<br />SCJP, SCJD
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by fred rosenberger:
We used to use them in our C++ days. One of our senior developers was a STRONG advocate of them.
We merged with another company, and that developer left. The new company had a large code base we started working on, with no asserts in it. Since nobody is pushing for them, they're not being used.
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
Did you notice any difference in bug density?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by fred rosenberger:
i'm a fairly low-level programmer here, and don't get to see the kind of stats that would tell me.
Most of the bugs i see i don't think would have been fixed/caught with asserts, but i could (and probably am) wrong in my belief of that.
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
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
I'm not sure I get you. What do you mean with turning it on at compile time? Using the -source 1.4 option to indicate that you're happy writing JDK 1.4 specific source? But surely that's a one-time thing; ten seconds of setup in a build script or development environment. Who cares about that kind of time?Originally posted by David Hibbs:
a) If you have to turn it on twice to get the asserts to work (compiler AND runtime), who will really take the time use it?
What do you mean?b) If you're going to write assumption checks, why be lazy?
![]()
That'd simply be misuse of Java assertions. They are a development and testing tool. If you want to keep your checks around in production, use plain old Java code and think carefully about how you are going to handle them. I don't see how this is a problem with the assertion facility.c) It's simply a throwback to C days. [...] Because you can use assert anywhere without regard to putting thought into where the exception will go, who will handle it, or what the result will be, the more assertions there are the more unstable the software is (barring a).
[...] In C, assertions were used because there was no other good way to handle an error condition. In C++ and Java, we have these things called "Exceptions".
I could not disagree more. Checked exceptions are not a good way to flag up programming errors. Traditionally, RuntimeExceptions have been used for these (IndexOutOfBoundsException, IllegalArgumentException, etc). Such disastrous errors typically cannot and should not be handled in a fine-grained way, but allowed to bubble up unchecked until some top-level dispatch loop or error handler which can display an error message and/or retry the entire operation. With the assertion facility we've also got AssertionError for testing-only checks which by definition don't need sophisticated handling at all.If an assumption is invalid, throw as SPECIFIC an exception as possible indicating what happened. Put it in the method signature for cryin' out loud, so everyone calling it KNOWS it might blow up.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Ilja Preuss:
Uh, how does that work out for you?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by Peter den Haan:
I'm not sure I get you. What do you mean with turning it on at compile time? Using the -source 1.4 option to indicate that you're happy writing JDK 1.4 specific source? But surely that's a one-time thing; ten seconds of setup in a build script or development environment. Who cares about that kind of time?
Having to enable them at run time is exactly the point of assertions, of course.
That'd simply be misuse of Java assertions. They are a development and testing tool. If you want to keep your checks around in production, use plain old Java code and think carefully about how you are going to handle them. I don't see how this is a problem with the assertion facility.
This remark I don't understand at all. An assertion is just a fancy way to throw an exception (well, an Error actually).
You seem to be blaming a screwdriver for being poor at hammering nails into the wall.
I could not disagree more. Checked exceptions are not a good way to flag up programming errors. Traditionally, RuntimeExceptions have been used for these (IndexOutOfBoundsException, IllegalArgumentException, etc).
I must say I do like assertions a lot. They aren't, and don't want to be, a universal way to check all of your preconditions, postconditions and invariants all the time. They are a straightforward way to embed those checks that are worthwhile to have as testing and documentation, but either too strict or too expensive to perform in production.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Originally posted by David Hibbs:
Yes, this is exactly what I mean. Is it a language feature or not? Why do I have to specifically enable it on the compiler if it won't be enabled on the JVM anyway?
On top of this, to enable assertions in J2EE code I'd have to enable assertions on the whole app server JVM. I don't know about you, but I don't want to have to enable/disable at that level.
How often have you seen tools misused?
If you want a development and testing tool, use one. There are many many of them to choose from. Assertions are merely an extraneous addition to the list.
Exactly. If you want to throw an exception, then throw an exception. Make it clear that that's what will happen.
What I'm saying is that I have a screwdriver. I can take it with me anywhere and use anywhere. Why do I need a *corded* electric screwdriver that I can only use where I have access to an electrical outlet?
1) Why do I want my unit tests embedded in my code base?
2) What do they accomplish for documentation that a comment line cannot?
3) Assuming that I _do_ want my unit tests embedded within my application code, why would I include a heavy or strict check to clutter the code?
If I wanted my Java code to look and read like C/C++, I'd be writing C#.
Originally posted by Daniel Mayer:
Because of source code compatibility - Sun decided that you should be able to compile 1.3 code without any hassles.
That's not true, as far as I know - you can enable assertions at package granularity, at least.
I don't see how other tools could replace assertions.
To someone knowing the language, it *should* be totally clear.
Assertions are not unit tests, they are complimentary.
How would you implement the functionality of assertions without embedding them into the source code?
I don't understand this question.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|