Log in

View Full Version : Funny Code



keyboard
08-06-2012, 01:02 AM
Anyone seen some especially hilarious or painfull code over the years?

Found this whilst browsing the internet... can't remember where it's from now...




x = x;


When asked to explain their code, the person said "I wanted to make sure that x doesn't lose it's value".

molendijk
08-06-2012, 01:10 PM
This is hilarious, of course. But there are cases very similar to the one you mention where seemingly tautologous lines are not a real tautology. For instance, the following script will not work without the lines in red:

<script>
var x=document.createElement('div')
function hilarious(laughing,some_id)
{
x.innerHTML='<div>'+laughing+'<\/div>';
x.setAttribute("id",some_id);
ssome_id=some_id;
setTimeout('some_id=ssome_id',0);
setTimeout('document.getElementById(some_id).innerHTML=document.body.appendChild(x).innerHTML',100)
}
</script>

<a style="cursor: pointer" onclick="hilarious('hihi')">let us laugh</a>
===
Arie.

jscheuer1
08-06-2012, 05:20 PM
<noscript><!-- hide from older browsers
document.write('Your browser doesn\'t support javascript')
//--> end hiding
</noscript>

keyboard
08-06-2012, 10:15 PM
<noscript><!-- hide from older browsers
document.write('Your browser doesn\'t support javascript')
//--> end hiding
</noscript>

Wow, that's precious.... :D

Thanks for that molendijk!

EDIT - Here's some more from here (http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered?page=1&tab=votes#tab-top)


stop(); // Hammertime!


return 1; # returns 1


// Replaces with spaces the braces in cases where braces in places cause stasis
$str = str_replace(array("\{","\}")," ",$str);


Catch (Exception e) {
//who cares?
}


/* Emits a 7-Hz tone for 10 seconds.
True story: 7 Hz is the resonant frequency of a
chicken's skull cavity. This was determined
empirically in Australia, where a new factory
generating 7-Hz tones was located too close to a
chicken ranch: When the factory started up, all the
chickens died.
Your PC may not be able to emit a 7-Hz tone. */

main()
{
sound(7);
delay(10000);
nosound();
}


Not from the link provided, but still funny

motor[Wheel_Left] = 50;
motor[Wheel_Right] = 45; // to make it go in a straight line

keyboard
08-07-2012, 11:37 PM
Any more anyone?

williamsun
08-08-2012, 06:59 PM
<noscript><!-- hide from older browsers
document.write('Your browser doesn\'t support javascript')
//--> end hiding
</noscript>
Hilarious

jscheuer1
08-08-2012, 08:41 PM
Thanks.

This one actually works. I just find it a little humorous how it's worded (highlighted added due to lack of context):


(function(){
var dash = /-(.)/g;
function toHump(a, b){return b.toUpperCase();};
String.prototype.encamel = function(){return this.replace(dash, toHump);};
})();

keyboard
08-08-2012, 10:17 PM
I don't really get it??? :D

jscheuer1
08-09-2012, 02:17 AM
Which? What it does, or why (dash, toHump) is a little funny?

keyboard
08-09-2012, 02:20 AM
(dash, toHump)
that bit

jscheuer1
08-09-2012, 03:43 AM
Well, walk then.

keyboard
08-09-2012, 04:13 AM
Well, walk then.

Huh? :D



WOOT! 700th post!!!! (except not really cause we're in the lounge :D)

jscheuer1
08-09-2012, 05:05 AM
I have trouble explaining dirty jokes to my sister too.

traq
08-09-2012, 05:17 AM
lol.

This code is actually live on one of my sites. wasn't intentional.
$action = $_GET['lost'];

keyboard
08-09-2012, 05:34 AM
I have trouble explaining dirty jokes to my sister too.

I got the joke... I was curious if you'd explain it :D... so go on :D

P.s. what about



$randomvariableicantrememberthenameof = $_POST['mail'];

bernie1227
08-10-2012, 07:38 AM
My favorite ones to find in code tend to be those that tell me not to touch pieces of code:


/* seriously, don't touch this or people will die */



// magic do not touch



// don't change this or #%€& will hit the fan

jscheuer1
08-10-2012, 08:24 AM
/* seriously, don't touch this or people will die */



// magic do not touch



// don't change this or #%€& will hit the fan



// 'Hammer Time!' (U Can't Touch This)

bernie1227
08-10-2012, 08:57 AM
Haha, I like it, personally I actually like to write these kind of comments to myself so that I don't screw my code up, I saw a funny comic once where there were two software engineers standing over a computer and one says:
I don't get your code
The other says:
Neither do I, but it seems to work

keyboard
08-10-2012, 11:19 AM
// 'Hammer Time!' (U Can't Touch This)




stop(); // Hammertime!


I did it first! :D

molendijk
08-10-2012, 03:20 PM
I have some code that may not be funny, but it surely is funnily strange. It's about how javascript handles and/or statements. An and/or statement is only false when both members of the statement are false (as opposed to either...or statements that are only false when the members are both true or both false).
So this:
Premise: x1=x2
Conclusion: (since x1=x2), 'x1 is bigger than or equal to x2'
is a true statement.

Let's convert that to javascript. If we put:

<script>
var x1, x2;
x1=x2;
if(x1==x2 || x1>x2){alert('CORRECT.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).')} else {alert('WRONG.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).\nWhy am I getting this "else" alert that says I`m wrong?')}
</script>
we get the expected result.
But if we put

<script>
var x1, x2;
x1=x2;
if(x1>=x2){alert('CORRECT.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or)')} else {alert('WRONG.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).\nWhy am I getting this "else" alert that says I`m wrong?')}
</script>
we incorrectly get a non-expected result.
So using '||' gives the expected outcome, whereas '>=' makes trouble.
What makes things even more weird is that '>=' stops annoying us when we assign concrete values to x1 and x2, as in:

<script>
var x1=1, x2=1;
x1=x2;
if(x1>=x2){alert('CORRECT.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or)')} else {alert('WRONG.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).\nWhy am I getting this "else" alert that says I`m wrong?')}
</script>
What is going on here?
===
Arie.

djr33
08-10-2012, 04:30 PM
Arie, I'd guess that's because >= is strictly a mathematical operator, so it can't/won't handle non-numerical values properly.



Continuing on the comments discussion, it's always amusing to read a creatively commented script. At the top of my list I think are IPB and SMF forums' code, always complete with very strange sounding comments... something like "//put the dog in the doghouse" or equally strange things.
(Then as I begin to edit things, I begin to make complaints like "//because this is broken!!")
:)

jscheuer1
08-10-2012, 04:36 PM
Makes perfect sense.


>=

is a mathematical comparison operator. It type converts the items to be compared to numbers. If one or both of the items being compared is NaN, well NaN is equal to nothing, not even to itself.

When you use == || >, in javascript == is a type non-specific comparison operator, so anything that is roughly equivalent will match.


'1' == 1

is true. In your example it's:


undefined == undefined

As it so happens, I believe that:


null == undefined

and definitely that:


0 == false

those sort of comparisons are also true.

If you want a type specific comparison, use ===

With that undefined === undefined is still true, but those others are not. With type specific comparison you can always first covert both to a chosen type and then see if they're still equal.

I could go on and on with this sort of thing. But I think you get the point.

molendijk
08-10-2012, 05:03 PM
Thanks Daniel and John. I get the point.
Arie.

keyboard
08-10-2012, 10:55 PM
I have some code that may not be funny, but it surely is funnily strange. It's about how javascript handles and/or statements. An and/or statement is only false when both members of the statement are false (as opposed to either...or statements that are only false when the members are both true or both false).
So this:
Premise: x1=x2
Conclusion: (since x1=x2), 'x1 is bigger than or equal to x2'
is a true statement.

Let's convert that to javascript. If we put:

<script>
var x1, x2;
x1=x2;
if(x1==x2 || x1>x2){alert('CORRECT.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).')} else {alert('WRONG.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).\nWhy am I getting this "else" alert that says I`m wrong?')}
</script>
we get the expected result.
But if we put

