Comment On Pascal Strings

Originally posted by "JukeboxJim"... [expand full text]
« PrevPage 1 | Page 2Next »

Re: Pascal Strings

2008-04-11 08:05 • by NaN
*Blink*.

Re: Pascal Strings

2008-04-11 08:09 • by Vollhorst (unregistered)
public static final char[] FILENOTFOUND = {'F','i','l','e',' ','n','o','t',' ','f','o','u','n','d'}; is missing!

Re: Pascal Strings

2008-04-11 08:12 • by Rick
I see the WTF.
public static final char[] NaN = {'N','a','N'};
should be:
public static final byte[] NaN = {'N','a','N'};

Re: Pascal Strings

2008-04-11 08:14 • by SlyEcho (unregistered)

switch(pstring.length)
{
case 1:
return pstring[]PSTRING_SIZE_OFFSET] == 0;
case 16 < 0:


How does it even compile, can you switch on booleans and ints at the same time? It would work in C but in Java?

Or is it just a typo?

Re: Pascal Strings

2008-04-11 08:16 • by Someone You Know
Oh My Lack Of God...

Re: Pascal Strings

2008-04-11 08:17 • by Someone You Know
189214 in reply to 189211
SlyEcho:
Or is it just a typo?


Yes, it is; look at the other cases. It's probably meant to be 16 << 0, though why anyone would type such a thing is beyond me.

Re: Pascal Strings

2008-04-11 08:17 • by wtf (unregistered)
WTF?

Re: Pascal Strings

2008-04-11 08:19 • by Ben Blok (unregistered)
189216 in reply to 189215
wtf:
WTF?

QFT

Re: Pascal Strings

2008-04-11 08:19 • by J. Walter Weatherman (unregistered)
That's brilliant as I drop a massive shit.

Re: Pascal Strings

2008-04-11 08:32 • by Christian Vogel (unregistered)
189218 in reply to 189209
Vollhorst:
public static final char[] FILENOTFOUND = {'F','i','l','e',' ','n','o','t',' ','f','o','u','n','d'};


No, that would be {14,'F','i','l','e',' ','n','o','t',' ','f','o','u','n','d'}.

Re: Pascal Strings

2008-04-11 08:33 • by {'M','y',' ','N','a','m','e'} (unregistered)
So how often do they convert the MIN_INT_VALUE string to a number in a typical application, so they could compare other numbers to it?

Re: Pascal Strings

2008-04-11 08:35 • by Zombie_Hunter
My brain hurts! (Mmmm Braaains)

Re: Pascal Strings

2008-04-11 08:37 • by M (unregistered)
189221 in reply to 189211
SlyEcho:
How does it even compile, can you switch on booleans and ints at the same time? It would work in C but in Java? Or is it just a typo?
You're right, the implicit boolean to integer conversion does not work in Java. And that "pstring[]PSTRING_SIZE_OFFSET]" part is also great.

Re: Pascal Strings

2008-04-11 08:43 • by Zied (unregistered)
WTF ?

Re: Pascal Strings

2008-04-11 08:48 • by anonymous (unregistered)
Why are chars [a-z] in in the char array intDigits? Is this being used for Base36?

The rest of the WTFs just look like someone having no idea how to code... at least in Java (or probably any newer-generation languages). This has the earmarks of an old-school mainframe coder.

Re: Pascal Strings

2008-04-11 08:51 • by M.L. (unregistered)
It would be nice to know the context of this code.

It may be a part of some kind simulation of abstract machine or processor where those constructs make much more sense.

Re: Pascal Strings

2008-04-11 08:55 • by Proko (unregistered)
It hurts, it physically hurts.
Why, why would anyone do THAT???

Re: Pascal Strings

2008-04-11 08:58 • by Martin (unregistered)
189227 in reply to 189225
M.L.:
It would be nice to know the context of this code.

It may be a part of some kind simulation of abstract machine or processor where those constructs make much more sense.


Simulation of Brillant Paula's brain? Now it makes sense!

Re: Pascal Strings

