• (unregistered)

WTF?  Mid(Cstr(...1,1))?

Like Left(...,1) Wouldn't do?

• (cs)

I found this in some production code:

int iChkShut; // variables MUST be initialized, not sure why
Funny enough, the parameter iChkShut is used (uninitialized) for comparisment a couple of rows later.

The fact that that exists in prodiction code is absolutely frightening..

• (unregistered) in reply to Mike R

Hey Mike, you obviously haven't seen real production code then, have you?

• (cs)

... and speaking of testing things Simon White ... what do you get if something is not true but not false? Simon White shows us ...

<font color="#009900">//ED: allocatedLimitOnly declared as a boolean above ...</font>
<font color="#000099">if</font> (allocatedLimitOnly) { processAbridgedCalculations();} <font color="#000099">else if</font> (!allocatedLimitOnly) { processFullCalculations();} <font color="#000099">else</font> {  resetAllocationStatus();}

Maybe he's checking for the elusive "true2" we saw earlier?
• (unregistered)

Am I missing something about the haskell code snippet? Looks easy enough to me..

:

WTF?  Mid(Cstr(...1,1))?

Like Left(...,1) Wouldn't do?

By using Mid, the code can be used with number systems that may exist in the future that put the negative sign in the middle.  He's just thinking ahead is all.

• (unregistered)

Next we hear from Andrew, who found a very interesting way of displaying "0" on a web page ...

  <%# DataBinder.Eval(Container.DataItem, "0") %>  ... and on the codebehind ...  DataTable objTable = new DataTable();  objTable.Columns.Add("0", typeof(string) );

Unless I'm mistaken, that will only name a column "0" and display it; it shouldn't actually display 0's... unless they're inserted into the rows later.
• (cs)

Hey now. Quicksort is quite clean in C.

qsort(my_array, num_elements, sizeof(ELEMENT_TYPE), cmp_func);
I don't see how that's hard to read at all!
• (unregistered) in reply to SurfaceTension

Well, in SQL, you have tri-state logic (true, false, unknown), but, as I understand it, unknown eventually evaluates to false for the sake of simplicity.

e.g.

!(3 = null)

evaluates to:

!(3 = unknown) //since null functionally means unknown

= !(unknown) //since it is impossible to know if 3 = unknown

= (unknown) //since not unknown is again unknown

= false

:
Am I missing something about the haskell code snippet? Looks easy enough to me..

Looks to me like someone puked on the screen.  I know there's a simple algorithm in there some where, but I can't find it amongst all the keyboard mashings.
• (unregistered)

Just because you do not understand the syntax of a particular programming language does not make it hard to understand, much less a WTF.

To me, if you squint your eyes just right and tilt your head a bit, the piece of haskell looks like a description of the quicksort algorithm in my old university course on algorithms. For someone who has only had a chance to work with procedural languages, the real WTF might be that it is possible to solve a problem by describing the solution, not the steps needed to reach the solution...

:
Just because you do not understand the syntax of a particular programming language does not make it hard to understand, much less a WTF.

The point is that they made such a big deal out of how clear Haskell code was and that anyone could read and understand it without knowing the language or the quicksort algorithm.  I'm familiar with quicksort and I know quite a few languages, but there is nothing inherently obvious about that snippet.  On the other hand, for anyone knowledgable about procedural languages before encountering the snippet, the introductory text is still misleading as such as person would already know enough about procedural language syntax and, presumably, quicksort.

The WTF is that they claim that you don't need to understand either understand either Haskel or Quicksort to understand the code.

I do know Quick sort, but I can't even figure out what they are doing there.

• (unregistered)

Looks to me like someone puked on the screen.  I know there's a simple algorithm in there some where, but I can't find it amongst all the keyboard mashing.

Your standards are obviously way too high.  Take a look at APL.

Anonymous Coward:

WTF?  Mid(Cstr(...1,1))?

Like Left(...,1) Wouldn't do?

Yes, using LEFT() would be a MUCH better way to determine if a number is negative ... well done!

• (cs) in reply to Jeff S

