Comment On EvalToInteger, 'gumdrops', and More

"I recently found this while going over some code in a Util library used by my project," Ian writes, "clearly, this method makes sure the job gets done." [expand full text]
« PrevPage 1 | Page 2Next »

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 07:17 • by ParkinT
Visible -- When this Post is read it is Visible
Hidden -- When this Post is read it is Hidden
FIRST -- When this Post is read it is VeryFIRST

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:07 • by Sam Vimes (unregistered)
That's Constable Carrot, thank you very much.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:10 • by SCSimmons
string sql = "exec spRequestInitechData '"
+ txtData.Text.ToString().Replace("'", "''") + "'";

Sometimes, I can't imagine the thought processes that lead to the WTF. I think it may be scarier when I can.

"We should escape the apostrophes when we build the SQL command, to prevent injection attacks."
"Actually, I've heard that the accepted standard is to use stored procedures."
"Oh. Hey, I've got an idea. Let's do both! Belt and suspenders, right?"
"Brillant!"

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:17 • by WhoMe (unregistered)
What exactly is wrong with this?

$dir = 'test';

if (!file_exists($dir) || !is_dir($dir))
{
exec('mkdir '.$dir);
}


Safe mode == exec. It's not ideal, but it works.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:24 • by Quietust
378709 in reply to 378708
WhoMe:
What exactly is wrong with this?

$dir = 'test';

if (!file_exists($dir) || !is_dir($dir))
{
exec('mkdir '.$dir);
}



What, you mean aside from the fact that it's failing to use the mkdir() function?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:39 • by Kendall (unregistered)
Come on, even Excel has VeryHidden data. Nothing wrong with keeping the users out of the icky stuff.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:54 • by Makkhdyn (unregistered)
The "parseStringData()" method isn't that weird.

"replace()" replaces (as its name states) a character with another, but here every '/' is removed; it's not quite the same thing as a replacement.

Sure it could have been better, going through the "char[]" version of the "String" and putting every non '/' character into a "StringBuilder" is way more efficient than using "split()" (which is a regex), but still, it isn't _that bad_.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 09:55 • by Makkhdyn (unregistered)
378712 in reply to 378711
PS: I assumed it was Java code.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:00 • by kjordan (unregistered)
378713 in reply to 378711
Makkhdyn:
The "parseStringData()" method isn't that weird.

"replace()" replaces (as its name states) a character with another, but here every '/' is removed; it's not quite the same thing as a replacement.

Sure it could have been better, going through the "char[]" version of the "String" and putting every non '/' character into a "StringBuilder" is way more efficient than using "split()" (which is a regex), but still, it isn't _that bad_.

But with replace() you can choose to use an empty string to replace with.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:03 • by Don (unregistered)
Actually, hidden/visible/veryhidden is probably akin to the Excel functionality for sheet visibility; when just hidden the sheet is there but you can get it back very easily using the unhide functionality. Veryhidden means it will only be unhidable by use of VBE or the immediate window (both of which you can lock down).

I would imagine the functionality is looking to do something like that; in other words hidden just means from view but accessible through the GUI or app, with an option to unhide; while veryhidden means only code can unhide.

Or maybe the function is part of an Excel library itself?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:04 • by Programming 101 (unregistered)
if (!file_exists($dir) || !is_dir($dir))
if (!file_exists('test') || !is_dir('test'))
if (!TRUE || !FALSE)
if (FALSE || TRUE)
if (TRUE)

So if 'test' exists and is not a dir, a dir named 'test' will be created?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:05 • by Makkhdyn (unregistered)
378716 in reply to 378713
Only since java 1.5, if you work with an old code (which can happen [really, it happens to me all the time]) this kind of "gem" can be found everywhere.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:11 • by Nagesh (unregistered)
When makeing directorys it must be avoideing the "horse race condition" that another user takes you directorie befor you used it. This bug cause hakker joy steel all data etc. Must use current time to create garenteed uneek directorie then rename to 'test' or watever name is reallee wanted. Sum language have function to do this alreadee. Any professional programmeer know this best practic.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:21 • by Zylon
378718 in reply to 378706
Sam Vimes:
That's Constable Carrot, thank you very much.

