Comment On ISelfAware, Very Thorough, Crazy Hashmaps, and More

Seeing that I somehow neglected to publish an article yesterday, I figured today would be a great day for a big ole smorgasbord of interesting code. Enjoy! [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6Next »

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:05 • by Larry (unregistered)
the article:


if (_tblItem.getTable().getModel() != null
&& _tblItem.getTable() != null
&& _tblItem != null)


TRWTF is languages that read left-to-right.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:06 • by Bobbo (unregistered)
I, Robot

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:06 • by TGV
I can only hope they rolled a die to ensure this was actually random

And I hope they are in a universe where 215 is actually a prime.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:07 • by Uh... (unregistered)
public static int RANDOM_PRIME_NUMBER = 215

Ok, I see how this might be random when he entered it, but I do not see how it is prime.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:07 • by Mad Adder (unregistered)
"This is in our production code," notes Joseph Daigle, "I can only hope they rolled a die to ensure this was actually random."
public static int RANDOM_PRIME_NUMBER = 215;


Hrmm... not random, not a prime number. Looks like we got a winner here.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:09 • by One (unregistered)
Do we get to have a discussion about whether or not 1 is a prime number?

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:09 • by WthyrBendragon
I keep thinking that that getSelf() method should be Private. After all, wouldn't you want to be private while doing some sort of self exam?

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:09 • by cynical cynic (unregistered)
At last, the explanation to all the Bert Glanstrom comments!
public static boolean isFunnyOrInsightful(comment c)

{
return !isFunny(c) && !isInsightful(c);
}

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:10 • by Markp
323420 in reply to 323414
TGV:
I can only hope they rolled a die to ensure this was actually random

And I hope they are in a universe where 215 is actually a prime.


Maybe that code path is only taken if 1 == 0?

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:10 • by Bogolese (unregistered)
<div>ine

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:11 • by Mad Adder (unregistered)
323422 in reply to 323416
And TRWTF is a triple-simul-post... or me just not refreshing in the few seconds it took to type my comment.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:11 • by OPTIMUS PRIME (unregistered)
If by prime they mean divisible by itself, 1, and 5 then yes, 215 is a prime number.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:12 • by Fibonacci (unregistered)
"... 3. is for lucky :)"

priceless <3

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:15 • by Markp

// Do not remove the following line. HashMaps are crazy and point
// to old reference data even if they were instantiated fresh!
workMap.clear();


Come on, who among us hasn't sat debugging something so long that the logical conclusion is a conspiracy? Paranoia is the natural mental state.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:15 • by The Nerve (unregistered)
Fixed?

//public interface ISelfAware {
//
// /**
// * Useful in an MBean so that it can return a live reference to itself as a
// * method call
// *
// * @return reference to this object
// */
// public ISelfAware getSelf();
//}

//if(completed == 1)
// if(startdate[1] != 2)
month = startdate[2];
// else
// month = startdate[2];
//else
// month = startdate[2];

if (&& _tblItem != null != null
&& _tblItem.getTable() != null
_tblItem.getTable().getModel())

/* This program will only run if the laws of mathematics hold
if(1 == 0)
{
fprintf("Oh crap - we are not running in the correct Universe\n");
exit(17);
}*/

public static int FIXED_NONPRIME_NUMBER = 215;

/*3 times because if we have filter on some column -
clean only that data, and after that cleans everything
else (2.), and the 3. is for lucky :)
worksheet.Cells.ClearContents();
worksheet.Cells.ClearContents(); */
worksheet.Cells.ClearContents();

Map<TransactionId, List<BillingTransaction>> workMap
= new HashMap<TransactionsId, List<BillingTransaction>>();

// Do not remove the following line. HashMaps are crazy and point
// to old reference data even if they were instantiated fresh!
//workMap.clear();

public static boolean isNotAlphaNumeric(char c)
{
return !isLetter(c) && !isDigit(c);
}

<!-- <script type="text/javascript">document.write('</div>')</script>
<noscript></div></noscript> -->

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:15 • by WthyrBendragon
323428 in reply to 323417
One:
Do we get to have a discussion about whether or not 1 is a prime number?


Well, it is only integer factorable to 1 and itself so, yes, 1 is prime.

However, random it is not.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:16 • by Anonymous (unregistered)
I like the way there appears to be a dedicated error code for "not running in the correct Universe". I'd have gone for -42 instead of 17 but well done anyway. Wait, can you pass negative exit codes? I suppose it doesn't matter, if that error code ever gets returned we have to assume that the apocalypse is upon us.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:17 • by Anon a mouse (unregistered)
323430 in reply to 323423
OPTIMUS PRIME:
If by prime they mean divisible by itself, 1, and 5 then yes, 215 is a prime number.


Well itself 1, 5 and 43

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:18 • by frits

Arnold Vriezekolk writes, "one of the guys on our team likes to be thorough. Very, very thorough."

/* This program will only run if the laws of mathematics hold */
if(1 == 0)
{
fprintf("Oh crap - we are not running in the correct Universe\n");
exit(17);
}






Right. Because in your universe fprintf() doesn't need a file pointer.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:19 • by Remy Martin (unregistered)
I just got done refactoring all the references to logError to wtf and checking it into the application.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:22 • by Short-ed (unregistered)
Here's another bit of code that I came across recently, taken from production code, of course!


int16_t wrapCounts( int16_t delta ) {
const short SIZE_SHORT = 32768;
int16_t ret;

if (delta < -SIZE_SHORT)
ret = -(2 * SIZE_SHORT + delta);
else if (delta > SIZE_SHORT)
ret = (2 * SIZE_SHORT - delta);
else
ret = delta;

return ret;
}


Enjoy!


Captcha: feugiat - contrapuntal Fiat

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:24 • by DOA
323434 in reply to 323426
Markp:
Come on, who among us hasn't sat debugging something so long that the logical conclusion is a conspiracy?
The sad part is I completely agree with this.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:24 • by notovny (unregistered)
323435 in reply to 323428
The standard formulation of the Fundamental Theorem of Arithmetic requires that 1 not be considered a prime number.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:26 • by Old Smith (unregistered)
I rolled a die while reading this

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:28 • by Matt (unregistered)
323437 in reply to 323433
Short-ed:
Here's another bit of code that I came across recently, taken from production code, of course!


int16_t wrapCounts( int16_t delta ) {
const short SIZE_SHORT = 32768;
int16_t ret;

if (delta < -SIZE_SHORT)
ret = -(2 * SIZE_SHORT + delta);
else if (delta > SIZE_SHORT)
ret = (2 * SIZE_SHORT - delta);
else
ret = delta;

return ret;
}


Somebody missed the day when they talked about variables having finite space in memory and not being drawn out of the ether.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:30 • by anon (unregistered)
For those unable to read this comment, it says:
<NoComment>For those unable to read this comment, it says:
<NoComment>For those unable to read this comment, it says:
<NoComment>For those unable to read this comment, it says:
<NoComment>For those unable to read this comment, it says:
<NoComment>For those unable to read this comment, it says:
<NoComment>For those unable to read this comment, it says:

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:31 • by An Non (unregistered)
Actually I think I know what the ISelfAware is trying to achieve - bypassing the proxy logic and pass a direct reference to the original java object when instantiated within the same JVM. Messy and badly named... but I worryingly believe I understand what they meant to achieve (i.e. a badly thought out early optimisation)

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:32 • by operagost
323440 in reply to 323436
Old Smith:
I rolled a die while reading this

http://xkcd.com/221/

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:32 • by Bert Glanstron (unregistered)
323441 in reply to 323419
Dear cynical cinic,

In case you can’t tell, this is a meta-joke comment. The fact that you insist on bashing people who beat old memes clearly shows that you’re too mature and too intelligent to be posting on TDWTF.

Go back to your Starbucks.

Sincerely,
Bert Glanstron

[Captcha: commoveo - The people's SUV!]

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:33 • by Ancient Mathematician (unregistered)
323442 in reply to 323428
WthyrBendragon:
One:
Do we get to have a discussion about whether or not 1 is a prime number?


Well, it is only integer factorable to 1 and itself so, yes, 1 is prime.

However, random it is not.

Well, if you were old enough, you'd know that 1 is not even a number, so it can't be a prime.
And if you're young enough, you should know that 1 is a unit, so it can't be a prime.
Only if you're stuck some time between -200 and 1900 is 1 a prime.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:34 • by Anonymous (unregistered)
323443 in reply to 323431
frits:

/* This program will only run if the laws of mathematics hold */
if(1 == 0)
{
fprintf("Oh crap - we are not running in the correct Universe\n");
exit(17);
}

Right. Because in your universe fprintf() doesn't need a file pointer.

You can't just assume this is C/C++. Plenty of other languages have an fprintf function and not all require a file pointer. In Matlab, for example, the fprintf function writes to the screen if no file ID is provided.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:35 • by Anonymous Kernel Hacker (unregistered)
I think certain versions of Linux have included the line

if(false)panic();

just to verify that boolean logic is operating correctly.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:36 • by briggs davis (unregistered)
323445 in reply to 323427
The Nerve:
Fixed?

//public interface ISelfAware {
//
// /**
// * Useful in an MBean so that it can return a live reference to itself as a
// * method call
// *
// * @return reference to this object
// */
// public ISelfAware getSelf();
//}

//if(completed == 1)
// if(startdate[1] != 2)
month = startdate[2];
// else
// month = startdate[2];
//else
// month = startdate[2];

if (&& _tblItem != null != null
&& _tblItem.getTable() != null
_tblItem.getTable().getModel())

/* This program will only run if the laws of mathematics hold
if(1 == 0)
{
fprintf("Oh crap - we are not running in the correct Universe\n");
exit(17);
}*/

public static int FIXED_NONPRIME_NUMBER = 215;

/*3 times because if we have filter on some column -
clean only that data, and after that cleans everything
else (2.), and the 3. is for lucky :)
worksheet.Cells.ClearContents();
worksheet.Cells.ClearContents(); */
worksheet.Cells.ClearContents();

Map<TransactionId, List<BillingTransaction>> workMap
= new HashMap<TransactionsId, List<BillingTransaction>>();

// Do not remove the following line. HashMaps are crazy and point
// to old reference data even if they were instantiated fresh!
//workMap.clear();

public static boolean isNotAlphaNumeric(char c)
{
return !isLetter(c) && !isDigit(c);
}

<!-- <script type="text/javascript">document.write('</div>')</script>
<noscript></div></noscript> -->

ironically, your comment contains many comments.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:39 • by Dani Messerman (unregistered)
323446 in reply to 323423
No, because it's also divisible by 43 :)

TRWTF is CS of course...

2010-09-29 09:40 • by DaveK
Actually, no, it's bloody Akismet, which wouldn't let me post the source of the mangled link in the article because it looked spammy, but is perfectly happy to let me post this link http://pastebin.com/J5tAekpK to the post content instead.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:41 • by Dani Messerman (unregistered)
323448 in reply to 323423
OPTIMUS PRIME:
If by prime they mean divisible by itself, 1, and 5 then yes, 215 is a prime number.

Forgot to quote this in my previous comment ^^

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:41 • by frits
323449 in reply to 323443
Anonymous:
frits:

/* This program will only run if the laws of mathematics hold */
if(1 == 0)
{
fprintf("Oh crap - we are not running in the correct Universe\n");
exit(17);
}

Right. Because in your universe fprintf() doesn't need a file pointer.

You can't just assume this is C/C++. Plenty of other languages have an fprintf function and not all require a file pointer. In Matlab, for example, the fprintf function writes to the screen if no file ID is provided.


OK, you out-nerded me there (that's not difficult, btw). You could also come up with some #define scenario that would allow that (or a user function prototype). However, snippets posted on TDWTF is supposed to be professional production code, so please don't mention Matlab. Additionally, those aren't Matlab comments, are they?

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:41 • by v (unregistered)
323450 in reply to 323415
Uh...:
public static int RANDOM_PRIME_NUMBER = 215

Ok, I see how this might be random when he entered it, but I do not see how it is prime.


public static NOT_RANDOM_NOT_PRIME_BUT_PROBABLY_NOT_A_NUMBER = 215

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:46 • by NullPointerException (unregistered)
323451 in reply to 323449
frits:
However, snippets posted on TDWTF is supposed to be professional production code, so please don't mention Matlab.

I would be pretty surprised if there wasn't at least one case of someone using Matlab for production purposes.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:47 • by itsmo (unregistered)
323452 in reply to 323417
One:
Do we get to have a discussion about whether or not 1 is a prime number?


Do we get to have a discussion about whether or not 1 is a number?

FTFY

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:48 • by Anonymous (unregistered)
323453 in reply to 323442
Ancient Mathematician:
WthyrBendragon:
One:
Do we get to have a discussion about whether or not 1 is a prime number?


Well, it is only integer factorable to 1 and itself so, yes, 1 is prime.

However, random it is not.

Well, if you were old enough, you'd know that 1 is not even a number, so it can't be a prime.
And if you're young enough, you should know that 1 is a unit, so it can't be a prime.
Only if you're stuck some time between -200 and 1900 is 1 a prime.

Hey there Ancient Mathematician, you might be just the person I need to help me with an ancient Roman math problem. The following sum is written in Roman numerals. Can you solve it and provide your answer also in Roman numerals?

(IV + I) - V = ?

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:49 • by Steve The Cynic
323454 in reply to 323444
And don't forget the code I found a very long time ago, in the Technical Reference manual for the IBM PC/XT (or maybe it was the PC/AT - I said it was a long time ago). This was the time when IBM published the assembly source of the BIOS in the Tech Ref manual, and the first few instructions executed after the escape from 0FFFFh:0000-land[1] consisted of stuffing a value into one of the machine's 16-bit registers and proving that it could be passed from register to register, hitting all of them. If the original value did not emerge at the other end, the BIOS panicked.

[1] All versions of the 8086 processor family start in something that approximates to the 8086's real mode (exception: the 80376 started in protected mode as it was an abortive attempt to get away from real mode. It failed in the market) at a 16:16 address of 0xFFFF:0x0000. They have 16 bytes to jump somewhere else before they fall off the end of the world and start executing the real-mode interrupt vector table. It is a really good idea to make sure that this part of the BIOS ROM contains just a far jump.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:55 • by Oh THAT Brian! (unregistered)
323455 in reply to 323423
Also divisible by 43 - really a good example of a random prime number!

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:55 • by anon (unregistered)
323456 in reply to 323426
Markp:

// Do not remove the following line. HashMaps are crazy and point
// to old reference data even if they were instantiated fresh!
workMap.clear();


Come on, who among us hasn't sat debugging something so long that the logical conclusion is a conspiracy? Paranoia is the natural mental state for a software developer.


FTFY

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:55 • by Steve The Cynic
323457 in reply to 323453
Anonymous:
Hey there Ancient Mathematician, you might be just the person I need to help me with an ancient Roman math problem. The following sum is written in Roman numerals. Can you solve it and provide your answer also in Roman numerals?

(IV + I) - V = ?

Ah, but you forget that the things we call Roman numerals were for writing down numbers, not for performing arithmetic. One of the principal advantages of the modern versions of Arabic numerals (the 0..9 system that we use today) is that they use the same notation for writing down numbers and for doing arithmetic. The Romans used a form of abacus (note that the wire-and-bead calculators that we call abacuses are in fact NOT abacuses) when performing non-trivial arithmetic.

All that, of course, does not change the fact that there is no way to use Roman number-recording-notation to write zero.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 09:59 • by Severity One
"I could make a smart-ass comment about needing a reference to get a reference, but I think the code speaks for itself."

So make the method static!

Really, some people know nothing about programming.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 10:00 • by THE NUMBER ONE (unregistered)
323459 in reply to 323452
Do we get to have a discussion about whether or not I am a number?

FTFY

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 10:00 • by Pyrexkidd (unregistered)
323460 in reply to 323435
notovny:
The standard formulation of the Fundamental Theorem of Arithmetic requires that 1 not be considered a prime number.


An element p of the ring D, nonzero and not a unit, is called prime if it can not be decomposed into factors p=ab, neither of which is a unit in D.
http://primes.utm.edu/notes/faq/one.html


and now it is all clear. whew.

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 10:01 • by itsmo (unregistered)
323461 in reply to 323457
Steve The Cynic:
Anonymous:
Hey there Ancient Mathematician, you might be just the person I need to help me with an ancient Roman math problem. The following sum is written in Roman numerals. Can you solve it and provide your answer also in Roman numerals?

(IV + I) - V = ?

Ah, but you forget that the things we call Roman numerals were for writing down numbers, not for performing arithmetic. One of the principal advantages of the modern versions of Arabic numerals (the 0..9 system that we use today) is that they use the same notation for writing down numbers and for doing arithmetic. The Romans used a form of abacus (note that the wire-and-bead calculators that we call abacuses are in fact NOT abacuses) when performing non-trivial arithmetic.

All that, of course, does not change the fact that there is no way to use Roman number-recording-notation to write zero.


There is also a way of doing arithmetic with Roman numerals:

http://mathforum.org/dr.math/faq/faq.roman.html#calc

BTW Askimet is a fucking idiot - can't put URL tags round this^^

Re: ISelfAware, Very Thorough, Crazy Hashmaps, and More

2010-09-29 10:01 • by Anonymous (unregistered)
323462 in reply to 323449
frits:
Anonymous:
frits:

/* This program will only run if the laws of mathematics hold */
if(1 == 0)
{
fprintf("Oh crap - we are not running in the correct Universe\n");
exit(17);
}

Right. Because in your universe fprintf() doesn't need a file pointer.

You can't just assume this is C/C++. Plenty of other languages have an fprintf function and not all require a file pointer. In Matlab, for example, the fprintf function writes to the screen if no file ID is provided.

OK, you out-nerded me there (that's not difficult, btw). You could also come up with some #define scenario that would allow that (or a user function prototype). However, snippets posted on TDWTF is supposed to be professional production code, so please don't mention Matlab. Additionally, those aren't Matlab comments, are they?

No, those aren't Matlab comments. Matlab was just a random example of a language with its own implementation of fprintf but you're right, the less said about it the better. Weak dynamic typing is surely the work of the devil (great source of WTF though).
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6Next »

Add Comment