- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
WTF? Mid(Cstr(...1,1))?
Like Left(...,1) Wouldn't do?
Admin
The fact that that exists in prodiction code is absolutely frightening..
Admin
Hey Mike, you obviously haven't seen real production code then, have you?
Admin
Maybe he's checking for the elusive "true2" we saw earlier?
Admin
Am I missing something about the haskell code snippet? Looks easy enough to me..
Admin
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.
Admin
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.
Admin
Hey now. Quicksort is quite clean in C.
I don't see how that's hard to read at all!Admin
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
Admin
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.
Admin
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...
Admin
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.
Admin
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.
Admin
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.
Admin
Yes, using LEFT() would be a MUCH better way to determine if a number is negative ... well done!
Admin
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.
Admin
"int iChkShut; // variables MUST be initialized, not sure why" , not sure how I got a job
I think this was the original comment.
Admin
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?
Admin
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.
Admin
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!
Admin
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!
Admin
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.
Admin
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...
Admin
This means "when function qsort is invoked with an empty set, return the empty set." This will be important in the next part.
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).
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:
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.
Admin
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.
Admin
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.
Admin
> 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.
Admin
As allready explained, that haskell WTF is totally taken out of context
Admin
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.
Admin
The identifier names in the Haskell example are horrible; I'll give you that. My brain wanted to read lt as an operator.
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.
Admin
Your forum escapes <> but your preview doesn't. Now that's a WTF.
Admin
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.
Admin
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.
Admin
Admin
Somehow I still think the following snippet of ruby is more readable despite being as short as the haskell version.
It is possible to golf this even shorter, but this is probably the most readable version.
Admin
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:
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):
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??!!!
Admin
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.
Admin
Admin
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
Admin
Uhh,
Yeah... I have.... The people I work with aren't idiots :)
Admin
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.
Unless they do it anonymously so they can run and hide, aparently. [:)]
Admin
Wow, trolling. I really think anonymous posters shouldn't be allowed, they really lower the level of conversation.
Admin
Admin
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?
Admin
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])
Admin
Admin
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.
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.
Admin
Haskell is great for describing algorithms... but when you have to do actual programming, it's downright painful.
Admin
...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.
Admin
<font face="Georgia">Well, hell: I just barely remember how quicksort works (I can't tell quick, shell and shell-metzner apart without reaching for a book) and I don't know Haskell but do know C, and yet I could read that example more easily than I could read the equivalent C code, because (a) it's simpler, and (b) I spend some of my time not using Algol-derivatives, so I have a head start. Either Prolog or advanced C++ templating preprocessor code will give you the mindset you need to understand that example; the syntax is irrelevant beyond a bit of guessable context.</font>