I don't know if the string indexes are 0-based or 1-based, but if they are 0-based, one possible explanation is they are parsing a string which could be  "$1.00" or "$-1.00", and are using MID to skip the first character.

• (cs)

"int iChkShut; // variables MUST be initialized, not sure why" , not sure how I got a job

I think this was the original comment.

:
The WTF is that they claim that you don't need to understand either understand either Haskel or Quicksort to understand the code.

I do know Quick sort, but I can't even figure out what they are doing there.

Have you ever seen a class in set theory?
Is the difference between [y | y <- xs, y >= x] and { y | y \in xs and y \geq x } so high?

It makes a little more sense when you realize elts_lt_x means "elements less than x" and elts_greq_x  means "elements greater than or equal to x", but it's still entirely worthy of a WTF on the grounds that the tutorial presents it matter-of-factly as "EVEN A MORON COULD UNDERSTAND THIS,"  when in fact you'd have to possess at least a passing familiarity with functional programming to begin to grasp what it does.

:
Well, in SQL, you have tri-state logic (true, false, unknown), but, as I understand it, unknown eventually evaluates to false for the sake of simplicity.

e.g.

!(3 = null)

evaluates to:

!(3 = unknown) //since null functionally means unknown

= !(unknown) //since it is impossible to know if 3 = unknown

= (unknown) //since not unknown is again unknown

= false

In this case, the variable is a boolean so nulls are not an issue.

In SQL, it expressions with NULL not explicitly handled NEVER evaluate to either TRUE or FALSE, but I can see how it might appear to, depending on how you write your logic.

Remember, in T-SQL, an IF works like this:

IF <Condition> <TruePart> ELSE <AnyThingOtherThanTrue>

not as

IF (Condition) THEN <TruePart> ELSE <FalsePart>

same with a CASE.   Remember ELSE literally means "else", not "if condition = false".

And a WHERE clause works by returning only rows in which the condition is TRUE; it does NOT suppress rows in which the condition evaluates to FALSE.   Very, very important difference!

• (unregistered)

Jeff S. wrote:
Yes, using LEFT() would be a MUCH better way to determine if a number is negative ... well done!

I can't tell if you are being sarcastic here, but any idiot knows using string functions on numbers is dumb!  You have to use bitwise assembly code operations for maximum efficiency.  Too bad VB doesn't let you call assembly code... WTF!

• (unregistered)

I've never seen haskell before, let alone coded in it, but it seemed immediately obvious to me what that code was doing. I agree with the point someone else disagreed with - you WOULD have to be a moron to not understand that (assuming you were already a programmer - I would not call a non-programmer a moron for not getting this). If you earn your living as a programmer and can't immediately recognise that as describing sets, then you are a code monkey who has probably never learnt more than one language. No offense meant, you can always learn more in the future.

• (unregistered)

The Haskell bit is a bit misleading in my opinion: The detailed explanation does indeed follow on the web page - directly after the code. They just decided to put the code first so you know what the explanation talks about...

• (unregistered)
qsort []     = []qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x   where     elts_lt_x   = [y | y <- xs, y < x]     elts_greq_x = [y | y <- xs, y >= x]

I don't know haskell, but I think I can figure this out.  If I'm wrong, would somebody please say so?

	qsort []     = []
This means "when function qsort is invoked with an empty set, return the empty set."  This will be important in the next part.

	qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
qsort is a function that takes a list (or array if you prefer) as input.  The first element of that list will be called x, and the remainder of the list is called xs.  qsort returns a sorted list (that's why it's called qsort) by building a list with three parts.  These parts are 1) a sorted list, of elements less than x, 2) x, and 3) another sorted list, of elements greater than x.  The ++ must be a way to build lists.  [x] is a list with just one element in it.

Let's stop for a moment to consider what happens if the list passed to qsort is small.  If it is 0 elements, haskell will use the first version of qsort (from earlier) and return an empty list.  If it is only 1 element, then it will become x, and xs will become empty.  There are obviously no elements greater than or less than x, so qsort will return empty lists for those.  Two empty lists plus x is the same as x by itself.  So, qsort(x) returns (x).

   where     elts_lt_x   = [y | y <- xs, y < x]     elts_greq_x = [y | y <- xs, y >= x]
These are two variables used inside qsort.  They are also lists (does haskell have anything but lists?)  These variables are recursively passed to qsort (either this same qsort if the list has one or more elements, otherwise the empty list version is used.)

The meaning of:
	[y | y <- xs, y < x]
is "y is an element of this list if it is an element of xs and if it is less than x"

Not a bad day's work for just four variables.

Great explanation of that bit of haskell.  I have read that bit of the faq and didn't get even that much out of it.  I might be able to add a little bit, after having read about erlang yesterday.

the values assigned to elts_lt_x and elts_greq_x each are surrounded by square brackets, so I'm thinking that square brackets generally mean you are building a list.  It reads really like math which is funny: "where elts_lt_x is a list of y, such that y is an element of xs and y < x"

The other thing I wanted to mention is that this function looks almost certainly tail recursive, which would be intentional.

:
 Next we hear from Andrew, who found a very interesting way of displaying "0" on a web page ...  <%# DataBinder.Eval(Container.DataItem, "0") %> ... and on the codebehind ... DataTable objTable = new DataTable(); objTable.Columns.Add("0", typeof(string) );

Unless I'm mistaken, that will only name a column "0" and display it; it shouldn't actually display 0's... unless they're inserted into the rows later.

Yes, no zeros.

It doesn't display 0, the creator needed one column, but felt that giving it a name was not important.

I guess he was right: They support the code they wrote but are not able to actualy debug or fix any of the many bugs in it.[+o(]

"objTable" is also very descriptive.

I do evil things too, but at least I'd call the table: crufyThingNames and the column DisplayName.

• (unregistered)

> Does Haskell have anything but lists?

Yes. But lists are so useful...

I strongly disagree with the people who said you need to know functional programming to understand this quicksort.
You need to know mathematical notation, but not functional programming.
In fact, if you're a mathematician, you probably don't even need to know programming at all to understand it.

• (cs)

As allready explained, that haskell WTF is totally taken out of context

• it's being explained immediately after the code what the code does. I don't know haskell, but i now see that functional languages are extreamly elegant.
• (unregistered)

I'll admit to having a passing experience with Haskell, so the fact that the code reads easily for me shouldn't shock anyone.

But the beauty of Haskell (which certainly goes for pure, functional Common Lisp, Erlang and ML too) is that a bit of mathematical notation is all you need. If you ever took a class in discrete mathematics, the snippet should seem obvious to you. It's all set theory, algebra and graph teory.

Anyway, I'm not gonna get religious on your asses, but give it a shot before dismissing it. It's a beautiful way to solve problems.

• (unregistered)

The identifier names in the Haskell example are horrible; I'll give you that. My brain wanted to read lt as an operator.

qsort []     = []
qsort (pivot:rest) = qsort low ++ [pivot] ++ high
where
low  = [e | e <- rest, e < pivot]
high = [e | e <- rest, e >= pivot]


I've been thinking "ok, haskell is this weird language, but I don't need it." I've also been watching the perl6/parrot development that's been going on for the past few years.

I changed my mind after seeing Autrijus Tang implement a Perl interpreter from scratch in a few weeks. Damnit, I'm going to learn that language, even if it does have those scary monad things.

Your forum escapes <> but your preview doesn't. Now that's a WTF.

• (unregistered)

For some strange reason my company thinks this is a good idea.

if (Value == TRUE)

-or-

if (Value == FALSE)

This works ok if "Value" only has two values of TRUE and FALSE.  But if Value is an int, then

if (Value == TRUE)
{ stuff }
else if (Value == FALSE)
{ stuff }
else
{ stuff }

is a perfectly valid, functional, but stupid construct.

:
I've never seen haskell before, let alone coded in it, but it seemed immediately obvious to me what that code was doing. I agree with the point someone else disagreed with - you WOULD have to be a moron to not understand that (assuming you were already a programmer - I would not call a non-programmer a moron for not getting this). If you earn your living as a programmer and can't immediately recognise that as describing sets, then you are a code monkey who has probably never learnt more than one language. No offense meant, you can always learn more in the future.

You, Mr. Anonymous, are exactly the type of person that make me absolutely sick when I read these forums, just like I wrote a few topics away.

Yes, I'm a programmer and no, I don't know Haskell, and that sytnax looks completely like Chinese to me. I am glad though that you find yourself such superior a programmer that you call others a moron for not getting it.

Please STFU in future calling people a moron if they think a language construction / syntax is confusing, we are not all as elite as you.

• (unregistered)

"int iChkShut; // variables MUST be initialized, not sure why"I think the word he was looking for was "declared", not "initialized".

Somehow I still think the following snippet of ruby is more readable despite being as short as the haskell version.

def qsort(list)
return [] if list.size == 0
x, xs = *list
less, more = xs.partition{|y| y < x}
qsort(less) + [x] + qsort(more)
end

It is possible to golf this even shorter, but this is probably the most readable version.

• (unregistered) in reply to QuinnFazigu

Actually the Haskell WTF in this post is a load of BS. The poster grabbed the Haskell code snippet out of context, and didn't include the next couple of paras which explain the syntax of the Haskell used and the variable names. The point the Haskell site is making is that given the following quick explanation of the language syntax, you can understand the function of the Quicksort snippet, because the language expresses the result you're trying to achieve, not the steps in how to achieve it:

qsort []     = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x   = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]


The first line reads: "The result of sorting an empty list (written []) is an empty list". The second line reads: "To sort a list whose first element is x and the rest of which is called xs, just sort all the elements of xs which are less than x (call them elts_lt_x), sort all the elements of xs which are greater than or equal to x (call them elts_greq_x), and concatenate (++) the results, with x sandwiched in the middle."

The definition of elts_lt_x, which is given immediately below, is read like this: "elts_lt_x is the list of all y's such that y is drawn from the list xs, and y is less than x". The definition of elts_greq_x is similar. The syntax is deliberately reminiscent of standard mathematical set notation, pronouncing "|" as "such that" and " <-" as "drawn from".

After you understand the syntax, the Haskell code makes a lot more sense than the equivalent C code for Quicksort. You can understand C syntax perfectly, and yet not have a clue what the code is doing (unless you've seen Quicksort before and recognise the pattern):

qsort( a, lo, hi ) int a[], hi, lo;
{
int h, l, p, t;
if (lo < hi) {
l = lo;
h = hi;
p = a[hi];
do {
while ((l &lt; h) &amp;&amp; (a[l] &lt;= p))
l = l+1;
while ((h &gt; l) &amp;&amp; (a[h] &gt;= p))
h = h-1;
if (l &lt; h) {
t = a[l];
a[l] = a[h];
a[h] = t;
}
} while (l &lt; h);

t = a[l];
a[l] = a[hi];
a[hi] = t;

qsort( a, lo, l-1 );
qsort( a, l+1, hi );

}
}


There are enough WTFs around without having to trump one up by quoting out of context. It illustrates how anyone can have a WTF if they don't RTFT.

By the way, I'd heard of Haskell before reading this post but had never seen the language or its web site before reading this WTF. Having clicked the link in the WTF and taken 2 minutes to read it, I could understand the code perfectly. If you can't do that then WTF are you doing programming and/or reading this site??!!!

• (unregistered) in reply to Razzie
Razzie:

Yes, I'm a programmer and no, I don't know Haskell, and that sytnax looks completely like Chinese to me. I am glad though that you find yourself such superior a programmer that you call others a moron for not getting it.

Please STFU in future calling people a moron if they think a language construction / syntax is confusing, we are not all as elite as you.

You GOTTA be kidding, right??!!! The whole RAISON D'ETRE (that's the French language by the way - go look it up) of this site is so that one group of people can take the piss out of code written by some other people with the implication that the first group is superior to the second. IOW, this site is all about elitism. You just don't like it because you think you're in the elite category, but now one of your site peers is suggesting you might be in the other. You just discovered the first risk of being a member of an elitist organisation: they might come to doubt your eligibility for membership.

So if you think you're on top of the pile and can take the piss out of everyone below you because you're the smartest of all, it's time for a wakeup call. OTOH, if you don't think this, then you're a hypocrit who thinks it's OK to make fun of others because YOU think they're moronic, but can't take it when people take the piss out of you. Which is it? I suspect the latter, so...

People who live in glass houses shouldn't throw stones, pal.

• (unregistered)
<font color="#009900"></font>
[code language="c#"]//ED: allocatedLimitOnly declared as a boolean above ...if (allocatedLimitOnly) {   processAbridgedCalculations();} else if (!allocatedLimitOnly) {   processFullCalculations();} else {      resetAllocationStatus();}[/code]
Oh yes, we really do like these ifs. We call it
[code language="c#"]if () {} else {} otherwise {}[/code]

• (cs)

Functional languages are very different from genral purpose languages.
If you are used to looking at c,java, pascal, basic and their like, it is different than if you are used to looking at formulae all the time.

I think the WTF with that page (not Haskel itself) is the variable names

:
The identifier names in the Haskell example are horrible; I'll give you that. My brain wanted to read _lt_ as an operator.

qsort [] = []
qsort (pivot:rest) = qsort low ++ [pivot] ++ high
where ...

:
Hey Mike, you obviously haven't seen real production code then, have you?

Uhh,

Yeah... I have.... The people I work with aren't idiots :)
Anonymous Idiot:

You GOTTA be kidding, right??!!! The whole RAISON D'ETRE (that's the French language by the way - go look it up) of this site is so that one group of people can take the piss out of code written by some other people with the implication that the first group is superior to the second. IOW, this site is all about elitism. You just don't like it because you think you're in the elite category, but now one of your site peers is suggesting you might be in the other. You just discovered the first risk of being a member of an elitist organisation: they might come to doubt your eligibility for membership.

WRONG. the purpose of this site is to look at code is that so horribly written that you cannot help but laugh at it and say out loud "WTF!"  The point isn't to nitpick or to try to prove your intelligence (though lots of times the comments -- mostly from anonymous people like you -- end up that way) but to enjoy a good laugh in regards to code that you simply cannot believe someone would actually write.

Sometimes, we even have intelligent discussions regarding the code and concepts and ideas in general, except for when anonymous trolls like yourself jump in and start insulting people.

Anonymous Idiot:

People who live in glass houses shouldn't throw stones, pal.

Unless they do it anonymously so they can run and hide, aparently. [:)]

• (cs)

Wow, trolling. I really think anonymous posters shouldn't be allowed, they really lower the level of conversation.

• (cs) in reply to Jeff S
Jeff the Idiot:

Unless they do it anonymously so they can run and hide, aparently. [:)]

Who made you the forum police, anyway?

:

You GOTTA be kidding, right??!!! The whole RAISON D'ETRE (that's the French language by the way - go look it up) of this site is so that one group of people can take the piss out of code written by some other people with the implication that the first group is superior to the second. IOW, this site is all about elitism. You just don't like it because you think you're in the elite category, but now one of your site peers is suggesting you might be in the other. You just discovered the first risk of being a member of an elitist organisation: they might come to doubt your eligibility for membership.

So if you think you're on top of the pile and can take the piss out of everyone below you because you're the smartest of all, it's time for a wakeup call. OTOH, if you don't think this, then you're a hypocrit who thinks it's OK to make fun of others because YOU think they're moronic, but can't take it when people take the piss out of you. Which is it? I suspect the latter, so...

People who live in glass houses shouldn't throw stones, pal.

First of all I never said I considered myself to be on the 'elite' side if that side even exists. Apparantly, from your response, you clearly consider yourself to be on this elite side and think that it is therefor ok to call people a moron who don't know as much as you.

Like Jeff already said, this site is to make fun of WTF code. Code that makes you say 'OMG' when you look at it. And most importantly, I LAUGH at WTF code when I see it and ask how on earth it is possible to write it, I don't call the people who write it 'idiots' or 'morons'.

If I say that I think Haskell code looks like Chinese to me but you just happen to understand it, well good for you pal, does that make me a moron? No. Does that make you elite? Ha, you'd wish. Sorry to break the news to you, 'pal', but I don't freaking care if you think it is easy to read. So again, stop with that childish 'being the best' attitude. Apparantly it seems very important to you. I wonder why?

