Comment On To the Hexth Degree

I have a policy that I try follow regarding duplicate concepts: I'll only post the concept again if the implementation somehow outdoes the previous. You may have guessed by the title, but today's example is from one of the more complex realms of mathematics and computer science: hexadecimal. Today's example is actually the sixth post of its kind. David H's former colleague now holds the "hex" prize for using no less than 5,000 lines to convert a byte array to hexadecimal, something which could normally be done with a single line of Java code ... [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: To the Hexth Degree

2006-03-24 14:52 • by apaq11
wow that is really something to be proud of right there.

Re: To the Hexth Degree

2006-03-24 14:52 • by Seltsam
It's enterprisey!

Re: To the Hexth Degree

2006-03-24 14:54 • by Ken Nipper
65577 in reply to 65576
Sounds like LOC to me.........

Re: To the Hexth Degree

2006-03-24 14:54 • by no name
Some one got paid by the line.



I hope....

Re: To the Hexth Degree

2006-03-24 14:56 • by jb
At least it's well-commented!

Re: To the Hexth Degree

2006-03-24 14:57 • by Brendan Kidwell
Holy crap! Is this some kind of joke? This is beyond brillant levels of productivity. How did this happen?

Re: To the Hexth Degree

2006-03-24 14:57 • by Morthy
65582 in reply to 65580
Anonymous:
At least it's well-commented!


True that!

I bet its done by pay per line.

Re: To the Hexth Degree

2006-03-24 14:58 • by ferrengi
OK then. I guess it was a slow day at the office and David's colleague felt the need to spend the entire day reinventing the wheel.
Also is funny how he feels the need to have 20 character long constants to represent the numbers 1, 2, 3 and 4.
What happens if the binary number has more than 4 bits?
I guess this function wouldn't work eh...
I cannot immediately detect any logic errors in this so I guess he should be congratulated for at least reinventing the wheel without creating any fatal flaws in the application.
Also, I doesn't look like this was really 5000 lines of actual code. There are a lot of lines being taken up by useless comments and a lot of whitespace. This probably could've been done with only 1000 lines of code.

This one is a little bit of a letdown compared to the highly entertaining WTFs of the past 2 weeks.

Re: To the Hexth Degree

2006-03-24 14:58 • by Maxim
Brilliant!

Well... not really... he actually did 5000 LOC

what about being paid per lines?

Re: To the Hexth Degree

2006-03-24 14:59 • by loneprogrammer
If only Java had provided a way to loop, he wouldn't have been forced to do it with nothing but if statements.


OH WAIT, IT DOES HAVE LOOPS! 

Re: To the Hexth Degree

2006-03-24 14:59 • by mrsticks1982

i bet I could do it faster by hand than this code ... where the heck was the manager ... hmm maybe he was the manager and thought he was the best programmer in the world ..


oh well, I hope this programmer was given the old yeller for this hideous creation

Re: To the Hexth Degree

2006-03-24 15:01 • by toxik
65587 in reply to 65578
Someone wasn't too pleased to get fired I guess :P

Re: To the Hexth Degree

2006-03-24 15:04 • by lizardfoot
It's difficult to type a response when your eyes have melted out of your head from looking at code like that.

Good thing it's Friday.  I have all weekend to recuperate.


Re: To the Hexth Degree

2006-03-24 15:10 • by cconroy
65591 in reply to 65589
Deal Lord in
Heaven.  At least it's nicely commented.  I especially like
how he keeps referring to "an hexadecimal".  When did the 'h'
become silent?



Re: To the Hexth Degree

2006-03-24 15:11 • by cconroy
65592 in reply to 65591
Er, that would be "Dear Lord", of course.



Re: To the Hexth Degree

2006-03-24 15:11 • by lizardfoot
Alex Papadimoulis:
  /**

* The number of hexadecimal characters per byte.
*/

public static final int NUMBER_OF_HEXADECIMAL_CHARACTERS_PER_BYTE = 2;



This is my favorite line.  So descriptive, not only in name, but also in documentation. 


/**
 * this is the value which helps us determine the radius of a circle
 */
public static final int VALUE_THAT_HELPS_US_DETERMINE_THE_RADIUS_OF_A_CIRCLE = 3.14;

Re: To the Hexth Degree

2006-03-24 15:13 • by Damn Yank
65595 in reply to 65591
This must be cockney code!

Re: To the Hexth Degree

2006-03-24 15:14 • by Burning Eyes
65596 in reply to 65593
public static final String HEX_CHARS = "0123456789ABCDEF";
public char convertBitsToHexadecimalCharacter(boolean bit1,boolean bit2,boolean bit3,boolean bit4) {
   return HEX_CHARS.charAt((bit1?8:0)+(bit2?4:0)+(bit3?2:0)+(bit4?1:0));
}


Oh forgive me, I had to write this to fix my eyes...

Re: To the Hexth Degree

2006-03-24 15:15 • by Oliver Klozoff
I want to see his Octal class.

Re: To the Hexth Degree

2006-03-24 15:15 • by Sean
65598 in reply to 65589
lizardfoot:
It's difficult to type a response when your eyes have melted out of your head from looking at code like that.

Good thing it's Friday.  I have all weekend to recuperate.




The tears from my laughter just shorted out my keyboard.  I had to get a new one.

Re: To the Hexth Degree

2006-03-24 15:18 • by Ytram
65599 in reply to 65591
cconroy:
Deal Lord in
Heaven.  At least it's nicely commented.  I especially like
how he keeps referring to "an hexadecimal".  When did the 'h'
become silent?





I think that is proper British english.  I'm not 100% sure, but I know I have see "an" in front of 'h' words quite a bit when reading british articles and literature.  Older english literature especially.

Re: To the Hexth Degree

2006-03-24 15:18 • by DiamondDave
65600 in reply to 65593
lizardfoot:
Alex Papadimoulis:
  /**
* The number of hexadecimal characters per byte.
*/

public static final int NUMBER_OF_HEXADECIMAL_CHARACTERS_PER_BYTE = 2;



This is my favorite line.  So descriptive, not only in name, but also in documentation. 


/**
 * this is the value which helps us determine the radius of a circle
 */
public static final int VALUE_THAT_HELPS_US_DETERMINE_THE_RADIUS_OF_A_CIRCLE = 3.14;





I remember Eclipse's auto-generated comments looking like
this....  After all, if one has to write 5000 lines of meaningless
code like this, it helps to save some time by having your IDE generate
your comments for you :)