Constable Carrot of the Yard!?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:40 • by doctor_of_common_sense (unregistered)
meh. Seen a lot worse. Until the setting drop down category selection to "I Am Krogan" does something nefariously stupid, all these WTFs are nothing more than a coffee stain on a book in someone else's trash.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:47 • by Loren Pechtel
What's the problem with:

public static int EvalToInteger(string statement) {
string s = EvalToString(statement);
return int.Parse(s.ToString());
}

Note that the supplied string is named "statement"--I would assume EvalToString is doing some sort of evaluation, it doesn't just return what was passed in.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:47 • by sadwings (unregistered)
378722 in reply to 378717
Nagesh:
When makeing directorys it must be avoideing the "horse race condition" that another user takes you directorie befor you used it. This bug cause hakker joy steel all data etc. Must use current time to create garenteed uneek directorie then rename to 'test' or watever name is reallee wanted. Sum language have function to do this alreadee. Any professional programmeer know this best practic.


I miss TopC0der, but you are fun too.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:49 • by Fred (unregistered)
VeryHidden Very Hidden. When the item is serialized out as xml, its value is "veryHidden".
Were it not for this line, the table could have been completely machine generated. But the three variations on "very hidden" suggest at least the possibility that some human drudge-drone was involved -- but not human enough to realize that an actual explanation might be useful.

Anyway, why is it a table? Shouldn't it be XML?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:53 • by Jack (unregistered)
378724 in reply to 378722
sadwings:
Nagesh:
When makeing directorys it must be avoideing the "horse race condition" that another user takes you directorie befor you used it. This bug cause hakker joy steel all data etc. Must use current time to create garenteed uneek directorie then rename to 'test' or watever name is reallee wanted. Sum language have function to do this alreadee. Any professional programmeer know this best practic.

I miss TopC0der, but you are fun too.
I'm operating on the assumption that they are the same person. After all, didn't Alex banish TopCod3r to India? (As a fate worse than death, it is the supreme punishment.)

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 10:55 • by Paul Neumann (unregistered)
# Find the last 200 transactions
logging.debug( "Finding the last 600 transactions" )
ConnMysql.query("select Id from Transactions order by ts desc limit 0,10000 ")


This is quite obvious. The requirements changed. Everyone knows only green code needs to be commented. When changing existing code, the intent is already clear so updating the documentation is merely a work avoidance technique.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:03 • by emurphy
378726 in reply to 378721
Loren Pechtel:
What's the problem with:

public static int EvalToInteger(string statement) {
string s = EvalToString(statement);
return int.Parse(s.ToString());
}

Note that the supplied string is named "statement"--I would assume EvalToString is doing some sort of evaluation, it doesn't just return what was passed in.


Maybe so, but s.ToString() is redundant, and what's left is simple enough that you might want to compact it into one line:

return int.Parse(EvalToString(statement));

Still, if your assumption is correct, then what's left is a relatively small WTF; on the same scale as BDate and EDate, where AFAICT the only WTF is that ToUpper() is unneeded.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:04 • by emurphy
378727 in reply to 378723
Fred:
VeryHidden Very Hidden. When the item is serialized out as xml, its value is "veryHidden".
Were it not for this line, the table could have been completely machine generated. But the three variations on "very hidden" suggest at least the possibility that some human drudge-drone was involved -- but not human enough to realize that an actual explanation might be useful.

Anyway, why is it a table? Shouldn't it be XML?


For robustness, you should print out the XML, photograph it on a wooden table...

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:06 • by Coyne
I think the visibility enumeration needs a few more enumerations. These come to mind: Sort of Hidden, Cleverly Hidden, Poorly Hidden, Extra Hidden, Forever Hidden, Optimally Hidden, Resolutely Hidden, Nervously Hidden, Unbelievably Hidden.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:07 • by Tom (unregistered)
Whoever wrote that "EditTDemensions" function should be beaten.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:08 • by PedanticCurmudgeon
378730 in reply to 378706
Sam Vimes (fake):
That's Captain Carrot, thank you very much.
FTFY

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:09 • by FragFrog (unregistered)
378731 in reply to 378721
Loren Pechtel:
What's the problem with:

public static int EvalToInteger(string statement) {
string s = EvalToString(statement);
return int.Parse(s.ToString());
}

Note that the supplied string is named "statement"--I would assume EvalToString is doing some sort of evaluation, it doesn't just return what was passed in.

If there are any sort of naming conventions there, EvalToString will convert something to a string, just like EvalToInteger converts something to an integer. So now you have a string, which is evalled as a string, and then its string value is parsed.

That doesn't sound the least bit redundant to you?

Mind you, now I am assuming that a string variable's value is equal to it's .ToString value. Would not surprise me much if there is some weird null condition where that is not the case.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:27 • by Terry Pratchett (unregistered)
378732 in reply to 378706
Sam Vimes:
That's Constable Carrot, thank you very much.


You need to catch up now. I am dying and you're still stuck on the constable part. Carrot was promoted to Captain several books ago.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:30 • by MiffTheFox
378733 in reply to 378731
FangFrog:
If there are any sort of naming conventions there, EvalToString will convert something to a string, just like EvalToInteger converts something to an integer. So now you have a string, which is evalled as a string, and then its string value is parsed.

That doesn't sound the least bit redundant to you?


I think the intended idea is that EvalToSTring will evaluate the statement and return the result as a string, just like EvalToInteger will evaluate the statement and return the result as an integer.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:32 • by Paul Neumann (unregistered)
378734 in reply to 378731
FragFrog:
Loren Pechtel:
What's the problem with:

public static int EvalToInteger(string statement) {
string s = EvalToString(statement);
return int.Parse(s.ToString());
}

Note that the supplied string is named "statement"--I would assume EvalToString is doing some sort of evaluation, it doesn't just return what was passed in.

If there are any sort of naming conventions there, EvalToString will convert something to a string, just like EvalToInteger converts something to an integer. So now you have a string, which is evalled as a string, and then its string value is parsed.

That doesn't sound the least bit redundant to you?

Mind you, now I am assuming that a string variable's value is equal to it's .ToString value. Would not surprise me much if there is some weird null condition where that is not the case.


However, your entire naming convention assumption is that EvalToInteger is the same as int.Parse. If EvalToString is not the same as .ToString(), then EvalToInteger cannot be the same as int.Parse and the naming convention is preserved. The reverse is also true (though admittedly redundant (my shop calls this a "friction layer")).

Therefore you have presented us with a tautolgy and yet complain it is false.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 11:53 • by AB (unregistered)
[quote]"Like many fellow developers, the codebase I work on each day is terrible and devoid of any structure,"[quote]

Hey, as a developer I may be terrible and devoid of any structure, but I resent being compared to that code.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 13:15 • by Jay (unregistered)
With no clue what EvalToString does, the only thing odd about the example is that he takes a toString of a string, which is pointless.

Some posters seem to be assuming that EvalToString converts an integer to a string, so that then doing the parse just converts it back, making the function pointless. But this clearly can't be true, as the input parameter is not an integer but a string.

I don't see a WTF here at all. They have some function that does we know not what to a string, and gets a result that is another string. In at least some cases, this result is, in fact, parsable as an integer, so they have a second function that calls the first, gets the result, and then parses it to an integer. This seems like plain good coding to me. What would be preferable, to make another function identical to EvalToString except that it returns an int? Duplicating who knows how much code?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 13:17 • by Lone Marauder (unregistered)
That last one reminds me of OSPF area types:

Stubby
Not So Stubby
Totally Stubby
Totally Not So Stubby

I wish I were making this up...

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 13:17 • by Jay (unregistered)
I'm really surprised that no one has pointed out the obvious error in the enum. Of course there should be FOUR values: Visible, Hidden, VeryHidden, and FileNotFound.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 13:25 • by method1
The "THIS SETTING SHOULD NOT BE 'TRUE'" WTF is classic. I can imagine this pattern is present in huge numbers of dodgy codebases. The "sort of 3(ish) value" "boolean". Hours of fun debugging & maintaining no doubt.
The Visible/Hidden/VeryHidden one is the same as Windows Explorer's Visible/Hidden/Protected OS scheme, so a popular 'idea', though popularity is no guide to quality.
Having just seen Jays post above, of course he's correct about 'file_not_found'

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 14:09 • by The Nerve (unregistered)
The System.out one is easily fixed at a global level.

public class SystemInfoLogger extends PrintWriter {

Log log = LogFactory.getLog(SystemLogger.class);

public void print(String val) {
if (log.isInfoEnabled()) {
log.info(val);
}
}

// other overridden methods here
}

public static void main(String[] args) {
System.setOut(new SystemInfoLogger());
System.setErr(new SystemErrorLogger()); // left as an exercise to the reader...I can't do all you're thinking for you.
}

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 14:17 • by pjt33
378744 in reply to 378726
emurphy:
... on the same scale as BDate and EDate, where AFAICT the only WTF is that ToUpper() is unneeded.

Does DRY mean anything to you?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 14:25 • by briverymouse
378745 in reply to 378744
pjt33:
Does DRY mean anything to you?


I must admit I don't get it either. One is today's date, the other is tomorrow. Where does he repeat himself?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 14:26 • by that guy (unregistered)
378746 in reply to 378744
The first one looks like a part of this code, probably not a WTF.
http://odetocode.com/code/80.aspx

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 15:02 • by jmacpherson (unregistered)
[I] [just] [don't] [see] [any] [problems] [with] [the] [classic] [ASP] [code] [.] [Where's] [the] [WTF] [?]

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 15:05 • by Alex Papadumbass (unregistered)
378748 in reply to 378747
jmacpherson:
[I] [just] [don't] [see] [any] [problems] [with] [the] [classic] [ASP] [code] [.] [Where's] [the] [WTF] [?]


STFU. I am the boss here and if I have published it, it is a WTF. Print your expert opinions on a toilet paper and shove it up your ass.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 15:36 • by PiisAWheeL
378749 in reply to 378741
Jay:
I'm really surprised that no one has pointed out the obvious error in the enum. Of course there should be FOUR values: Visible, Hidden, VeryHidden, and FileNotFound.
Wrong wrong wrong! Its an enum, not a BOOL. True, False, and File_not_found are the 2 BOOLEAN VALUES we can pick from. It has no place in enums.

Although, if hidden well enough, may not be found...

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 15:50 • by Nagesh (unregistered)
378750 in reply to 378748
Alex Papadumbass:
jmacpherson:
[I] [just] [don't] [see] [any] [problems] [with] [the] [classic] [ASP] [code] [.] [Where's] [the] [WTF] [?]


STFU. I am the boss here and if I have published it, it is a WTF. Print your expert opinions on a toilet paper and shove it up your ass.

I know what ass is (shown, left), but what is toilet papper?



Re: EvalToInteger, 'gumdrops', and More

2012-04-09 15:54 • by Nagesh (unregistered)
378751 in reply to 378724
I am being re-encarnation, but not knowing my prevous identities.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 16:01 • by Gary Olson (unregistered)
Private CARROT() As Char = {"^"c}
Carrots contain vitamin A, not vitamin C.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 16:53 • by Not Nagesh Either (unregistered)
378753 in reply to 378717
Nagesh:
When makeing directorys it must be avoideing the "horse race condition" that another user takes you directorie befor you used it. This bug cause hakker joy steel all data etc. Must use current time to create garenteed uneek directorie then rename to 'test' or watever name is reallee wanted. Sum language have function to do this alreadee. Any professional programmeer know this best practic.