2008-04-11 09:05 • by SlyEcho (unregistered)
Well if it had been written in C#, it would look much simpler because instead of

private final static char[] intDigits =
{'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z' };

you can just write:

private const string intDigits = "0123456789abcdefghijklmnopqrstuvwxyz";

</Troll>

Re: Pascal Strings

2008-04-11 09:06 • by Ilya Ehrenburg (unregistered)
My eyes! The goggles do nothing!
Really, that hurts.

Re: Pascal Strings

2008-04-11 09:18 • by Steve (unregistered)
189233 in reply to 189224
anonymous:
The rest of the WTFs just look like someone having no idea how to code... at least in Java (or probably any newer-generation languages). This has the earmarks of an old-school mainframe coder.
Hey! I resemble that remark! (Started in the middle 1960s when punched cards were all the rage and we didn't need any newfangled text editors, green screens, or operating systems -- just put the compiler deck in the hopper, slap the source code deck on top, and press "START".)

But, yeah, seriously, WTF? I'd really like to know the context of this project. Maybe it was a class assignment of some sort.

Re: Pascal Strings

2008-04-11 09:24 • by DOA
I don't suppose anyone could tell me what the hell this is supposed to do?

Re: Pascal Strings

2008-04-11 09:35 • by abigo (unregistered)
189237 in reply to 189230
SlyEcho:
Well if it had been written in C#, it would look much simpler because instead of

private final static char[] intDigits =
{'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z' };

you can just write:

private const string intDigits = "0123456789abcdefghijklmnopqrstuvwxyz";

</Troll>

could have been
char[] thingie = "string".toCharArray();

Re: Pascal Strings

2008-04-11 09:35 • by diaphanein (unregistered)
This is purely an experiment in entropy.

Re: Pascal Strings

2008-04-11 09:49 • by y0y
I'd really like to comment something witty and intelligent, but clearly I lack the cerebral capabilities to fully appreciate and comprehend the genius at work here. Someday.. someday..

Re: Pascal Strings

2008-04-11 10:16 • by Mark (unregistered)
Even my code isn't that f*cked up.

Seriously, as somebody who left programming eight years ago for a systems analyst role, I'd forgotten this simple truth about development in many corporate environments: Incompetence is immortal.

What I mean by that is that in most other functions, when something is built/done by somebody who is truly incompetent it will usually be replaced or repaired. But when it happens in development (and bad code makes it into production) it takes on a life of its own because nobody wants to touch the code (and rightly so).

Re: Pascal Strings

2008-04-11 10:18 • by Reuben (unregistered)
189251 in reply to 189230
In java you could write:

private final static char[] intDigits = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();

Re: Pascal Strings

2008-04-11 10:31 • by Easter Bunny (unregistered)
Hmmm.

I think this is the 14th Sign of the Apocalypse.

Re: Pascal Strings

2008-04-11 10:36 • by Tom Woolf (unregistered)
I wonder how many weeks he/she got off for worker's comp after their carpal tunnel surgery...

Re: Pascal Strings

2008-04-11 10:39 • by Fraggle My Rock (unregistered)
189267 in reply to 189230
SlyEcho:
Well if it had been written in C#, it would look much simpler because instead of

private final static char[] intDigits =
{'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z' };

you can just write:

private const string intDigits = "0123456789abcdefghijklmnopqrstuvwxyz";

</Troll>


Pffft. You're being silly.

Re: Pascal Strings

2008-04-11 10:39 • by SomeCoder (unregistered)
189268 in reply to 189231
Ilya Ehrenburg:
My eyes! The goggles do nothing!
Really, that hurts.


2nd.

This is just... GAH!

The very epitome of WTF

2008-04-11 10:46 • by Konrads (unregistered)
Just brilliant. This has got to be the best WTF: Programmer gave it a thought and dedicated considerable effort just to do something utterly wrong.

Re: Pascal Strings

2008-04-11 11:17 • by ubersoldat
But why? Oh my! Why? WTF?!? Please, someone slap this person out of programming. I mean, this person and ALL of his team mates, because someone had to read THAT on a CVS/SVN changes email.

Re: Pascal Strings

2008-04-11 11:26 • by MeRp (unregistered)
189295 in reply to 189235
DOA:
I don't suppose anyone could tell me what the hell this is supposed to do?


Ok, keep in mind that I'm only going to give a brief description of what this is supposed to do, not a) what it actually does nor b) why they did it.

In Pascal strings, instead of being null terminated (like in C e.g. c-strings), instead always have the length of the string as the first element of the array. This collection of what can only (and loosely at that) be referred to as "java statements" appears to be an attempt to implement this in java, perhaps so as to somehow interact with Pascal... for some reason.

Re: Pascal Strings

2008-04-11 12:27 • by Maks Verver (unregistered)
189312 in reply to 189295
In Pascal strings, instead of being null terminated (like in C e.g. c-strings), instead always have the length of the string as the first element of the array.

The irony of course, is that in Java an array of characters is the same thing.

This collection of what can only (and loosely at that) be referred to as "java statements" appears to be an attempt to implement this in java, perhaps so as to somehow interact with Pascal...

That almost make sense. Doesn't really explain the huge look-up tables though, and why the switch isn't just implemented like this:
switch(pstring.length)

{
case 1:
case 16 << 0:
case 16 << 1:
case 16 << 2:
case 16 << 3:
case 16 << 4:
case 16 << 5:
case 16 << 6:
case 16 << 7:
case 16 << 8:
case 16 << 9:
case 16 << 10:
case 16 << 11:
case 16 << 12:
return pstring[PSTRING_SIZE_OFFSET] < pstring.length;
default:
return false;
}


Or even shorter (although a bit more complicated):
int n = pstring.length;

return (n == 1 || (n >= 16 && n <= 65536 && (n&(n-1)) == 0)) && pstring[0] < n;

I don't see the point of making PSTRING_SIZE_OFFSET a constant if your code will only ever work if it is set to zero (the empty-string case).

Re: Pascal Strings

2008-04-11 12:28 • by FluffGrrl (unregistered)
189313 in reply to 189230
Yo' C-pound ain't no array like tha Java be. Go home.

Re: Pascal Strings

2008-04-11 12:29 • by Smash (unregistered)
public static final char[] SMART_COMMENT = {'S','m','a','r','t',' ','C','o','m','m','e','n','t'};

Re: Pascal Strings

2008-04-11 12:34 • by operagost
189318 in reply to 189212
Someone You Know:
Oh My Lack Of God...

Congrats, you're the theological version of this guy.

Re: Pascal Strings

2008-04-11 12:35 • by operagost
189320 in reply to 189233
Steve:
anonymous:
The rest of the WTFs just look like someone having no idea how to code... at least in Java (or probably any newer-generation languages). This has the earmarks of an old-school mainframe coder.
Hey! I resemble that remark! (Started in the middle 1960s when punched cards were all the rage and we didn't need any newfangled text editors, green screens, or operating systems -- just put the compiler deck in the hopper, slap the source code deck on top, and press "START".)

So they not only looked like washing machines, but worked like them?

Re: Pascal Strings

2008-04-11 12:44 • by Smash (unregistered)
On regard to the DigitTens and DigitOnes arrays, the bloke obviously wanted to do something like this (I'll do it in C because it's been a while since I last touched any java):
//current value of n = 73

int n1 = DigitOnes[n]; // n1 = 3
int n10 = DigitTens[n];// n10 = 7
I wonder what will happen when the need to check for hundreds or even thousands arise. It probably will result in tendinitis

Re: Pascal Strings

2008-04-11 12:48 • by real_aardvark
189329 in reply to 189249
Mark:
Even my code isn't that f*cked up.

Seriously, as somebody who left programming eight years ago for a systems analyst role, I'd forgotten this simple truth about development in many corporate environments: Incompetence is immortal.

What I mean by that is that in most other functions, when something is built/done by somebody who is truly incompetent it will usually be replaced or repaired. But when it happens in development (and bad code makes it into production) it takes on a life of its own because nobody wants to touch the code (and rightly so).

More to the point, this is a work of art. Would you re-shape the smile on the Mona Lisa? Would you paint a smiley face on Munch's "The Scream?" Would you edit the captions for Mandatory Fun Day?

If I came across this in production code, I would refuse to edit it on aesthetic grounds (well, maybe retouch it so that it compiles, but that's it). I'd rather refactor all the other code that depends on it, to make inferior stuff work.

Pascal Strings go to Eleven

2008-04-11 12:49 • by Nigel (unregistered)

I'm glad to see that MIN_INT_VALUE goes to ELEVEN!

final static char[] MIN_INT_VALUE =

{ 11, '-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8' };


Nigel: You see, most blokes will be playing at 10. You’re on 10, all the way up, all the way up...Where can you go from there? Nowhere. What we do, is if we need that extra push over the cliff...Eleven. One louder.

DiBergi: Why don’t you just make 10 louder and make 10 be the top number, and make that a little louder?

Nigel: These go to 11


If I had to maintain this code I would definitely be looking for a cliff...

We don't need no stinking purpose...

2008-04-11 12:53 • by iddJoe (unregistered)
189333 in reply to 189235

I don't suppose anyone could tell me what the hell this is supposed to do?


Who cares? It's Pretty :)

Re: Pascal Strings

2008-04-11 12:55 • by Someone You Know
189334 in reply to 189318
operagost:

<bait tempting="false">
Congrats, you're the theological version of this guy.
</bait>


Fixed that for you. ;)

Re: Pascal Strings

2008-04-11 13:02 • by Anthony (unregistered)
I like how each function is bracketed with }; because that's the face I make when I'm reading this WTF.

Re: Pascal Strings

2008-04-11 13:09 • by jimlangrunner
Oh.

My.

I tried gouging out mine eyes, and it didn't work. They still burn.

Wait. No. Mace. Mace'll do that to you.

Heed well, young Jedi: not even Mace can take away the pain of bad code.

Re: Pascal Strings go to Eleven

2008-04-11 13:14 • by DiBergi (unregistered)
189344 in reply to 189331
Actually, the MIN_INT_VALUE doesn't go up to anything. They're using the 11 to tell you how many characters in the string '-2147483648', which is the minimum signed number in a 4 byte representation. That is why the other solutions about just initializing to a string won't work as this appears to have a requirement that the first 'char' actually be a number indicating how many more characters are in the string.

That being said, my amp goes to 12...

Re: Pascal Strings

2008-04-11 13:38 • by Gumby (unregistered)
I hate it when I have to write code like that. I wish someone would invent a computer that could do arithmetic.

Re: Pascal Strings

2008-04-11 13:50 • by 0xbaadf00d (unregistered)
What kills me is that DigitTens and DigitOnes are only useful if indexed mod 100.

If the table is only useful if indexed mod 100, can I assume the author's knowledge of mod 100?

If the author knows how to mod 100, can I assume the author's knowledge of div 100?

If the author knows how to mod and div, then why, oh, why the arrays of digits?

Re: Pascal Strings

2008-04-11 14:42 • by foo (unregistered)
189366 in reply to 189320
operagost:
Steve:
anonymous:
The rest of the WTFs just look like someone having no idea how to code... at least in Java (or probably any newer-generation languages). This has the earmarks of an old-school mainframe coder.
Hey! I resemble that remark! (Started in the middle 1960s when punched cards were all the rage and we didn't need any newfangled text editors, green screens, or operating systems -- just put the compiler deck in the hopper, slap the source code deck on top, and press "START".)

So they not only looked like washing machines, but worked like them?


Not only that, but when your code didn't work you could literally shuffle it around until it did.

In FORTRAN we always used the same variable names. That way, when you needed to add a line of code, you might already have it in one of your other programs so you could just dig through your old decks and find it. Saved waiting for a free 029.

We could put a lot of FORTRAN WTFs up here, but it would be shooting fish in a barrel.
« PrevPage 1 | Page 2Next »

Add Comment