Re: To the Hexth Degree

2006-03-24 15:20 • by SilverDirk
My personal favorite is

static final Char[] hexChars="0123456789ABCDEF".getChars();
char toHex(int val) { return hexChars[val&0xF]; }

and then use varieties of it in a loop to convert however many you need

though of course Java provides
String Integer.toString(int value, int radix);

(and no, I'm not going to use IE just so I can add formatting to this)

Re: To the Hexth Degree

2006-03-24 15:22 • by meh
65603 in reply to 65591
about 'an hour' ago.  :p

Re: To the Hexth Degree

2006-03-24 15:26 • by SilverDirk
65604 in reply to 65602
Oh, and in C its even more fun

char toHex(int val) { return "0123456789ABCDEF"[val&0xF]; }

Re: To the Hexth Degree

2006-03-24 15:27 • by VGR
There is a first time for everything.  And today is the first time I feel I must claim that this WTF must be made up.



We are getting close to April 1, after all.



I've seen many people re-implement functionality Java already provides
because they think they can do it better.  I've seen it so many
times I've practically memorized the tirade I give them at code reviews.



But this... this is so above and beyond the call of "I'd rather do it
my way" that I just can't imagine anyone sleeping at night after
writing it.



I can, however, imagine that whoever wrote it went on a campaign to try
to get everyone else on the team to use it wherever the need to convert
bytes to hex strings arose.  Bad frameworks are as common as
fungus and about as resistant to being cleaned up.

Re: To the Hexth Degree

2006-03-24 15:27 • by rob_squared
65606 in reply to 65580
Anonymous:
At least it's well-commented!


He forgot the *hiccup* notations to indicate his drunkenness.

Re: To the Hexth Degree

2006-03-24 15:28 • by Cassandra
65607 in reply to 65603
oh my hat that hurt.  It burns!

Re: To the Hexth Degree

2006-03-24 15:28 • by bcammack

I can't help but feel that this is an example of how a person can be intelligent and educated regarding computers and programming, but doesn't have that creative "something" that makes a truly good programmer.   Yeah, it compiles and yeah, it works, but...


I liken it to somebody who really, really wants to play the guitar, but doesn't have a lick of innate creative capacity for it.  They can practice their brains out for years, but never be more than an ordinary hack.   I've seen this before.  My cousin is/was a musical virtuoso who could play practically any instrument you handed him extremely well.  My older brother, OTOH, loves music dearly and has practiced and played the guitar for over four decades, yet is, to put it charitably, "adequate" at it.

Re: To the Hexth Degree

2006-03-24 15:29 • by marvin_rabbit
65609 in reply to 65592
cconroy:
cconroy:
Deal Lord in
Heaven.  At least it's nicely commented.  I especially like
how he keeps referring to "an hexadecimal".  When did the 'h'
become silent?



Er, that would be "Dear Lord", of course.




Oh, I thought you were talking about the Patron Saint of Car Salesmen.

Re: To the Hexth Degree

2006-03-24 15:32 • by rob_squared
65610 in reply to 65592
cconroy:
Er, that would be "Dear Lord", of course.





Oh, I thought you were referring to ebay.

Re: To the Hexth Degree

2006-03-24 15:33 • by nitpick
65611 in reply to 65591
cconroy:
Deal Lord in
Heaven.  At least it's nicely commented.  I especially like
how he keeps referring to "an hexadecimal".  When did the 'h'
become silent?

cconroy:
Er, that would be "Dear Lord", of course.

lol

Re: To the Hexth Degree

2006-03-24 15:33 • by WWWWolf
Looks like the work of a person who didn't know anything about Programming, sat through two lectures of Haskell, and never quite got hang of these Leet Advanced Features...

There's functional programming and then there's functional functional programming.

Re: To the Hexth Degree

2006-03-24 15:37 • by lamborghini
Alex Papadimoulis:

  /**
   * The '1' hexidecimal character.
   */

  public static final char ONE = '1';



 

mmmm k, thx.

 

[:D][:D][:D]

Re: To the Hexth Degree

2006-03-24 15:38 • by marvin_rabbit
65615 in reply to 65605
VGR:
There is a first time for everything.  And today is the first time I feel I must claim that this WTF must be made up.



We are getting close to April 1, after all.



I've seen many people re-implement functionality Java already provides
because they think they can do it better.  I've seen it so many
times I've practically memorized the tirade I give them at code reviews.



But this... this is so above and beyond the call of "I'd rather do it
my way" that I just can't imagine anyone sleeping at night after
writing it.



I can, however, imagine that whoever wrote it went on a campaign to try
to get everyone else on the team to use it wherever the need to convert
bytes to hex strings arose.  Bad frameworks are as common as
fungus and about as resistant to being cleaned up.

Yes, and surely not by reusing the code.  Instead it should be copy-pasted everywhere it's needed.

More effecient to do it in-line, you know.

Re: To the Hexth Degree

2006-03-24 15:39 • by ammoQ
This looks like a practical joke from an unfortunate programmer whose
performance is measured in LOC per day and who is tortured with overly
strict requirements regarding comments, constants etc.

Re: To the Hexth Degree

2006-03-24 15:43 • by WWWWolf
For whatever it's worth, this is what I did once...

#ifndef ASM_HEXIFY
   const char hexchars[] = {48,49,50,51,52,53,54,55,56,57,1,2,3,4,5,6};
#  define hex_low(what) (hexchars[((what) & 0x0F)])
#  define hex_hi(what) (hexchars[(((what) & 0xF0) >> 4)])
#else
#  define hex_low(what) hex_low_asm(what)
#  define hex_hi(what) hex_hi_asm(what)
#endif

...and before you complain about the character values, remember that all the world is not ASCII. =(

The assembler version of these routines sucked for some reason or other...


Re: To the Hexth Degree

2006-03-24 15:46 • by Valdas
Hey, I've spotted another WTF: they did not declare constants for lowercase numbers ;)



public static final char lower_1 = '1';



That would be priceless.. Also, more LOCs.



Re: To the Hexth Degree

2006-03-24 15:46 • by ptomblin
65620 in reply to 65596
Something wrong with String.toHexString(int i)?

Re: To the Hexth Degree

2006-03-24 15:53 • by BlackTigerX
Alex Papadimoulis:

  public static final int NUMBER_OF_HEXADECIMAL_CHARACTERS_PER_BYTE = 2;


hey!!... truth is how you define it


besides, this makes it really scalable

Re: To the Hexth Degree

2006-03-24 15:56 • by PCBiz


If he gets paid by the line I hope none of his future
employers see this code.  Boy what a waste of time.  Can you imagine
the frustration he must have had when someone pointed out that he just has
reinvented the wheel? 



Re: To the Hexth Degree

2006-03-24 16:00 • by Mike
65624 in reply to 65599
    Only if the next word starts with a vowel, or a silent consonant.  Eg: an apple, an hotel (if you don't pronounce the "h", as some people don't).

Re: To the Hexth Degree

2006-03-24 16:02 • by GoatCheez
Today is a good example of how not to build enterprise class software. First, pick a language that is has a lot of hype around it such as java. Then, disregard all concern for performance, because we all know you can just through a faster machine at it. Finally, hire a skilled programmer and tell them that they will get paid by the number of lines of code they write, and that you expect them to comment every single line of code. The result will be a very slow, but easily maintainable piece of crap.

The above example was most likely generated by a programmer that was paid by the number of lines of code he or she produced. The programmer then creates a program to output this code in oh, lets say about five hours to give him or her time to debug, surf the net, and just screw around... After done with the generater, the programmer runs it, and then sits around for the next week doing nothing because they were able to make a program that wrote 5000 lines of code that is clean, commented, and technically correct...

Of course, we all know what we would have done had this project been our baby...

Re: To the Hexth Degree

2006-03-24 16:05 • by MikeMontana
At 5000 lines of code, you would wind up with shorter code by writing:



for(int a; a=0; a < array.length())

{

  switch(array[a]) {

    case 0b00000001: ...

     ....

    case 0b11111111: ...

}



...that would come to about 1000 lines. 1/5th the size for 256 times
the stupidity.  Despite the absolute terribleness of this
implementation, what bothers me more-so is the fact that an entire
class has been designed and declared for such a trivial procedure. In
terms of overhead to benefit, this one outsinks the titanic.

Re: To the Hexth Degree

2006-03-24 16:08 • by stephen
65630 in reply to 65591
cconroy:
Deal Lord in
Heaven.  At least it's nicely commented.  I especially like
how he keeps referring to "an hexadecimal".  When did the 'h'
become silent?







Maybe he's french.

Re: To the Hexth Degree

2006-03-24 16:09 • by HatTrick
65631 in reply to 65593
lizardfoot:
Alex Papadimoulis:

  /**

* The number of hexadecimal characters per byte.
*/

public static final int NUMBER_OF_HEXADECIMAL_CHARACTERS_PER_BYTE = 2;




This is my favorite line.  So descriptive, not only in name, but also in documentation. 


/**
 * this is the value which helps us determine the radius of a circle
 */
public static final int VALUE_THAT_HELPS_US_DETERMINE_THE_RADIUS_OF_A_CIRCLE = 3.14;


OMG I am not sure which I am laughing harder at..the WTF or this comment.

Re: To the Hexth Degree

2006-03-24 16:12 • by hem
65632 in reply to 65625
Guys, I'm putting this gem into my library of reusable code. Someday this piece will save my life.

Re: To the Hexth Degree

2006-03-24 16:12 • by Digitalbath
65633 in reply to 65599

Ytram:
cconroy:
Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?



I think that is proper British english.  I'm not 100% sure, but I know I have see "an" in front of 'h' words quite a bit when reading british articles and literature.  Older english literature especially.


Maybe he was speaking in pirate.  "An 'exidecimal is upon us, ye lads.  Hard to port!" 


Maybe not...it was funny in my head though.

Re: To the Hexth Degree

2006-03-24 16:17 • by PresidentBeef
65634 in reply to 65599
Ytram:
cconroy:
Deal Lord in
Heaven.  At least it's nicely commented.  I especially like
how he keeps referring to "an hexadecimal".  When did the 'h'
become silent?





I think that is proper British
english.  I'm not 100% sure, but I know I have see "an" in front
of 'h' words quite a bit when reading british articles and
literature.  Older english literature especially.






The rule is, use 'an' if it makes a vowel sound. So, 'an hour' (sounds like 'our'), but 'a horse'.



But I don't think 'hexadecimal' starts with a vowel sound, so the original point stands.

Re: To the Hexth Degree

2006-03-24 16:17 • by Iago
65635 in reply to 65599
Ytram:

I think that is proper British english.  I'm not 100% sure, but I know I have see "an" in front of 'h' words quite a bit when reading british articles and literature.

Nope.  Modern British follows the same rules as American (i.e. you go by the pronunciation, "an hour" but "a hotel").  Traditionally there was a rule that where a word began with "h" and the first syllable was unaccented, then you'd write "an", so "a hospital" but "an hotel", but that is now obsolete and only used by the stuffiest pedants.  No literate Briton ever wrote "an hospital".

As for the WTF... to think I was joking when I posted something vaguely similar in the other thread!  (Though, to be fair, this is a billion times worse than my version...)
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment