- 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
You haven't felt pain until you've seen someone write a lambda inside a normal function inside a lambda which was being passed around as a struct.
If this man is your friend, please, shoot him. Shoot him now.
Admin
Okay, so now a dispatch table is considered a WTF. More and more it becomes obvious that the readers of TDWTF are TRWTF.
But hey, it's a common symptom of never having programmed anything real in your life.
Admin
Like, "Oh, don't be so judgemental. I suppose YOU'VE never killed anyone for kicks, huh?"
Admin
Admin
Should have used a null array
Admin
Those who do not understand function pointers will recreate them badly.
Admin
Admin
Admin
Well, I'd agree with you -- if they filled the array. For five entries, they'd be far better off with a different method. How 'bout 5 if()s :
Way more clear as to what it's doing, and a helluva lot smaller that wasting 512 (or 1024, depending on function pointer size) bytes on the sparely populated array.
Admin
Can't anyone read. TRWTF is right here:
"In fact, here's a single line of code from one of the many layers."
The formatting to make it readable screws up the WTF. There aren't 10 entries per line so you can easily find the 54th entry easily. It's all on one line. Nobody sane creates a vtable and puts all the entries on a single line.
The fact that the junior programmer encountering this doesn't understand it is secondary.
Admin
Sorry, beg to differ (from the article): "Apparently, this structure is essential for passing information to other layers. Now if I only knew how it's supposed to do that..."
The submitter had no idea what it was supposed to so, much less complain about the formatting, however I do agree with you that formatting this on one line is a WTF as well.
Admin
Reason? They don't know; they were drunk.
-South Park
Admin
My guess would be that MAX_NUM_SERVICE_IDENTIFIERS is the last member of an enum. Hopefully, every item in the enum is clearly documented somewhere.
One advantage of this over many of the proposed fixes is deterministic,consistent execution time. Important if it is running on an embedded system or a slow CPU.
This reminds of a OO chapter I read once where the author went through great pains to develop a complex double dynamic dispatch solution for a problem that could have easily and clearly been solved by a simple two dimensional array of function pointers!
Admin
A real C programmer would use memset() here.
void *memset(void *s, int c, size_t n);
/* set buff buffer to zeroes. */ memset(buff, 0, sizeof(buff));
Admin
Admin
Trimming the table to the actually required size (the highest index in use is 46) and populating it with a loop to init to NOOP, then set the five entries would have resulted in far less space required than this "solution".
Admin
Admin
Admin
Your not too bright, are you?
Admin
Huh?
The title reads "The Interface".
The text talks about layers and layers and layers.
The code sample is a (poorly implemented, unless autogenerated) dispatch table.
What's happened to the idea that title, text and code should, uhm, have something to do with each other?
Seems like TDWTF is TRWTF. Did you srew up your SQL to randomly select an item from GENERIC_TITLE, USER_STORY and CODE_SAMPLE? Alright, I'll stop now. I guess I shouldn't be too harsh; you're probably still rebuilding your database.
Admin
Man, that gets boring really fast... I'm curious what the payload-to-troll content ratio currently is. I'm pulling a magic out-of-my-ass number and say it's at least 50/50.
Admin
Admin
Hey now, lets not get out of hand here. Nobody said useful content, I just said at least 50% is non-trolling. This could mean actual useful content or someone smashing their fish on a keyboard for 10 seconds before hitting the submit button.
Admin
hndsafhflk;hds;lfkhodsioudsuhniks ujmdfpdsisd098u9dfsa-]9sadfs9yh[0fsasa bsda0 f dsfba
Admin
See! We need moar of this! ^^
Admin
Admin
That makes as much sense as the code posted in this WTF.
Admin
Perfectly acceptable as long as you comment your NULLs so you can find out where to add the new ones. http://git.libssh.org/projects/libssh.git/tree/src/packet.c
And this is way better code than wrapping everything in a huge switch/case. At least you can see the unimplemented packets.
Admin
Admin
Unfortunately, the end result of too much trolling is that everybody thinks that everybody else is trolling, always. It's like the whole forum has gone paranoid-schizophrenic. Hearing and seeing trolls when there isn't any, etc.
(In case I wasn't clear enough, I'm not sock-puppeteering)
Admin
It would be so easy, if everyone registered. This unregistered commentating is driving up the troll ratio.
For the record, I am not against trolls if they happen to be witty. One troll who has tried to be witty from time to time is hoodacticus.
If you are going to troll, be an entertaining troll. Don't be stick in mud garden vareity troll.
Admin
Hey Hoodaticus, with friends likes this...
Admin
No, Nagesh, you are not an entertaining troll. Stop wishing that you could be a "good" troll.
Admin
Admin
But he's registered, so clearly he's not part of the problem at all.
Admin
The feed clearly indicates that no handles are allowed. I insist that Nagesh be cut from thedailywtf.com completely.
Sincerely, Bert Glanstron
Admin
Admin
Admin
Admin
gurkle gulkle gurkle GACK!
Admin
QFT
Admin
I agree. The biggest problem is the lack of documentation. Otherwise, this is a straight forward dispatching construct. Constructs like these are how "your" favorite OO language map objects to methods.
TRWTF is that people still believe the Gang of Four's treatise on organizing code. Properly implemented (and that includes documentation, at least through descriptive names and notes on name semantics), customized control structures are the easiest to maintain. This is especially true in languages with strong type systems, where you can get the compiler to literally derive the glue code from the logic code. (See "Djinn", for example. It's not tied to a particular compiler, but it will derive free theorems for Haskell types (a.k.a glue code))
Admin
Admin
The comedy here is so sweet, I think I'll be skipping lunch today
Admin
Admin
trivial. It's a vtable implementation in C and these NULLs are pointers to (abstract) virtual functions. Someone must have hated C++ so much they decided to rewrite it in C.
Admin
TRWFT is that there isn't really a WTF in this article...just a function dispatch table.
Admin
It is obvious you are all TRWTF more and more everyday. obsly this is the only brillant way to implement a table of static multiconstructor abstract classes through the use of lambdas in an embedded device with no file system. othrwse, you'll only get FILE_NOT_FOUNDS
Admin
Implementing your own vtable in C is stupid since you almost always get a C++ compiler to go with your C compiler.
Admin
You win "The lamest handle in WTF." award.