You are very bad at being Nagesh. "hakker"? "Sum"? Seriously, don't do it again.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 17:10 • by PiisAWheeL
378754 in reply to 378750
Nagesh:
Alex Papadumbass:
jmacpherson:
[I] [just] [don't] [see] [any] [problems] [with] [the] [classic] [ASP] [code] [.] [Where's] [the] [WTF] [?]


STFU. I am the boss here and if I have published it, it is a WTF. Print your expert opinions on a toilet paper and shove it up your ass.

I know what ass is (shown, left), but what is toilet papper?



And since we're on that topic... can we stop using the same 7 pictures of a 3rd world country over and over again everytime we want to demean the quality of work or people from india?

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 17:14 • by geoffrey, MCP, PMP (unregistered)
378755 in reply to 378731
FragFrog:
Loren Pechtel:
What's the problem with:

public static int EvalToInteger(string statement) {
string s = EvalToString(statement);
return int.Parse(s.ToString());
}

Note that the supplied string is named "statement"--I would assume EvalToString is doing some sort of evaluation, it doesn't just return what was passed in.

If there are any sort of naming conventions there, EvalToString will convert something to a string, just like EvalToInteger converts something to an integer. So now you have a string, which is evalled as a string, and then its string value is parsed.

That doesn't sound the least bit redundant to you?

Mind you, now I am assuming that a string variable's value is equal to it's .ToString value. Would not surprise me much if there is some weird null condition where that is not the case.


EvalToString obviously has to do something besides pass through the parameter passed in as a return value. Otherwise, why even have it there? You make a dangerous assumption. I'm guessing that it does some sort of logical evaluation on the value passed in, so that int.Parse() does not receive a null value.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 17:25 • by Richard (unregistered)
378756 in reply to 378754
PiisAWheeL:
Nagesh:


And since we're on that topic... can we stop using the same 7 pictures of a 3rd world country over and over again everytime we want to demean the quality of work or people from india?
I don't know why you consider this picture demeaning. They have shoes (sorta) paved roads and even, it would appear, intermittent access to running water. Sounds like one of those Chamber of Commerce things trying to praise a place, not put it down.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 17:33 • by PiisAWheeL
378757 in reply to 378756
Richard:
PiisAWheeL:

And since we're on that topic... can we stop using the same 7 pictures of a 3rd world country over and over again everytime we want to demean the quality of work or people from india?
I don't know why you consider this picture demeaning. They have shoes (sorta) paved roads and even, it would appear, intermittent access to running water. Sounds like one of those Chamber of Commerce things trying to praise a place, not put it down.
I didn't consider the picture demeaning. Its context (fake nagesh using it with bad english and not saying anything funny) was designed to be demeaning. But that is not my point. There are like 7 of these pictures that get used in EVERY FUCKING THREAD! Its called the internet. Go find something a little more original and less worn out. That picture needs an arrow to the knee.

Re: EvalToInteger, 'gumdrops', and More

2012-04-09 17:43 • by Mr.'; Drop Database -- (unregistered)
378758 in reply to 378750
Nagesh:
Alex Papadumbass:
jmacpherson:
[I] [just] [don't] [see] [any] [problems] [with] [the] [classic] [ASP] [code] [.] [Where's] [the] [WTF] [?]
STFU. I am the boss here and if I have published it, it is a WTF. Print your expert opinions on a toilet paper and shove it up your ass.
I know what ass is (shown, left), but what is toilet papper?
It's that disgusting stuff they use in countries that aren't civilized enough to use bidets.
« PrevPage 1 | Page 2Next »

Add Comment