Comment On Convoluted toString, Interesting Comments, and More

"Everyone knows that Russians are the best programmers, and the guy we recently hired is no exception," Kip DeMane wrote, "though his English is a little... off. Here are his comments from a recent commit." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:05 • by Josephus (unregistered)
stories about Russians? this would be good as an audio reading...

just saying..

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:08 • by Ocson (unregistered)
After a day off, Alex lets loose with an explosion of WTF. Well played sir.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:09 • by joeyadams
309043 in reply to 309041
Josephus:
stories about Russians? this would be good as an audio reading...

just saying..


I suppose all the code samples could be read in a Russian accent.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:12 • by @Deprecated (unregistered)
"The sad part about this code," Ramin writes," is that its author actually tries to justify this pattern. "

googleId = googleId == null ? null : googleId; // ensure really null


Dammit, now I have to go back through all my unit tests and check for really null. And then change my var names to camel toe.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:15 • by djmaze

public static bool IsInfiniteLoop()
{
return !IsFiniteLoop();
}

public static bool IsFiniteLoop()
{
return !IsInfiniteLoop();
}

void definiteCrash()
{
IsInfiniteLoop();
}

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:15 • by frits
/***        REVISION: 6.9                                   *** 

*** DATE: 6 June 2006 ***
*** PROGRAMMER: Fedor Emelianenko ***
*** DESCRIPTION: Upgraded all camel toe vars to ***
*** moose knuckle case. ***/

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:18 • by FeepingCreature (unregistered)
The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:19 • by Markp
The toString() snippet is an even more direct example of an infinite loop.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:22 • by anonymous coward (unregistered)
309049 in reply to 309047
FeepingCreature:
The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


Then it would still be a WTF for using operator overloading when it doesn't make sense (which is almost always. The only places where I can see operator overloading used sensibly is in math libraries)

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:23 • by xyzzy (unregistered)
309050 in reply to 309047
It would also make sense in PHP, if you want to turn "something like null" (false, 0, etc) into "really and truly is null".

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:24 • by Drew (unregistered)
frist = frist != frist ? frist : frist; // ensure really frist

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:24 • by Michael Mol (unregistered)
A little redundant, and slightly inconsistent, but this kind of thing helps me stay insane, and therefore continue to enjoy my job:
iFoundIt = someSet.find(val);

someSet.erase(iRemove);