<script>
var x1, x2;
x1=x2;
if(x1>=x2){alert('CORRECT.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or)')} else {alert('WRONG.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).\nWhy am I getting this "else" alert that says I`m wrong?')}
</script>
we incorrectly get a non-expected result.
So using '||' gives the expected outcome, whereas '>=' makes trouble.
What makes things even more weird is that '>=' stops annoying us when we assign concrete values to x1 and x2, as in:

<script>
var x1=1, x2=1;
x1=x2;
if(x1>=x2){alert('CORRECT.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or)')} else {alert('WRONG.\nWe have postulated that x1 is equal to x2, so x1 is equal to or bigger than x2 (inclusive or).\nWhy am I getting this "else" alert that says I`m wrong?')}
</script>
What is going on here?
===
Arie.



You lost me at javascript :D

molendijk
08-10-2012, 11:31 PM
Makes perfect sense.

>=
is a mathematical comparison operator. It type converts the items to be compared to numbers. If one or both of the items being compared is NaN, well NaN is equal to nothing, not even to itself.
Yes, I got it. The same holds for
!=. This explains why

<script>
if(NaN==NaN){alert('CORRECT')} else {alert('WRONG')}
if(NaN!=NaN){alert('CORRECT')} else {alert('WRONG')}
</script>
gives 'WRONG' first, then 'CORRECT'.
Thanks for the enlightment.
Arie.

bernie1227
08-11-2012, 12:19 AM
Wow, when did this thread become about actuall code? Just stumbled on some gems:


// I am not sure if we need this, but too scared to delete.

// I am not responsible of this code.
// They made me write it, against my will.

//Dear future me. Please forgive me.
//I can't even begin to express how sorry I am.

options.BatchSize = 300; //Madness? THIS IS SPARTA!

// I have to find a better job

// hack for ie browser (assuming that ie is a browser)

keyboard
08-11-2012, 12:24 AM
// this should work. Hold my beer will you?




//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 39
//




// When I wrote this, only God and I understood what I was doing
// Now, God only knows




// MSXML is... special.
// (Yes, we really do need fifty lines of code for IE and *one* for everything else)




// this code makes the bosses cd tray open at random intervals for no reason. As apparently I dont need to go the bank today.




aComment = 'this is not aComment' # this is aComment


---------------------------------------------------------------------------


Wow, when did this thread become about actuall code?
lol

bernie1227
08-11-2012, 01:00 AM
/* Seriously, people will die if you change this */



Thanks for reading my post keyboard, I've already done that one.

keyboard
08-11-2012, 01:05 AM
I deny this :D

bernie1227
08-11-2012, 01:15 AM
/* seriously, don't touch this or people will die */



Deny It all you want, doesn't make it false

jscheuer1
08-11-2012, 01:34 AM
if(ie){ /* Now I am become death, the destroyer of worlds */

keyboard
08-11-2012, 02:15 AM
if(ie){ /* Now I am become death, the destroyer of worlds */

Someone needs to learn what a grammar checker is....

bernie1227
08-11-2012, 02:55 AM
most used comment ever:


// TODO: Finish.

jscheuer1
08-11-2012, 04:21 AM
Someone needs to learn what a grammer checker is....

I'm not an ace grammarian, what's wrong with it in your opinion?

BTW, you misspelled grammar.

keyboard
08-11-2012, 06:00 AM
BTW, you misspelled grammar.
lol

Anyway, the phrase "Now I am become death, the destroyer of worlds" makes no sense... it'd have to be

"Now I am death, the destroyer of world"

or something like that....

traq
08-11-2012, 06:19 AM
lol

Anyway, the phrase "Now I am become death, the destroyer of worlds" makes no sense... it'd have to be

"Now I am death, the destroyer of world"

or something like that....

it's a quote (wikipedia.org/wiki/Bhagavad_Gita).

jscheuer1
08-11-2012, 06:33 AM
Yes it is a quote. And there's nothing wrong with it grammatically that I can see. Break it down:

"Now I am become death,"

That's clear enough if a bit overwrought. And who is this death that I become? Why:

"the destroyer of worlds"

of course.

molendijk
08-11-2012, 10:41 AM
Yes it is a quote. And there's nothing wrong with it grammatically that I can see.
I'm not a native speaker of English, so I'm not sure, but shouldn't that be I HAVE become Death? But perhaps it used to be I am become in middle or old English.
Arie.

jscheuer1
08-11-2012, 02:53 PM
That could be. The translation could have been made so long ago that a colloquial form which at the time was common and proper was used. Or the translator may have gone for a more literal interpretation, rather than one that made for good sounding modern English. Or they may have used that form to emphasize the immediacy of the event. Once you introduce the word "have" it makes it sound less immediate, somehow already slipping into the past.

In any case, I'm not convinced it's grammatically incorrect, though it might be. It would take an expert grammarian to tell us for sure. Even various experts at grammar might have different opinions about it.

djr33
08-11-2012, 11:28 PM
Aha, a linguistics discussion :)

The whole thing is fine except for "am become".

There's nothing wrong with that as an archaic form, but it's bizarre for modern English, to the point where I'd certainly call it incorrect.

It is likely either an old translation or intended to sound like an old translation. Often old documents (maybe a Latin text for example) are translated archaically even if they are translated today.

In earlier English (earlier Modern English-- Shakespeare also wrote in 'Modern English'-- Middle English and Old English looked very, very different, especially Old English-- unintelligible to all of us here), there was a distinction between transitive and intransitive verbs in perfect forms. When the verb had (or could have) an object, it used "have" as the auxiliary, but if it was an intransitive verb (such as 'become') then the auxiliary was 'be'. Note that this is the same system that exists in languages such as German and Italian (and even Basque) today (while other languages, such as Spanish, have the same have-only system of English).


To an English speaker today, it sounds like "am" is an extra word in the sentence.

So a modernized form would be either:
"Now I have become death, the destroyer of worlds"
"Now I become death, the destroyer of worlds" [not the originally intended meaning]


In short, this is just like archaic phrasing used in still-used translations of the bible.



Also, by the way, I'd like to add-- the have/be distinction was still in use (at least by some, especially in writing) until the 1800s :) Not so long ago.

molendijk
08-12-2012, 12:42 AM
Aha, a linguistics discussion :)
In earlier English [...], there was a distinction between transitive and intransitive verbs in perfect forms. When the verb had (or could have) an object, it used "have" as the auxiliary, but if it was an intransitive verb (such as 'become') then the auxiliary was 'be'.
My linguistic guess is that not all intransitive verbs took the auxiliary 'be'. They must have said 'I HAVE walked' in early English, not 'I AM walked', despite the fact that 'to walk' is intransitive, in the sense that it can't have a direct object. Or would you call 'to walk' a transitive verb, Daniel?
I think that 'I am become Death' was possible in early English because 'Death' attributes a quality to 'I' (the subject), just as in 'I am (the) Death'. Anyhow, that's still the modern linguistic situation in my native language (Dutch: 'ik BEN de dood geworden'), in German ('ich BIN der Tod geworden'), in French ('je SUIS devenu la Mort') and other languages ('ben'/'bin'/'suis' = 'am').
Btw, I wish more Americans and 'British' spoke more than one language (Daniel does!). We 'non-English-speaking-people' always have a disadvantage in discussions, because we must 'find our words'. That takes time. But I'm not complaining. That's not my character. (Or should I say: 'that's not IN my character', or 'that's not my NATURE', or 'that's not IN MY NATURE'?. I don't know).
===
Arie.

djr33
08-12-2012, 12:51 AM
My linguistic guess is that not all intransitive verbs took the auxiliary 'be'. They must have said 'I HAVE walked' in early English, not 'I AM walked', despite the fact that 'to walk' is intransitive, in the sense that it can't have a direct object. Or would you call 'to walk' a transitive verb, Daniel?Whatever the explanation, it's the same system as Italian and German. There has been plenty written about this, but the actual distinction is tricky. The simplest explanation is transitivity, but that's skipping some of the details. You know it from Dutch :) There might be slight variations from language to language, but I think you're right about 'walk', although I don't have any instincts/knowledge of the specific verbs in earlier English.


