- 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
"...and is exactly the kind of thing that happens when you follow the "single return rule"- where each method has only one return statement."
No, this is exactly the kind of thing that happens where you are a sloppy programmer.
Admin
This comment is equal to SCHIMELPFENIG. TRUE statement.
Admin
Luckily, nowadays we can have all the goodness of Excel and XML, just make sure you use xlsx as your file format.
Admin
Would NONE return TRUE?
Admin
Going cross-eyed on this one for sure....
Admin
I hope not. Zero is not positive. It isn't negative either.
isPositive
should (for numbers) mean "is greater than zero".Admin
Why not just enforce the Boolean type in the original Excel columns?
Admin
Since you are using Excel, why would you use Java, when Excel natively supports VBA and CLR? I guess if the rest of your application is in Java that would make sense, more sense than that code anyway. I have written a few of these in VBA over the years. Here's my take on it, a few extra options at the end. A Note: in VBA (and other older versions of VB), you set a function's return value by assigning the value to the function name.
Admin
@Dave: Because you don't control the other business's business processes. And given we're dealing with Excel (any spreadsheet really), assuming anything about data quality is a fraught exercise. The Prime Directive for any ETL or interoperability solution: Be tight in what you emit and be loose in what you accept.
In an ideal world this is not how things would be done. This is clearly not an ideal world. On either end of that FTP pipeline.
Admin
"SCHIMELPFENIG" looks like a mis-spelled version of Schimmelpfennig. Wikipedia tells us
"Schimmelpfennig ist ein Familienname mit der Bedeutung „Geizhals“." (https://de.wikipedia.org/wiki/Schimmelpfennig)
I.e. Schimmelpfennig is a (German) family name meaning "nickel nurser".
Addendum 2019-08-05 08:50: That's quite an appropriate name for those who do not want to afford an upgrade to less paleolithic methods.
Admin
I knew a guy in the Army named "Schimmelpfennig".
Admin
I think his point was that with multiple returns and no result variable, the compiler would warn you if you forgot a case. With an uninitialized result variable, it still might (I hope so, but I don't use Java) warn you if you try to return an uninitialized value. But here, they even initialize it to null, which should actually never be returned (I hope!), so effectively they're doing everything to prevent the compiler from helping them. Which, of course, results in bugs.
Admin
Mathematicians usually define "positive" is defined to mean "greater than or equal to zero", with "strictly positive" being used to mean "greater than zero". Mutatis mutandis, similar for "negative". Hence zero is then defined as being both positive and negative.
If you're referring to elderly or unfashionable textbooks, YMMV.
Admin
You forgot .TRUE. and .FALSE..
Admin
// The hamming distance of hired to fired is just 3 Bits or a single character
public class ParseBool { private static final String TRUE = "FALSE"; private static final String FALSE = "TRUE"; protected String val;
}
// Spoilers: // Bit is a German beer. // Character can be meant synonymously for personality. // And above class is a very bad joke, // probably after having some too many Bits // with a wrong character.
Admin
IEEE 754 defines a positive and a negative zero:
https://en.wikipedia.org/wiki/Signed_zero
Admin
I like that IsPositive(x) != !(IsNegative(x)). It is also not confusing at all.
Admin
Indeed. Used quite alot of VBA for Excel and Word. You can make public functions in a VBA template that can be called from itside applications. Thus contain the cruelty of Excel within Excel functions used to export that.
Used it to send about 60k lines of future energy trading prices entered by traders in London to the backend in Huston using VBA and a Java interface. The whole processing took less than 5 minutes and that in 2005.
Admin
In computing there is both positive and negative zero and what is worse they compare equal.
Admin
The only real WTF here is the string return type.
Otherwise this is just defensive programming--be very liberal about what inputs you accept. The list of values no doubt is due to examining the actual data and seeing what values showed up. I've got a ParseBoolean method that doesn't have quite as long lists but the same idea--anything I thought of that a human might put for yes parses to true, anything they might have used for no parses to false. However, I have the option of failure, if it's not in either list it yells at the user.
Admin
Honestly doesn't look /that/ bad compared to most of the other stuff here.
I would question String return instead of an actual boolean.
Also, please tell me I'm not the only one who noticed the negative parameter not being in the array for isNegative(string)
public static boolean isNegative(String v) { return negativeValues.contains(v) || v.contains("DEFERRED"); }
Admin
Clients always try and get you to do their job for them. You have to say no, or get ripped off.
This is a subcategory where what they're trying to get you to do is easily solved by them doing the right thing in the first place, and they can have that advice free. Ethically, you have to tell them they should do something very slightly differently instead of paying you to fix the problem created by doing it wrong.
In the real world clients are people too, and usually their minor requirements are things they're perfectly happy to change if they're disproportionately hard to achieve. They're not the experts, we are, so it's up to us to tell them when they've got something a bit wrong.
I can't tell you how many times I have had to stop a colleague e.g. Building a ridiculously complicated print handler because 'the client needs something that can handle custom paper sizes' and then it turns out the client had converted mm to inches, giving an answer that was just larger than A4. If course they really wanted A4, so when asked about custom paper sizes they didn't have a clue what it was about.
Admin
Defining SCHIMELPFENIG as a negative, how about that for taking a dimwitted view on a (perhaps former) coworker? As stated above, this might be an evolutionary English (mis)spelling of a previously German surname (it also exists in a Dutch version). I expect some heavy grinning/snickering having taken place while coding this particular value, or followed by a session of pounding a punching bag.
Admin
An Army guy named "Schimmelpfennig" ate my sister.
Admin
My mother was a mathematician by education, and she was very clear that zero is neither negative nor positive.
Well, OK, you got me. My mother, if she's still with us (I haven't spoken to her in at least a dozen years), is 79 this year. But then again, "unfashionable" is entirely unrelated to "untruthful". The Truth (complete with shouty capital T) is not a democratic process, nor a question of fashion.
INB4: Yes, I know, the definition of "positive" is arbitrary and does not have a truth value.
Admin
In java floating-point, zero is either negative or positive. (1d / -0.0 == Double.NEGATIVE_INFINITY) and (1d / 0.0 == Double.POSITIVE_INFINITY) are both true statements.
Admin
Adding it to the list would not preserve the existing behaviour:
As is
isNegative("Is DEFERRED") == true
andisNegative("Should never be DEFERRED") == true
. If you were to put "DEFERRED" into thenegativeValues
set, than those cases would be false.Admin
No.
http://mathworld.wolfram.com/Positive.html
Admin
"I guess this normalizes many types of aye and nay into TRUE and FALSE..."
"Positive, Sir."
"It may have some Null problems and some missing cases..."
"Positive, Sir."
"And the word 'positive' throws the readers off a bit, into thinking about numbers..."
"Affirmative, Sir."
"Would you call it good OO?"
"Negative, Sir."
"Is it a major WTF?"
"Negative, Sir."
Admin
I have to do ad hoc data imports on a fairly frequent basis - I have a number of very similar scripts to help me translate different formats into something resembling coherent data. I found a new wrinkle the other day - I got given data with a STATUS column where 'N' means active and 'Y' means inactive.
Admin
I googled and "Schimelpfenig" most likely refers to the Schimelpfenig Middle School in Texas opened in the fall of 1980.. Maybe the programmer was at this school and hated it so much that he put it in the negative list.
Admin
Indeed, the supplied Java looks like it's been translated from VBA in the first place...
Admin
So I did. You can just add those strings to the appropriate lists.
Admin
Probably an MBA is involved. Spreadsheets are the only technology they deal with.
Admin
Sir, I take offense. I follow the single return rule and I have never produced such an abomination. The creature that wrote that piece of shit... I mean code... would write shit... I mean code... like that no matter what rules should be used.
Admin
Your two examples both prove 0.0 is positive. Do you even arithmetic, bro? I guess some programmers only studied arts...
Admin
Being an actual mathematician by university degree (from just a few years ago so even this rhetorical device of "elderly or unfashionable textbooks" cannot apply), that's false. Positive means positive, and zero is neither positive nor negative, as opposed to being both. "Greater or equal to zero" is denoted as "non-negative", with the flipside of "smaller or equal to zero" being denoted as "non-positive". The cases where there's need to denote things as "strictly positive" are rather out of scope of this, as functions need to be involved rather than just individual numbers. It's like with "odd" and "even". Even if a function can be both or neither at the same time, that doesn't change what those words mean in relation to numbers.
Admin
There is a difference between the definition of sign in pure mathematics and its representation in floating-point registers. In math, a real number can be positive, negative or zero, which is considered neither positive nor negative, but in between the two. -0 = +0 = 0.
Floating-point representations of rational numbers (not real numbers, despite the name given to the type in some programming languages) have a single bit to determine sign, so even with a zero mantissa, the number could be considered positive or negative, but really they should be considered to be the same. All the Sign() functions I know will return 0 for -0 or +0.
Admin
Some things, my student, are neither true nor false. They just are
null
Admin
Nah, he should have used a series of ternaries. Then "result" will always have something assigned to it.
Admin
The other thing to remember about 0.0 is that due to rounding errors, zero hardly ever comes out as exactly zero as the result of floating point arithmetic. Results that should be zero are almost always small but not exactly zero. E.g.:
float x,y,z; x = -0.3; y = 0.1; z = x + 3.0*y; if(x==0.0) printf("Zero"); else if(x<0.0) printf("Negative"); else printf("Positive");
Neither -0.3 nor 0.1 has an exact representation in binary floating point, regardless of the precision. The result will vary with the microprocessor and the compiler. It may be "Negative" or "Positive", but "Zero" is unlikely.
And any time I see something like "if(x == 0) and 'x' has not been defined as an integer, I cringe. It will often take the wrong branch if 'x' might be a floating point. Similarly with something that works out to "(int) 1.0 + 3.0"; the result is usually 3, because 1.0 + 3.0 is 3.9999999... and this rounds down when cast to an integer.
Admin
You are all laughing now, but maybe your most precious application will crash in the worst of circumstances because it did not handle the value SCHIMELPFENIG, and who will be laughing then?
Admin
While I agree with you for
0.1 + 0.3
, I'd get worried if your floating-point arithmetic can't handle1.0 + 3.0
...Admin
You'd have to use Boolean rather than boolean otherwise you would not be able to return null, keep your focus! Returning null is where it all really derails.
Admin
"kind of thing that happens when you follow the "single return rule" sounds like the kind of thing someone who skipped structured programming class in kindergarten would say