• (cs) in reply to Jeff S

Jeff, what the anonymous guy said was correct... come on, dude. This IS what the site is all about - laughing at other people because they are morons (or atleast have made some retarded code). The point of this site IS to laugh about some of the courious perversions some people have made in Information Technology. To point fingers and say "look at how bad code some people write".

Even your own comments points out how braindead someones code is - and thereby implies that you're a better coder. I just made a random search: http://www.thedailywtf.com/ShowPost.aspx?PostID=26368 .
This sure sounds like an "i am better than him" statement to me.
(but i agree totally [;)] - and that what makes this site funny)

for example, i'm not the biggest "modifiability"-freak, so some times when i read some of the "rude" comments about f.e. that a function should have another name than this or that, or it would look clearere if he used a library-function than making 3 lines of code himself, etc, i also sometime take offense - because i don't see the ultra extreame importance (atleast not in all the code-snippets labeled as "WTF"'s in here). Don't try to make it sound like everyone here is politely commenting the code and sexual orientation of the creator of the code.

(And yeah... IF a coder earns his living as a programmer, i do think that he should know the very basic mathematics that is required to understand the haskell-example. Ofcause the syntax can get in the way, but after you've chewed a bit on it, that haskell-example allmost looks like a math-function. And we like math-functions, don't we? [:)] )

(btw, just for future reference...:i don't earn my living as a programmer so i'm free to be clueless... [:D])

:
[code language="c#"]if () {} else {} otherwise {}[/code]

Could be my girlfriend...
• (cs) in reply to Zatanix

Zatanix:
Jeff, what the anonymous guy said was correct... come on, dude. This IS what the site is all about - laughing at other people because they are morons (or atleast have made some retarded code). The point of this site IS to laugh about some of the courious perversions some people have made in Information Technology. To point fingers and say "look at how bad code some people write".

I've never viewed this site as a place where I could come and laugh at other people.  Verily, I like to laugh at the mistakes other people make, but not at the people themselves.  There is a difference.  Perhaps I'm only willing to do this because I'm a newbie to profressional programming, and as such, I make plenty of my own mistakes.  Now, I know that I'm not stupid, but rather ignorant, and so I tend to give the authors of these WTFs the same benefit of the doubt.

Zatanix:

(And yeah... IF a coder earns his living as a programmer, i do think that he should know the very basic mathematics that is required to understand the haskell-example. Ofcause the syntax can get in the way, but after you've chewed a bit on it, that haskell-example allmost looks like a math-function. And we like math-functions, don't we? Smile )

You hit the nail on the head, I believe, with your comment about syntax.  When I first viewed this WTF, gave it a passing glance and saw the questionably named variables all garbled together with syntax that I'm just not used to seeing in my everyday programming work, I thought, "Ugh."  But once I looked at it for more than .02 seconds and realized the similarities between its syntax and the mathematical notation I'm used seeing in math texts, it immediately clicked and I thought, "Ahh yes, that makes perfect sense!"

So I suppose I agree with both sides of this little argument, in part.  I understand how weird it looks to a person that's not used to the syntax and how easily such a person could dismiss it as a bunch of cryptic hooey.  But I also agree that if that person took a wee bit closer look at it, then he/she'd understand what was going on.  If not, so what, you're just ignorant of some mathematical notation and could probably benefit from picking up a book on set theory at the library...and there's absolutely no shame in that at all.

• (unregistered) in reply to UncleMidriff

Haskell is great for describing algorithms... but when you have to do actual programming, it's downright painful.

• (cs) in reply to UncleMidriff

UncleMidriff:

blah blah blah...Perhaps I'm only willing to do this because I'm a newbie to <FONT color=#0000ff>profressional</FONT> programming...blah blah blah

...see what I mean?

Definition: Profressional

Noun

1.  one that is professional; especially : one that engages in a pursuit or activity professionally and while doing so is deemed acceptable and is higly approved by someone, usually someone from the mid eighties.