- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Moo Moo Moo
I think what they wanted is foo != Integer.NAN the, um, cadillac version.
captcha suscipit - Suspicion of Incipidness.
Admin
Admin
C++ way:
union { float f; UINT32 u; } float_uint32;
float_uint32 fu32;
for (UINT64 i = 0; i <= 0xffffffff; i++) { fu32.u = (UINT32)i; float f = fu32.f;
}
Admin
What is CMMI?
Admin
Admin
The thing you have to realise when it comes to outsourcing firms, especially in the subcontinent, is that the higher their CMMI level, the more likely they are to develop your software exactly according to the way you spec it. Even when that spec is wrong.
Clearly somewhere along the line as part of the design specifications, someone has requested that a function be added to validate integer input. This is exactly what this function does. It takes an integer input and checks that it's a valid integer. The developer who implemented it probably also thought it was stupid, but the spec said that they had to have this function and so he came up with a fairly decent, well-written and well-documented way to do that. The fact that it's utterly retarded is a completely separate matter entirely.
You don't want stupid code from CMMI Level 5 outsourcers? Don't put stupid things in your specs and make sure you word every requirement precisely.
Admin
Is been a while. I think there is a method though, maybe in Number, like foo.isNaN() or some such.
Admin
Please tell me if you're just fucking with us.
Admin
It seems to me that if this is really what you're after, you could have a compiler or preprocessor or something do most of the work for you instead of spelling it out like this...
Admin
Thanks for replying to my question. I come from a c# background but I am only now learning for my .net certificaiton. If Java (and c#) will automatically box anything passed to this method, what will happen if the value passed to this method can't be cast to an integer (i.e. someone accidentally passes it a string)? Won't that cause an exception in itself, before the method even executes or will the runtime simply assign the parameter a null value?
Admin
Thanks for replying to my question. I come from a c# background but I am only now learning for my .net certificaiton. If Java (and c#) will automatically box anything passed to this method, what will happen if the value passed to this method can't be cast to an integer (i.e. someone accidentally passes it a string)? Won't that cause an exception in itself, before the method even executes or will the runtime simply assign the parameter a null value?
Admin
Having CMMI level 5 does not mean one is not producing crap. It just means they are producing crap deterministically.
Admin
Yeah, you can. I was once involved in developing a system where I was in charge of a key DLL. My log file was in the form of executable C++ code. Therefore, any logged session could be sent to me so that I could see, compile, run, and debug what their GUI code and the user's input had been doing with my DLL.
Admin
he was saying "heck" half jokingly, right?
Admin
uhh.... not in Java.
Admin
Admin
... does not mean that you are not producing crap. It just means that you have a process in place to improve the kind of crap you are producing, even if it is a slow and inconsequential improvement that is heading your company into oblivion.
Typically, the situation just described would produce some "key learnings", such as the following:
Admin
I know that the function is in Java not C++, but take a look at the fifth bullet point: http://gcc.gnu.org/onlinedocs/gcc-3.1.1/gcc/Disappointments.html
Worth considering if you're ever considering using == on floats.
Admin
Why not reading the rest of the thread (especially this post) before posting utter bullshit?
Admin
Admin
Admin
try with null
Admin
Admin
Parsing 10,000 will lead to a NumberFormatException, 10.000 AFAIR as well but might end up with 10. toString will always return 10000.
Admin
Autoboxing on the other side (since Java 1.5) is only working between primitives (int, long, float, ...) and their corresponding Object-Wrappers (java.lang.Integer, .Long, .Float, etc.). So you can "use" primitives e.g. as key for a Map (that needs classes derived from java.lang.Object). The compiler changes a call of
to and vice versa from to And if getKey() returns null there will be of course a NullPointerException leading to big questionmarks to the programmer who is not aware of that implicit change of code.Admin
Admin
This is the worst null-checker i've ever seen. The one that I stand by checks every number against the input to see if its that number, and if it loops all the way to int_max, then its null.
That way nothing gets through
CAPTCHA : Nulla; used to describe how non-existantly good things are.
That band was nulla good.
They were that good?
No, they were bad.
Admin
Imagine that, another coder who has no clue as to how computers work.
Admin
float a = Float.intBitsToFloat(i); if(a != a) counter++; i++; }while(i != INTEGER_MAX_VALUE)
There are quite a few NaN values in the spec
Admin
Interesting. It doesn't call logger.exiting in the case where someone passes in a value that trips the exception handler. Thankfully that only happens when someone's foolish enough to pass in a null but even so, have they never heard of a finally clause?
Admin
Don't get bent over dude. That reply you got was a natural response (most Java developers don't seem to know the intricacies of IEEE 754) to your example, which though correct, comes a bit off on the obscurantist side.
I do strongly believe CS people should know these kind of things (Numerical Analysis or at least consistent coverage of floating point stuff should be required topics). But unfortunate as it is, many programmers come from a CS background that does not cover floating point arithmetic at all (much less anything related to numerical analysis.) This is not counting MIS programmers, and non-EE/non-CE engineering grads who end up becoming full-time programmers on the job. It is what it is.
I would have been a bit more constructive if you had prefaced your example with a mention of IEEE 754 floats and a caveat saying that passing something like 0.0/0.0 or Float.NaN as arguments would make the method return false... just sayin' man.
Admin
At least you got a CMM level 5 code, where the log is properly done :-)
Admin
BTW, I haven't found that Java developers know less about IEEE 754 than other developers on average (in other words, VB/C#/C++/Perl/Ruby developers don't know shit about floating point arithmetic either in general) - just sayin' man.
Admin
Admin
It will return false when it is called with a null argument. Because they are using the upper case Integer class rather than the primitive type int, the integer that gets passed in must be wrapped in the Integer object.
the code will capture the NullPointerException, and incorrectly log a parse exception to the log file.
Admin
Imagine that. Someone so pedantic that their proctologist needs a ladder and a hazmat suit.
Don't confuse syntax with pointer arithmetic.
Admin
In all seriousness, I've seen cases where plugins or JNI code can corrupt the internals of objects that are Java system pre-defined types, notably Jython can corrupt a java.lang.String which contains multibyte characters to the point where you can't even pass it to System.out.println()
However, the data inside a java.lang.Integer is just a 32-bit int value, and all possible bit patterns are valid data, so the only way I can figure this could throw a NFE is if the input data is either null or some weird homegrown subclass of Integer with bugs.
CAPTCHA spelled wrong: delenit / delinit
Admin
No.
http://en.wikipedia.org/wiki/Halting_problem
CAPTCHA: "nibh" == misspelled Gaelic girls' name?
Admin
There is no such thing as OutOfMemoryException, it's OutOfMemoryError, and it is not a subclass of java.lang.Exception, because in general you're not supposed to catch it.
java.lang.Error directly inherits from java.lang.Throwable
CAPTCHA: "erat" == Latin for "was"
Admin
It's not my fault you tried to look smart, but ended up looking stupid.
Admin
Did you ask your employer you can publish the code of your company?
This is really a WTF - if you are stealing code from company without permission.
Admin
Making fun of is scarcely stealing (whether "stealing" is the proper term for use with copyright is another matter...I'd say you're taking liberties with language and legality there)...and, honestly, I'm not entirely sure this wouldn't be covered under fair use anyhow. It's the somewhere between the gray areas of whistleblowers and parodists.
If anyone wants to "steal" this for use in actual code, they deserve every copyright suit coming to them.
Admin
That was my LOL too
Admin
I used to love it when I was told as a consultant that they were 'going with an Indian company.' I'd say, "See you in six months" and almost never was turned away a second time.
Admin
When some sort of solar winds/cosmic rays/little green men change the string before parsing
Admin
In Java Integers/ints are signed 32 bit values, and the strings which can be parsed using Integer.parseInt can have a leading '-', and any number of leading zeros (after the minus if present). You get a NFE if the value parsed would exceed Integer.MAX_VALUE or be less than Integer.MIN_VALUE. As the max and min are different in value as well as sign, the regex has around 20 different branches ( if the first non-zero digit is 2 the next digit must be 0 or 1 or there must be fewer than 10 non-zero digits, and so on through 2147483647). I wouldn't want to hazard a guess on whether testing that lot with a regex is actually any more efficient that catching an exception.
Admin
Brother,
This is what happens when you have a CTO that doesn't code anymore. They fall for the fancy words and the cost savings that will occur with outsourcing. As usual they find out you get what you pay for. My advice, start looking for a new job. This CTO will throw you under the bus and won't even realize it.
Admin
its a matter of style. coding is like art and when its crap you know it. I believe that a good method should have one entry and exit point. Too many returns reflects that the programmer has not fully followed the logic from start to end, from the begining of the function to the end of the function, with all conditions tested for.
we could have recoded the above code to this:
var zRetValue = false; if (a == b){ zRetValue = true; } return zRetValue;
simple! one return point and the returned value gets set along its execution path.
KISS
Admin
Log driven development is a perfect excuse for not having any unittests!
Admin
Parameter of type Integer is not 'a' wtf... it is 'the' wtf in my opinion. Logging asid, you're taking an Integer, calling toString and then parsing the resultant string to see if it's a valid number? WTF?! :)
I guess most people are talking about logging because they didn't look at the parameter type and assumed it would be a String. I don't blame the. It would be really hard to imagine someone doing the above... LOL...