And yes, I'm proud to be in the (minority) multilingual group of Americans! (Although I must emphasize that I've studied a lot and speak a little-- still struggling with fluency in any of them, with my Spanish nearest, but still not quite there.)

molendijk
08-12-2012, 01:05 AM
I think you're right about transitive verbs. Any language I know (well or not that well) does what you claim.
No matter what your fluency is in other languages, I always feel happy to meet someone who is willing to 'go through the same linguistic trouble'.
Arie.

keyboard
08-12-2012, 01:14 AM
Aha, a linguistics discussion :)

The whole thing is fine except for "am become".

There's nothing wrong with that as an archaic form, but it's bizarre for modern English, to the point where I'd certainly call it incorrect.

It is likely either an old translation or intended to sound like an old translation. Often old documents (maybe a Latin text for example) are translated archaically even if they are translated today.

In earlier English (earlier Modern English-- Shakespeare also wrote in 'Modern English'-- Middle English and Old English looked very, very different, especially Old English-- unintelligible to all of us here), there was a distinction between transitive and intransitive verbs in perfect forms. When the verb had (or could have) an object, it used "have" as the auxiliary, but if it was an intransitive verb (such as 'become') then the auxiliary was 'be'. Note that this is the same system that exists in languages such as German and Italian (and even Basque) today (while other languages, such as Spanish, have the same have-only system of English).


To an English speaker today, it sounds like "am" is an extra word in the sentence.

So a modernized form would be either:
"Now I have become death, the destroyer of worlds"
"Now I become death, the destroyer of worlds" [not the originally intended meaning]


In short, this is just like archaic phrasing used in still-used translations of the bible.



Also, by the way, I'd like to add-- the have/be distinction was still in use (at least by some, especially in writing) until the 1800s :) Not so long ago.


Meaning I was right? :D
Has anyone read the thread title recently?

djr33
08-12-2012, 01:40 AM
Well, it's a quote that had a legitimate reason to be like it is. So it's not a grammatical mistake, it's just an archaic phrase. But yes, you were right that something was unusual about it.

As for the thread title... I think we've all shared what we have. Or is there more?

keyboard
08-12-2012, 02:04 AM
As for the thread title... I think we've all shared what we have. Or is there more?

I just found it funny that we got from funny code to grammatical discussion...

djr33
08-12-2012, 02:05 AM
Well, it is the lounge :)

bernie1227
08-12-2012, 02:06 AM
honestly, this thread is meandering quite a bit, we've gone from funny comments to actuall code and back and then to reflexive verbs, which i'm sure have a lot to do with funny comments.

keyboard
08-12-2012, 02:06 AM
Well, it is the lounge
True...

bernie1227
08-12-2012, 02:06 AM
Well, it is the lounge :)

I've always wondered how much you can actually get away with in the lounge (see keyboards yonkers thread)

keyboard
08-12-2012, 02:07 AM
Well, it didn't break any rules.... even though it was a bit pointless :p

bernie1227
08-12-2012, 02:08 AM
well I'm pretty sure my one word answer did

keyboard
08-12-2012, 02:09 AM
I'm pretty sure if either of us had been New Comers, we probably would have been warned or banned.... (mods?)

bernie1227
08-12-2012, 02:17 AM
eh, probably, does it take to get banned as a senior?

keyboard
08-14-2012, 02:42 AM
Found somemore -


// I don't know why I need this, but it stops the people being upside-down
x = -x;


# code below replaces code above - any problems?
# yeah, it doesn't ******* work.


} catch (PartInitException pie) {
// Mmm... pie


// This comment is self explanatory.


public boolean isDirty() {
//Why do you always go out and
return dirty;
}

bernie1227
08-14-2012, 02:58 AM
First one has already been posted

keyboard
08-14-2012, 03:22 AM
Where? (I couldn't find it)

bernie1227
08-14-2012, 03:23 AM
oh, nevermind, just looked similar my mistake