(No, we don't normally use i as a prefix for integers, why do you ask?)

(captcha: "paratus", as in, "Paratus! Paratus! Free Paratus!")

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:25 • by DOA
"googleId = googleId == null ? null : googleId; // ensure really null"

I think I have a brain haemorrhage

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:27 • by Anonymouse (unregistered)
Too lazy to verify with actual tests, but wouldn't the toString() one just get back the default toString() method if a parent class defined a custom one? Also, the googleId snippet looks valid for languages where values can be equal to null w/o acutally being null.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:29 • by sink (unregistered)
((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:29 • by Lee K-T (unregistered)
Why does he give names to his Camel's toes?

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:31 • by DES
309057 in reply to 309047
FeepingCreature:
The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


No, it will never make sense. What it actually does is:

googleId = googleId

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:32 • by Anon (unregistered)
309058 in reply to 309054
No. Java will always invoke the most specific implementation of a method for a given object instance. Attempting to cast an object does not change which method implementation is invoked.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:37 • by Severity One
recursion

re·cur·sion [ri-kur-zhuhn]

See: recursion

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:38 • by @Deprecated (unregistered)
r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

cleaned code, modified function format_for_rtf . no more
numbered key to access video array elements, renamed all
camel toe vars, applied consistent coding formating


I like how all those changes were applied to 1 line. Wow!

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:44 • by Kris (unregistered)
309061 in reply to 309057
No, there are certainly cases where it makes sense. Namely if it were JavaScript, which I suspect is the case. In JavaScript, undefined == null, but undefined !== null. So the line is actually equivalent to:

[pre]
if (googleId === undefined)
googleId = null;
[/pre]

The above would have certainly have been clearer, but I strongly suspect that it was, in fact, the intent.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:44 • by parquet (unregistered)
309062 in reply to 309057
<?php
$googleId = 0;
var_dump($googleId);
$googleId = $googleId == null ? null : $googleId;
var_dump($googleId);

outputs

int(0)
NULL

*shrug*.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:45 • by Core Xii (unregistered)
309063 in reply to 309057
DES:
No, it will never make sense. What it actually does is:

googleId = googleId

No, he's right. For example in PHP, with loose comparison (==), false returns true when compared to null. But when _assigned_ to null, it'll be of type null.

So this code is entirely legit, IF the assumed conditions hold true.

See here for reference:
http://www.php.net/manual/en/types.comparisons.php
false, 0, an empty array and an empty string all == null.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:46 • by SCB
309064 in reply to 309060
@Deprecated:
r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

cleaned code, modified function format_for_rtf . no more
numbered key to access video array elements, renamed all
camel toe vars, applied consistent coding formating


I like how all those changes were applied to 1 line. Wow!

He forgot to add in the comment
"removed all carriage returns"

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:47 • by blah (unregistered)
309065 in reply to 309057
DES:
No, it will never make sense. What it actually does is:

googleId = googleId

Not if the language is javascript and googleId was undefined. It's probably still a WTF but there are differences (in javascript):

js> undefined == null
true
js> Number(null)
0
js> Number(undefined)
NaN

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:48 • by junkpile (unregistered)
309066 in reply to 309060
@Deprecated:
r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

cleaned code, modified function format_for_rtf . no more
numbered key to access video array elements, renamed all
camel toe vars, applied consistent coding formating


I like how all those changes were applied to 1 line. Wow!


Yea, because they couldn't possibly have committed multiple resources with the same comment at the same time...

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:50 • by Sir Read-a-Lot (unregistered)
309067 in reply to 309056
Lee K-T:
Why does he give names to his Camel's toes?

Why does a Russian have a camel in the first place?

*disclamer: this comment is not meant to imply in any way that Russians are in some way incapable or undeserving of having camels. It's just... well... nevermind.


CAPTCHA: nulla - any null that hasn't yet been checked to make sure it really is null.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:54 • by Aris (unregistered)
309068 in reply to 309055
As another reader told, a method is always executed using the virtual pointer, whatever the object is casted to. The only exception is the method used on super.

This looks like java written by a C++ guy. And I really think java is better that C++ in this regard.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:57 • by IronMensan (unregistered)
309069 in reply to 309049
anonymous coward:
FeepingCreature:
The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


Then it would still be a WTF for using operator overloading when it doesn't make sense (which is almost always. The only places where I can see operator overloading used sensibly is in math libraries)


I've defined += on container classes and I've defined == on a few classes

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 09:57 • by Steve H. (unregistered)
My initial thought on the last one was that someone was trying to use a variable that should have been declared volatile. Then I looked a little more carefully and realized it was more WTF than I initially thought.

Correct me if I'm wrong, but rewriting that code to be more readable produces this functionality:

if (googleId == null) {
googleId = null;
}
else {
googleId = googleId;
}

So contrary to the comment, it doesn't even ensure that googleId is null at all, as opposed to REALLY null (a comment I'd expect with a WTF line like googleId = googleId = null;)

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:00 • by Jake Boxer (unregistered)
In our Android app, we deal with a bunch of JSON parsing. Have a look at JSONObject.NULL:

http://developer.android.com/intl/de/reference/org/json/JSONObject.html#NULL

Since JsonObject.NULL.toString evaluates to "null" (even though JsonObject.NULL == null returns true), this was causing us to end up with "null" in a bunch of our views. We ended up wrapping it in a method that converts it to real null, just like this guy is doing in the last one.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:09 • by enfiskutensykkel
309072 in reply to 309055
sink:
((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().


Nope, not in Java.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:13 • by @Deprecated (unregistered)
309073 in reply to 309066
junkpile:
@Deprecated:
r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

cleaned code, modified function format_for_rtf . no more
numbered key to access video array elements, renamed all
camel toe vars, applied consistent coding formating


I like how all those changes were applied to 1 line. Wow!


Yea, because they couldn't possibly have committed multiple resources with the same comment at the same time...


Sorry, didn't realize this site was "Curious Perversions in Information Technology, But No Stupid Jokes Please"...


Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:17 • by bl@h (unregistered)
Since when are camels native to Russia?

captcha:nulla -> Make sure it is really nulla!

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:18 • by Daniel (unregistered)
309075 in reply to 309071
Then he'd test for NULL, not null (which is a reserved keyword in Java, so you can't possibly refer to something else). I still find the JavaScript explanation the most likely.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:18 • by snoofle
I'm a consultant, and I've never, ever done a check for really null.

Now I have to go back and redo all the Java code I've written in the past 15 years. Wonderful!

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:24 • by Whiskey, Eh? (unregistered)
void myLifeStory()
{
iReceiveHead = false;
iReceiveTail = false;

/* ... sigh..... */
}

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:26 • by junkpile (unregistered)
309078 in reply to 309073
@Deprecated:
junkpile:
@Deprecated:
r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

cleaned code, modified function format_for_rtf . no more
numbered key to access video array elements, renamed all
camel toe vars, applied consistent coding formating


I like how all those changes were applied to 1 line. Wow!


Yea, because they couldn't possibly have committed multiple resources with the same comment at the same time...


Sorry, didn't realize this site was "Curious Perversions in Information Technology, But No Stupid Jokes Please"...




Sorry, I'm not convinced that it was a purposeful stupid joke...

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:26 • by DCRoss
309079 in reply to 309043
You have not experienced Kernighan and Ritchie until you have read them in the original Russian.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:29 • by Callin
public static bool IsNotNotNotEmpty(string value)
{
return !IsNotNotEmpty(value);
}

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:36 • by @Deprecated (unregistered)
309082 in reply to 309078
junkpile:

Sorry, I'm not convinced that it was a purposeful stupid joke...


Hmmm, yes, they rarely are... Hopefully this will help to sort it out:

"If, in reading the following pages, you are uncertain as to whether a specific statement is meant seriously or not, simply apply this rule of thumb: If the statement makes you consider filing a lawsuit, I was kidding!"

~ Dave Barry

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:39 • by fubar (unregistered)
As already pointed out, strict comparison is required in PHP.

<?php
$googleId = null;
var_dump($googleId);

$googleId = 0;
var_dump($googleId);

$googleId = ($googleId === null) ? null : $googleId;
var_dump($googleId);
?>

Output:
NULL
int(0)
int(0)

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:49 • by Just an ordinary code monkey (unregistered)
309084 in reply to 309061
Kris:
No, there are certainly cases where it makes sense. Namely if it were JavaScript, which I suspect is the case. In JavaScript, undefined == null, but undefined !== null. So the line is actually equivalent to:

if (googleId === undefined)
googleId = null;

The above would have certainly have been clearer, but I strongly suspect that it was, in fact, the intent.


undefined is certainly a possible reason for this code, but he doesn't cater for it, which the comment suggests he intends to. I don't think undefined is meant to slip through the net in this code, although it does...

I think people are getting carried away on it because to make sure it's really null, most people would just do the following...

googleId = null;

No..?

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:50 • by ChrisB (unregistered)
Our company uses a similar variation of Hungarian Notation to name variables. I did get to have a chuckle recently at some permissions checking code (where strings are used to denote the permission type)...

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:53 • by Jumble (unregistered)
Do PHP users things that two WTFs make an acceptable piece of code?

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:54 • by junkpile (unregistered)
309087 in reply to 309082
@Deprecated:
junkpile:

Sorry, I'm not convinced that it was a purposeful stupid joke...


Hmmm, yes, they rarely are... Hopefully this will help to sort it out:

"If, in reading the following pages, you are uncertain as to whether a specific statement is meant seriously or not, simply apply this rule of thumb: If the statement makes you consider filing a lawsuit, I was kidding!"

~ Dave Barry


Hmmm, indeed. I wasn't kidding, but if quoting someone else helps you cover your apparently obvious stupid joke you were trying to convey, well done...

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 10:54 • by Tony (unregistered)
public bool HideCenterContent
{
set
{
centerBlockControl.Visible = false;
}
}


This should really be a Get not a set. What were they thinking! With a get you could go object.HideCentercontent!
But with a set, it would have to be object.HideCenterContent = some value. Crazy developers, they should really know better.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 11:02 • by Quirkafleeg (unregistered)
309089 in reply to 309063
Core Xii:
But when _assigned_ to null
… you get a compile-time error.

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 11:07 • by Quirkafleeg (unregistered)
309090 in reply to 309064
SCB:
@Deprecated:
I like how all those changes were applied to 1 line. Wow!
He forgot to add in the comment
"removed all carriage returns"
That wouldn't make any difference. One line before, one line afterwards.

Now, removing all line feeds – that would make a difference…

Re: Convoluted toString, Interesting Comments, and More

2010-05-19 11:09 • by Henning Makholm (unregistered)
public bool HideCenterContent {

set {
centerBlockControl.Visible = false;
}
unset {
centerBlockControl.Visible = true;
}
}
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment