The Interface

« Return to Article
  • An Old Hacker 2011-02-23 09:03
    [NULL, 'frist', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL]
  • P-Well 2011-02-23 09:05
    "There are layers upon layers upon layers here."
    - Dan Kennedy
  • A. Cow Ard, the 3rd 2011-02-23 09:08
    The bad thing about reading so early in the morning is that the funny comments have not yet arrived. :(
  • Bogolese 2011-02-23 09:09
    TRWTF is WTF *is* it?
  • BlackBart 2011-02-23 09:11
    Bogolese:
    TRWTF is WTF *is* it?


    ECU -> Engine Control Unit. Gotta have 255 test cases to make sure there's no unintended acceleration!
  • henke37 2011-02-23 09:19
    Looks like a function pointer list that is only partially filled in this case.
  • ooblek 2011-02-23 09:19
    Objects? We don't need no stinkin' Objects.
  • SG_01 2011-02-23 09:19
    TRWTF is un-'typedef'ed function pointer arrays ^^
  • IronMensan 2011-02-23 09:21
    "Apparently, this structure is essential for passing information to other layers. Now if I only knew how it's supposed to do that..."


    Problem 1: That's not a structure, though it probably should have been one.
  • TGVish 2011-02-23 09:22
    Bogolese:
    TRWTF is WTF *is* it?

    An array with function pointers. You put in an index (probably a service number), and you get a function that you can apply to a string of bytes with its length. Simple!
  • Ben 2011-02-23 09:22
    So.. you have a lookup table to call a function depending on an opcode. How is this a WTF?
  • Cyp 2011-02-23 09:22
    I think I see the pattern there. Here, fixed the 5 bugs for you.


    static void (*const SID[MAX_NUM_SERVICE_IDENTIFIERS])
    ( const u8 *data, const u16 bytes ) =
    {
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL,
    NULL, NULL,NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL
    };
  • herp derp 2011-02-23 09:30
    oh, the joys of maintaining legacy applications.

    nothing like having to troubleshoot and debug applications which are used everyday by everyone in the company to find errors which are deep within an assembly with the most recent comments dating back to 1998. even better when it is all in VB6 and recompiling one assembly means having to recompile everything else which references it, upwards of 15 other assemblies and related applications. *sigh*
  • C3PO 2011-02-23 09:31
    Obviously, Brian does not understand C. He probably thinks it's like Java™, where references new arrays are initialized to [n]null[/b] or 0 (depending on type) automatically. In C, if you initialize a structure, it is filled with random bits and bytes. This could be a sparse array or a fixed-state machine, which should in either case contain a valid base-case value.

    I would think that a "real" C programmer would just use 0 here, but maybe that is TRWTF?
  • Anon 2011-02-23 09:33
    NULL, NULL, NULL, RAT, and NULL
  • Nagesh 2011-02-23 09:34
    Inside each small problem is a bigger one waiting to get out.
  • MadX 2011-02-23 09:38
    Whoa, Nully.
  • allen-poole.com 2011-02-23 09:39
    Layers just makes me think of Shrek

    An ogre is like an onion.
    They stink?
    Yes... NO!
    Oh, they make you cry?
    No!
    Oh, you leave 'em out in the sun, they get all brown, start sproutin' little white hairs...
    NO! Layers. Onions have layers. Ogres have layers. Onions have layers. You get it? We both have layers.
  • SeySayux 2011-02-23 09:39
    An Old Hacker:
    [NULL, 'frist', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL]


    Your use of python arrays in this context amuses me slighty, as it does confirm your sterotype as a dimwit.
  • Steve The Cynic 2011-02-23 09:42
    Ok, the arrangement of entries is a little wanked, mostly because the names of the functions aren't the same length in the source code as NULL is, but there's nothing particularly wrong with this.

    The declaration is confusing because, although it is accurately declared as an array of constant pointers to functions receiving const u8 * and (const) u16 and returning void, it is unusual to see an array of function pointers declared in a single step like this. I wrote my first C program 26 years ago (and have been writing them ever since, as well as C++, Fortran, assembler, Pascal, VB, Python, OPL, and a few other oddments), and it took me a moment to work out where the "const" was supposed to be binding.

    Other than that, and a lack of hint comments showing what the programmer thinks the indexes are, it's not so bad.
  • Migala 2011-02-23 09:43
    MadX:
    Whoa, Nully.


    +1. Was just listening to her (not that album, but still).
  • anonymouse 2011-02-23 09:49
    allen-poole.com:
    Layers just makes me think of Shrek

    An ogre is like an onion.
    They stink?
    Yes... NO!
    ...snip...


    Oh darn, someone beat me to the Shrek reference. This was the first thing that came to mind when I saw today's wtf.
  • Anon 2011-02-23 09:49
    Do you have something without so much NULL in it?
  • Belgarion 2011-02-23 09:49
    It looks like vanulla array initialization to me.
  • SnatchThePebblesFromMyHand 2011-02-23 09:53
    "Assemblies" in 1998? You're not fooling me, young grasshopper.
  • dugginator 2011-02-23 09:55
    Belgarion:
    It looks like vanulla array initialization to me.

    Really? I must not be squinting the right way, 'cause all I can see is a teapot.
  • frits 2011-02-23 09:58
    Who hasn't done something like this?
  • Patrick 2011-02-23 09:59
    Well if you want a python array it would be None, not NULL.

    Unless you did something like:

    NULL = None
    [NULL, 'not_frist', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL]
  • Hat Trick 2011-02-23 10:03
    anonymouse:
    allen-poole.com:
    Layers just makes me think of Shrek

    An ogre is like an onion.
    They stink?
    Yes... NO!
    ...snip...


    Oh darn, someone beat me to the Shrek reference. This was the first thing that came to mind when I saw today's wtf.

    While most normal people just thought of Inception.
  • whatamess 2011-02-23 10:03
    Seriously, anyone who thinks there isn't something inherently wrong with this code should change profession... you are hurting the industry!
  • boog 2011-02-23 10:03
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.
  • Nagesh 2011-02-23 10:04
    frits:
    Who hasn't done something like this?


    Not me, for sure.
  • Nagesh 2011-02-23 10:05
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?
  • frits 2011-02-23 10:07
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.

    I'm pretty sure you'd go to jail for animal cruelty. Ever heard of Michael Vick?

    Your not too bright, are you?
  • Gaddafi 2011-02-23 10:07
    Looks a little like a Python C extension.
  • " DROP TABLE USERS; " 2011-02-23 10:08
    whatamess:
    Seriously, anyone who thinks there isn't something inherently wrong with this code should change profession... you are hurting the industry!


    It's just initializing a sparse vtable, looks like. On an embedded system (in this case, a vehicle ECU), etc. etc.
  • Shiva 2011-02-23 10:08
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.
  • Nagesh 2011-02-23 10:10
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Really? Wow. I was off for two days to celebrate the dead Presidents of America.
  • no2trolls 2011-02-23 10:11
    Anon:
    Do you have something without so much NULL in it?


    I'll have your NULL. I love it.
  • JamesQMurphy 2011-02-23 10:16
    Anon:
    Do you have something without so much NULL in it?


    Cue the Vikings, singing, "NULL null null null NULL null..."

    Bloody Vikings!
  • Steve The Cynic 2011-02-23 10:16
    whatamess:
    Seriously, anyone who thinks there isn't something inherently wrong with this code should change profession... you are hurting the industry!

    These days I wouldn't *do* it that way, but on the grand scale of things, it is far from the worst possible WTF. In fact, the rest of the system sounds more like a candidate for "significantly worse than this one line of itself", if the number of layers is truly as grotesque as indicated.

    Me, I would have included a no-action function to avoid littering the code with if( function pointer from table is not NULL ) before each call. If the live actions are truly this sparse, though, and there is just 'one' point-of-call, I'd have written a switch() to dispatch instead. The boundary between "wants a switch for clarity" and "wants a dispatch table for clarity" is very fuzzy, and depends on many hard-to-quantify things.

    With access to an OO language, the response is different, of course, although this level of sparseness suggests a high probability of weak factoring. (I know you can build an OO system in non-OO languages, but the scope for hard-to-find bugs is just amazing.)
  • imgx64 2011-02-23 10:18
    C3PO:
    Obviously, Brian does not understand C. He probably thinks it's like Java™, where references new arrays are initialized to [n]null[/b] or 0 (depending on type) automatically. In C, if you initialize a structure, it is filled with random bits and bytes. This could be a sparse array or a fixed-state machine, which should in either case contain a valid base-case value.

    I think that C is TRWTF?


    FTFY.
  • lyates 2011-02-23 10:19
    Looks like a state machine to me.
    One with only a few states...
  • Code Slave 2011-02-23 10:19
    Hat Trick:
    anonymouse:
    allen-poole.com:
    Layers just makes me think of Shrek

    An ogre is like an onion.
    They stink?
    Yes... NO!
    ...snip...


    Oh darn, someone beat me to the Shrek reference. This was the first thing that came to mind when I saw today's wtf.

    While most normal people just thought of Inception.


    %s/normal/childless/g

    I can assure you - most parents with a child born after 1990 thought Shrek.
  • Nagesh 2011-02-23 10:20
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.


  • #TDWTFMafia #SOMafia 2011-02-23 10:22
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!
  • Aaron Rogers 2011-02-23 10:24
    JamesQMurphy:
    Anon:
    Do you have something without so much NULL in it?


    Cue the Vikings, singing, "NULL null null null NULL null..."

    Bloody Vikings!

    I couldn't care less about the Vikings. They can't even make the playoffs.
  • Pr0gramm3r 2011-02-23 10:27
    #define NULL 1337

    Then watch the shit storm fly.
  • frits 2011-02-23 10:36
    Pr0gramm3r:
    #define NULL 1337

    Then watch the shit storm fly.

    Who hasn't done something like this?
  • boog 2011-02-23 10:36
    It looks like more work from this guy. But today's code appears to be a step up from the other method. That is, at least he's not using a case statement.

    That we can see.
  • Power Troll 2011-02-23 10:39
    boog (imposting poster):
    It looks like more work from this guy. But today's code appears to be a step up from the other method. That is, at least he's not using a case statement.

    That we can see.

    Duh, it's the same guy. That's why their both named Brian.
  • boog 2011-02-23 10:40
    boog (defective copy):
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.
    You should tuck in your lack of creativity, my empty-headed emulator, before others see it.
  • Olivier 2011-02-23 10:41
    I think my brain just turned itself inside out. Can anyone else see a possible justification for this? The only valid use I know of for arrays of func ptrs is a (fixed sized) list of callbacks.
  • by 2011-02-23 10:41
    Everytime someone writes terrible code like this, a little kitty dies...

    The code says it perfectly -> };

    I would cry too.
  • Grown Man with a Van 2011-02-23 10:41
    Hey, how come they don't do featured comments anymore?
  • Bobbo 2011-02-23 10:42
    Migala:
    MadX:
    Whoa, Nully.


    +1. Was just listening to her (not that album, but still).


    +2! Make that a Featured Comment please..
  • by 2011-02-23 10:42
    Grown Man with a Van:
    Hey, how come they don't do featured comments anymore?


    Because nobody writes anything funny anymore. That, or it's a big conspiracy.
  • by by's sock puppet 2011-02-23 10:43
    by:
    Everytime someone writes terrible code like this, a little kitty dies...

    The code says it perfectly -> };

    I would cry too.

    In that case, it would be an excellent app for the Animal Control Organizations of America.

    Also a wonderful way to control a "catsplosion" in Dwarf Fortress
  • Nagesh 2011-02-23 10:46
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!


    Why???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    Please do not reply with "WHY NOT".

  • boog 2011-02-23 10:46
    Grown Man with a Van:
    Hey, how come they don't do featured comments anymore?
    So you're suggesting there have been comments worth featuring?

    Interesting...
  • by 2011-02-23 10:48
    Nagesh:
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!


    Why???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    Please do not reply with "WHY NOT".



    What the hell are you guys talking about? TDWTF used to be funny, turned trolling, turned to whatever the hell this is...

    I can't really complain though because I'm still here reading and commenting.
  • Dr. Pepper 2011-02-23 10:49
    Olivier:
    I think my brain just turned itself inside out. Can anyone else see a possible justification for this? The only valid use I know of for arrays of func ptrs is a (fixed sized) list of callbacks.

    I was just thinking about implementing something like this for a genetic programming project I'm doing. I'm thinking of putting binary operators/functions in a sparse matrix with the dimensions of the inputs vector. Instead of doing normal matrix x vector multiplication, I will chain the operations, using the result as an input to the next function. The result will be a vector which can be submitted to a fitting function. Of course my array will be dynamic and nulled by a loop, but I think that I could create an arbitrary means of creating genetic solutions in this fashion
  • backForMore 2011-02-23 10:50
    Now I understand Toyota's sudden acceleration problem.
  • by 2011-02-23 10:53
    by:
    Nagesh:
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!


    Why???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    Please do not reply with "WHY NOT".



    What the hell are you guys talking about? TDWTF used to be funny, turned trolling, turned to whatever the hell this is...

    I can't really complain though because I'm still here reading and commenting.

    Especially, considering you're a troll yourself, having hijacked my handle from a featured comment from months ago.

    No, Askimet, a link back to the host site is not spam.
  • HellKarnassus 2011-02-23 10:57
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.

    I would have strangled it when I saw the first {
  • NOT the original, ORIGINAL by 2011-02-23 11:05
    by:
    by:
    Nagesh:
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!


    Why???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    Please do not reply with "WHY NOT".



    What the hell are you guys talking about? TDWTF used to be funny, turned trolling, turned to whatever the hell this is...

    I can't really complain though because I'm still here reading and commenting.

    Especially, considering you're a troll yourself, having hijacked my handle from a featured comment from months ago.

    No, Askimet, a link back to the host site is not spam.


    LOL, really? That's funny... No, sorry, you're not clever enough to emulate, though I'm sure you keep that featured comment badge close to your heart. I honestly just didn't realize.

  • Jake 2011-02-23 11:08
    Obviously the new programmer just isn't as clever as the old programmer.

    Whether clever programmers should be allowed to live... well that's a whole separate discussion.
  • Silfax 2011-02-23 11:11
    allen-poole.com:
    Layers just makes me think of Shrek

    An ogre is like an onion.
    They stink?
    Yes... NO!
    Oh, they make you cry?
    No!
    Oh, you leave 'em out in the sun, they get all brown, start sproutin' little white hairs...
    NO! Layers. Onions have layers. Ogres have layers. Onions have layers. You get it? We both have layers.


    Well it is an ogre of a problem.
  • History Major 2011-02-23 11:11
    I think it all started back in August which, ironically, featured a troll. If we were to play hangman, I would hope you could fill in the blanks:

    _ _ r t
    _ _ _ _ _ t r _ _

    (by the way, if you can't figure out who I'm referring to, you should go away and grow up ;)

    [to be continued, based on Askimet censorship]
  • History Major 2011-02-23 11:12
    History Major:
    I think it all started back in August which, ironically, featured a troll. If we were to play hangman, I would hope you could fill in the blanks:

    _ _ r t
    _ _ _ _ _ t r _ _

    (by the way, if you can't figure out who I'm referring to, you should go away and grow up ;)

    [to be continued, based on Askimet censorship]


    Day after day, BG (as we'll call him), would comment using the same exact form as stated in the original article, not doubt getting the same amount of glee and fulfillment as the guy originally mentioned in the story. After a while, the moderators with no explanation started deleting posts. One would rationally conclude they decided "enough is enough."

    As normally is the case, this did not stop the problem. The enraged troll kept it up, and the volume of posts, along with misspelled versions indicated that other trolls were joining his cause against "oppression" and "censorship". Posts kept vanishing, and the troll found more and more clever ways to fly below the moderators' radar. Soon posts with a simple reference to "wooden tables" or "embedded systems" would vanish, driving more trolls to his cause.

    The mods haven't studied history. The best way to eliminate trolls is to ignore them, plain and simple. Just like violence in Afghanistan, you're just going to recruit more soldiers by deleting posts. Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    While I enjoyed the ride, I do not like how those with intelligence now use it for evil instead of valid comments. Be wise, gentlemen.
  • Behold 2011-02-23 11:13
    Interestingly, this is pretty much how you write Python modules in C (that is, bindings to C code for Python). Except I think the array is even larger there.
  • Matt Westwood 2011-02-23 11:15
    History Major:
    History Major:
    I think it all started back in August which, ironically, featured a troll. If we were to play hangman, I would hope you could fill in the blanks:

    _ _ r t
    _ _ _ _ _ t r _ _

    (by the way, if you can't figure out who I'm referring to, you should go away and grow up ;)

    [to be continued, based on Askimet censorship]


    Day after day, BG (as we'll call him), would comment using the same exact form as stated in the original article, not doubt getting the same amount of glee and fulfillment as the guy originally mentioned in the story. After a while, the moderators with no explanation started deleting posts. One would rationally conclude they decided "enough is enough."

    As normally is the case, this did not stop the problem. The enraged troll kept it up, and the volume of posts, along with misspelled versions indicated that other trolls were joining his cause against "oppression" and "censorship". Posts kept vanishing, and the troll found more and more clever ways to fly below the moderators' radar. Soon posts with a simple reference to "wooden tables" or "embedded systems" would vanish, driving more trolls to his cause.

    The mods haven't studied history. The best way to eliminate trolls is to ignore them, plain and simple. Just like violence in Afghanistan, you're just going to recruit more soldiers by deleting posts. Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    While I enjoyed the ride, I do not like how those with intelligence now use it for evil instead of valid comments. Be wise, gentlemen.


    Add another factor: the addition of Askimet, which is extremely badly broken.
  • Abso 2011-02-23 11:18
    History Major:
    Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    Perhaps that's the plan? If they were more clever, they'd be less annoying.
  • IRC is 1337 2011-02-23 11:25
    Nagesh:
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!


    Why???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    Please do not reply with "WHY NOT".



    Why ask why?
  • History Major 2011-02-23 11:26
    Abso:
    History Major:
    Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    Perhaps that's the plan? If they were more clever, they'd be less annoying.

    More clever = more difficult to detect. Apparently, you are only able to detect the less clever ones. The other side is the individual who marks a legitimate post as a "troll post". This, incidentally, can result in conversion to a troll or lack of desire to post anything.
  • frits is DEADBEEF 2011-02-23 11:28
    History Major:
    History Major:
    I think it all started back in August which, ironically, featured a troll. If we were to play hangman, I would hope you could fill in the blanks:

    _ _ r t
    _ _ _ _ _ t r _ _

    (by the way, if you can't figure out who I'm referring to, you should go away and grow up ;)

    [to be continued, based on Askimet censorship]


    Day after day, BG (as we'll call him), would comment using the same exact form as stated in the original article, not doubt getting the same amount of glee and fulfillment as the guy originally mentioned in the story. After a while, the moderators with no explanation started deleting posts. One would rationally conclude they decided "enough is enough."

    As normally is the case, this did not stop the problem. The enraged troll kept it up, and the volume of posts, along with misspelled versions indicated that other trolls were joining his cause against "oppression" and "censorship". Posts kept vanishing, and the troll found more and more clever ways to fly below the moderators' radar. Soon posts with a simple reference to "wooden tables" or "embedded systems" would vanish, driving more trolls to his cause.

    The mods haven't studied history. The best way to eliminate trolls is to ignore them, plain and simple. Just like violence in Afghanistan, you're just going to recruit more soldiers by deleting posts. Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    While I enjoyed the ride, I do not like how those with intelligence now use it for evil instead of valid comments. Be wise, gentlemen.


    The constant trolling by a few "cool" kids turn even the most well-meaning participators in trolls.
  • The Corrector 2011-02-23 11:30
    frits is DEADBEEF:

    The constant trolling by a few "cool" kids turn even the most well-meaning participators into trolls.
  • RickD 2011-02-23 11:30
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
  • frits 2011-02-23 11:33
    History Major:
    History Major:
    I think it all started back in August which, ironically, featured a troll. If we were to play hangman, I would hope you could fill in the blanks:

    _ _ r t
    _ _ _ _ _ t r _ _

    (by the way, if you can't figure out who I'm referring to, you should go away and grow up ;)

    [to be continued, based on Askimet censorship]


    Day after day, BG (as we'll call him), would comment using the same exact form as stated in the original article, not doubt getting the same amount of glee and fulfillment as the guy originally mentioned in the story. After a while, the moderators with no explanation started deleting posts. One would rationally conclude they decided "enough is enough."

    As normally is the case, this did not stop the problem. The enraged troll kept it up, and the volume of posts, along with misspelled versions indicated that other trolls were joining his cause against "oppression" and "censorship". Posts kept vanishing, and the troll found more and more clever ways to fly below the moderators' radar. Soon posts with a simple reference to "wooden tables" or "embedded systems" would vanish, driving more trolls to his cause.

    The mods haven't studied history. The best way to eliminate trolls is to ignore them, plain and simple. Just like violence in Afghanistan, you're just going to recruit more soldiers by deleting posts. Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    While I enjoyed the ride, I do not like how those with intelligence now use it for evil instead of valid comments. Be wise, gentlemen.

    Who hasn't posted an article like this?
  • History Major 2011-02-23 11:37
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.

    This system is fatally flawed because trolling is tricky to detect. To wit, I think there is an internet law about how sarcasm and trolling are indistinguishable.
  • Maurits 2011-02-23 11:40
    RickD:
    the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated...


    Unless they have backup "lurker" account.
  • serguey123 2011-02-23 11:42
    History Major:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.

    This system is fatally flawed because trolling is tricky to detect. To wit, I think there is an internet law about how sarcasm and trolling are indistinguishable.

    Wouldn't sarcasm with a deadpan delivery be considered the equivalent to trolling IRL?
  • Abso 2011-02-23 11:46
    History Major:
    Abso:
    History Major:
    Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    Perhaps that's the plan? If they were more clever, they'd be less annoying.

    More clever = more difficult to detect. Apparently, you are only able to detect the less clever ones. The other side is the individual who marks a legitimate post as a "troll post". This, incidentally, can result in conversion to a troll or lack of desire to post anything.

    History Major:

    This system is fatally flawed because trolling is tricky to detect. To wit, I think there is an internet law about how sarcasm and trolling are indistinguishable.

    It's not so much that they get harder to detect as that I enjoy sarcasm, so when the trolls edge closer to the thin sarcasm-trolling line, I find them less annoying.

    I suppose I could probably detect the more clever/less annoying trolls if I put more thought into it, but if they don't annoy me, then I don't care.
  • History Major 2011-02-23 11:50
    Abso:
    History Major:
    Abso:
    History Major:
    Just like an improperly-applied anti-biotic, you are going to make the trolls more clever if you sometimes delete posts and sometimes don't.

    Perhaps that's the plan? If they were more clever, they'd be less annoying.

    More clever = more difficult to detect. Apparently, you are only able to detect the less clever ones. The other side is the individual who marks a legitimate post as a "troll post". This, incidentally, can result in conversion to a troll or lack of desire to post anything.

    History Major:

    This system is fatally flawed because trolling is tricky to detect. To wit, I think there is an internet law about how sarcasm and trolling are indistinguishable.

    It's not so much that they get harder to detect as that I enjoy sarcasm, so when the trolls edge closer to the thin sarcasm-trolling line, I find them less annoying.

    I suppose I could probably detect the more clever/less annoying trolls if I put more thought into it, but if they don't annoy me, then I don't care.

    Until you have a valid insite, and its marked as trolling or its buried in troll responses.
  • b-redeker 2011-02-23 11:52
    Maurits:
    RickD:
    the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated...


    Unless they have backup "lurker" account.


    Who doesn't have one of these?
  • pjt33 2011-02-23 11:53
    Steve The Cynic:
    whatamess:
    Seriously, anyone who thinks there isn't something inherently wrong with this code should change profession... you are hurting the industry!

    These days I wouldn't *do* it that way, but on the grand scale of things, it is far from the worst possible WTF.

    It's not up there with the clbuttics, but it's the kind of unmaintainable code that makes a fed up maintainer think of posting to the DailyWTF. Having to count the NULLs to check that functions are in the right positions is not fun. It's fundamentally another form of magic number.
  • Skip 2011-02-23 11:53
    TRWTF here is that someone who would write this:

    "Apparently, this structure is essential for passing information to other layers. Now if I only knew how it's supposed to do that..."

    Was allowed to work on the project at all, and not sent to do some vb6 or javascript or something. Someone really should have said, "step away from the c compiler slowly, and nobody will get hurt". It shouldn't have to be said, but evidently I guess it has to be. A requirement for working on ancient c embedded systems is the ability to read c. This isn't even particularly complex c at that, it's just a normal vtable implementation. This is part of the piece of code that handles input from a hardware device. That device almost certainly is sending a packet of data where the first byte is an opcode, then two bytes indicating the length of data, then the data, and then probably a checksum. The code reading the data in from the port sanitizes it and calls the correct handler.

    This isn't difficult stuff, and the only very, very small potential WTF here is using NULL instead of a dummy function that just returns, but I can think of several reasons off of the top of my head for not doing that. The input could be sanitized elsewhere, this could be essentially a 'subclass' vtable, many other possiblities.
  • digghater 2011-02-23 11:54
    History Major:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.

    This system is fatally flawed because trolling is tricky to detect. To wit, I think there is an internet law about how sarcasm and trolling are indistinguishable.

    But please, dear god, do not put in a system like Digg, where every comment section turns into an exercise of groupthink.
  • boog 2011-02-23 12:02
    digghater:
    History Major:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.

    This system is fatally flawed because trolling is tricky to detect. To wit, I think there is an internet law about how sarcasm and trolling are indistinguishable.

    But please, dear god, do not put in a system like Digg, where every comment section turns into an exercise of groupthink.

    I would digg this comment if I could.
  • Skip 2011-02-23 12:03
    pjt33:
    Having to count the NULLs to check that functions are in the right positions is not fun. It's fundamentally another form of magic number.


    Sigh. There are 255 of them. 10 per line. Can you count to 10? What would you have them do? something like, in code, assign:

    SID[OP_START_DIAGNOSTIC] = &start_diagnostic_session;

    etc.? That's a really bad idea, because it's wasted space on a system where you're very likely counting bytes to fit all the code and data on a very small ROM, and it's simply unneeded. If this kind of thing bothers you, stay the heck away from embedded systems.
  • NOT the original, ORIGINAL by 2011-02-23 12:05
    Skip:
    pjt33:
    Having to count the NULLs to check that functions are in the right positions is not fun. It's fundamentally another form of magic number.


    Sigh. There are 255 of them. 10 per line. Can you count to 10? What would you have them do? something like, in code, assign:

    SID[OP_START_DIAGNOSTIC] = &start_diagnostic_session;

    etc.? That's a really bad idea, because it's wasted space on a system where you're very likely counting bytes to fit all the code and data on a very small ROM, and it's simply unneeded. If this kind of thing bothers you, stay the heck away from embedded systems.


    You posted twice, and have yet to tell people to stay the hell off your lawn... I'm quite disappointed, I must say.
  • El Jefe 2011-02-23 12:12
    Skip:
    pjt33:
    Having to count the NULLs to check that functions are in the right positions is not fun. It's fundamentally another form of magic number.


    Sigh. There are 255 of them. 10 per line. Can you count to 10? What would you have them do? something like, in code, assign:

    SID[OP_START_DIAGNOSTIC] = &start_diagnostic_session;

    etc.? That's a really bad idea, because it's wasted space on a system where you're very likely counting bytes to fit all the code and data on a very small ROM, and it's simply unneeded. If this kind of thing bothers you, stay the heck away from embedded systems.


    *Shudder*
    That line of code reminds me of an application I used to maintain. The codebase had several thousand lines of code like that in many different constructors. This particular application also had a C++ header file that had over 40,000 line of code. That file had the full inline implmentation code for something like 250 subclasses. Just thinking about that monstrocity makes me want a drink...

  • hoodaticus 2011-02-23 12:23
    I do this same thing in C#. After all, the simplicity of using lambda expressions is made even more simple by passing them around in giant STRUCTS. I dump every lambda I need into a struct and just pass it around everywhere.
  • Yuppie 2011-02-23 12:23
    Nagesh:
    Inside each small problem is a bigger one waiting to get out.


    Kind of like a reverse matryoshka doll from an evil parallel universe.

    Yes I did write that code in the Starbucks built on top of an ancient Native American burial ground ... why do you ask?
  • Myself 2011-02-23 12:25
    So TRWTF is... actually, nope, the WTF IS TRWTF.
  • boog 2011-02-23 12:26
    boog (copycat):
    I'm pretty sure I would digg this comment if I could.

    FTFY
  • NOT the original, ORIGINAL by 2011-02-23 12:27
    hoodaticus:
    I do this same thing in C#. After all, the simplicity of using lambda expressions is made even more simple by passing them around in giant STRUCTS. I dump every lambda I need into a struct and just pass it around everywhere.


    I died a little inside reading that.
  • The laughter of Children 2011-02-23 12:29
    NOT the original, ORIGINAL by:
    hoodaticus:
    I do this same thing in C#. After all, the simplicity of using lambda expressions is made even more simple by passing them around in giant STRUCTS. I dump every lambda I need into a struct and just pass it around everywhere.


    I died a little inside reading that.


    I died laughing!
  • NOT the original, ORIGINAL by 2011-02-23 12:35
    The laughter of Children:
    NOT the original, ORIGINAL by:
    hoodaticus:
    I do this same thing in C#. After all, the simplicity of using lambda expressions is made even more simple by passing them around in giant STRUCTS. I dump every lambda I need into a struct and just pass it around everywhere.


    I died a little inside reading that.


    I died laughing!


    You just know someone is going to read that, and think that it's 'extensible', or that it's some kind of pattern...

    Oh intertubes, you know not what power you yield over the minds of the uneducated, unwashed masses.
  • boog 2011-02-23 12:37
    Nagesh:
    Inside each small problem is a bigger one waiting to get out.
    And even when there isn't, the worst developers will try to solve it anyway.
  • Somebody Shoot Me Please 2011-02-23 12:38
    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.
  • smxlong 2011-02-23 12:39
    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.
  • Jay 2011-02-23 12:43
    frits:
    Who hasn't done something like this?


    Like, "Oh, don't be so judgemental. I suppose YOU'VE never killed anyone for kicks, huh?"
  • hoodaticus 2011-02-23 12:50
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!
    TRWTF is SO.
  • Bob the Builder 2011-02-23 12:54
    Should have used a null array
  • Troy 2011-02-23 12:54
    Those who do not understand function pointers will recreate them badly.
  • hoodaticus 2011-02-23 12:55
    Grown Man with a Van:
    Hey, how come they don't do featured comments anymore?
    Because all the comments suck ass.
  • hoodaticus 2011-02-23 12:56
    Nagesh:
    #TDWTFMafia #SOMafia:
    Nagesh:
    Shiva:
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?

    Nagesh, dude, someone hacked your account yesterday.


    Idiot,
    Nobody has hacked my account. THere's one stalkher I have acquired, who insists on using my good name.




    One? We are legion and the coolest!


    Why???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    Please do not reply with "WHY NOT".

    WHY NOT
  • JamesCurran 2011-02-23 12:57
    Skip:
    Sigh. There are 255 of them. 10 per line. Can you count to 10? What would you have them do? something like, in code, assign:

    SID[OP_START_DIAGNOSTIC] = &start_diagnostic_session;

    etc.? That's a really bad idea, because it's wasted space on a system where you're very likely counting bytes to fit all the code and data on a very small ROM, and it's simply unneeded.


    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 :

    if(op == OP_START_DIAGNOSTIC)
    start_diagnostic_session(len, dataptr);


    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.
  • jmucchiello 2011-02-23 13:01
    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.
  • NOT the original, ORIGINAL by 2011-02-23 13:05
    jmucchiello:
    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.


    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.
  • hoodaticus 2011-02-23 13:21
    Yuppie:
    Nagesh:
    Inside each small problem is a bigger one waiting to get out.


    Kind of like a reverse matryoshka doll from an evil parallel universe.

    Yes I did write that code in the Starbucks built on top of an ancient Native American burial ground ... why do you ask?
    I heard that before Starbucks built the store, they dug up all the bodies, pissed on them, then buried them again upside down.

    Reason? They don't know; they were drunk.

    -South Park
  • Englebart 2011-02-23 13:22
    JamesCurran:
    Skip:
    Sigh. There are 255 of them. 10 per line. Can you count to 10? What would you have them do? something like, in code, assign:

    SID[OP_START_DIAGNOSTIC] = &start_diagnostic_session;

    etc.? That's a really bad idea, because it's wasted space on a system where you're very likely counting bytes to fit all the code and data on a very small ROM, and it's simply unneeded.


    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 :

    if(op == OP_START_DIAGNOSTIC)
    start_diagnostic_session(len, dataptr);


    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.

    I once saw a code block of 135 ifs like you are proposing that would have worked a LOT better as a struct of key + function pointer. This article is kind of the opposite case.

    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!
  • Childish 2011-02-23 13:31
    C3PO:
    Obviously, Brian does not understand C. He probably thinks it's like Java™, where references new arrays are initialized to [n]null[/b] or 0 (depending on type) automatically. In C, if you initialize a structure, it is filled with random bits and bytes. This could be a sparse array or a fixed-state machine, which should in either case contain a valid base-case value.

    I would think that a "real" C programmer would just use 0 here, but maybe that is TRWTF?


    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));
  • hoodaticus 2011-02-23 13:35
    Englebart:
    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!
    Did the language(s) the book was written against even have function pointers?
  • Design Pattern 2011-02-23 13:36
    Englebart:

    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.

    There were not many fixes proposed, but even with this table there is a need for handling the NULL values (which could have been avoided by introducing a NOOP-function).

    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".
  • hoodaticus 2011-02-23 13:39
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
    You're all wrong. This is the best way to get rid of trolls. I promise.
  • DEADBEEF 2011-02-23 13:42
    Childish:
    C3PO:
    Obviously, Brian does not understand C. He probably thinks it's like Java™, where references new arrays are initialized to [n]null[/b] or 0 (depending on type) automatically. In C, if you initialize a structure, it is filled with random bits and bytes. This could be a sparse array or a fixed-state machine, which should in either case contain a valid base-case value.

    I would think that a "real" C programmer would just use 0 here, but maybe that is TRWTF?


    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));

    A real C programmer would have done it just like the article. Why waste time calling code, when you can use the compiler to initalize your data?
  • frits 2011-02-23 13:42
    hoodaticus:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
    You're all wrong. This is the best way to get rid of trolls. I promise.

    I'm pretty sure you'd go to prison for life in any U.S. state if you tried to implement that policy.

    Your not too bright, are you?
  • foo 2011-02-23 13:43
    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.
  • NOT the original, ORIGINAL by 2011-02-23 13:46
    frits:
    hoodaticus:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
    You're all wrong. This is the best way to get rid of trolls. I promise.

    I'm pretty sure you'd go to prison for life in any U.S. state if you tried to implement that policy.

    Your not too bright, are you?


    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.
  • foo 2011-02-23 13:49
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.
  • NOT the original, ORIGINAL by 2011-02-23 14:04
    foo:
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.


    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.
  • DOA 2011-02-23 14:10
    NOT the original, ORIGINAL by:
    foo:
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.


    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.


    hndsafhflk;hds;lfkhodsioudsuhniks ujmdfpdsisd098u9dfsa-]9sadfs9yh[0fsasa bsda0 f dsfba
  • NOT the original, ORIGINAL by 2011-02-23 14:11
    DOA:
    NOT the original, ORIGINAL by:
    foo:
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.


    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.


    hndsafhflk;hds;lfkhodsioudsuhniks ujmdfpdsisd098u9dfsa-]9sadfs9yh[0fsasa bsda0 f dsfba


    See! We need moar of this! ^^
  • pjt33 2011-02-23 14:18
    Skip:
    pjt33:
    Having to count the NULLs to check that functions are in the right positions is not fun. It's fundamentally another form of magic number.


    Sigh. There are 255 of them. 10 per line. Can you count to 10? What would you have them do? something like, in code, assign:

    SID[OP_START_DIAGNOSTIC] = &start_diagnostic_session;

    etc.? That's a really bad idea, because it's wasted space on a system where you're very likely counting bytes to fit all the code and data on a very small ROM, and it's simply unneeded. If this kind of thing bothers you, stay the heck away from embedded systems.

    Yes. And if the optimising compiler (they do exist for C, right?) can't produce optimal code, then I would look at how to do it with a preprocessor. When I write programs for the Java4k competition, which imposes a tight constraint on code size, I expect to put a moderate amount of effort into writing scripts which turn source I can maintain into source which produces the shortest output.
  • Nagesh 2011-02-23 14:21
    hoodaticus:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
    You're all wrong. This is the best way to get rid of trolls. I promise.


    That makes as much sense as the code posted in this WTF.
  • Aris 2011-02-23 14:30
    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.
  • Jenkins 2011-02-23 14:32
    NOT the original, ORIGINAL by:
    DOA:
    NOT the original, ORIGINAL by:
    foo:
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.


    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.


    hndsafhflk;hds;lfkhodsioudsuhniks ujmdfpdsisd098u9dfsa-]9sadfs9yh[0fsasa bsda0 f dsfba


    See! We need moar of this! ^^

    You mean sock puppeteering?
  • NOT the original, ORIGINAL by 2011-02-23 14:38
    Jenkins:
    NOT the original, ORIGINAL by:
    DOA:
    NOT the original, ORIGINAL by:
    foo:
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.


    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.


    hndsafhflk;hds;lfkhodsioudsuhniks ujmdfpdsisd098u9dfsa-]9sadfs9yh[0fsasa bsda0 f dsfba


    See! We need moar of this! ^^

    You mean sock puppeteering?


    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)
  • Nagesh 2011-02-23 14:41
    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.
  • dhromed 2011-02-23 14:46
    Nagesh:
    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.


    Hey Hoodaticus, with friends likes this...
  • ¢ÃƒÆ’ĉۮ2011-02-23 14:48
    Nagesh:
    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.


    No, Nagesh, you are not an entertaining troll. Stop wishing that you could be a "good" troll.
  • boog 2011-02-23 14:55
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
  • Abso 2011-02-23 14:56
    ¢ÃƒÆ’ƒâ€Ãâ€:
    Nagesh:
    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.


    No, Nagesh, you are not an entertaining troll. Stop wishing that you could be a "good" troll.


    But he's registered, so clearly he's not part of the problem at all.
  • Bert Glanstron 2011-02-23 14:56
    Nagesh:
    Bert Glanstron:

    Dear Nagesh,

    In case you can’t tell, this is a grown-up place. The
    fact that you insist on using your ridiculous fake handle
    clearly shows that you’re too young and too stupid
    to be using thedailywtf.com

    Go away and grow up.

    Sincerely,
    Bert Glanstron

    It would be so easy, if everyone registered.


    Dear admins,

    The feed clearly indicates that no handles are allowed. I insist that Nagesh be cut from thedailywtf.com completely.

    Sincerely,
    Bert Glanstron
  • hoodaticus 2011-02-23 15:02
    Nagesh:
    hoodaticus:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
    You're all wrong. This is the best way to get rid of trolls. I promise.


    That makes as much sense as the code posted in this WTF.
    As with the code posted here, it helps if you know the language.
  • hoodaticus 2011-02-23 15:13
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.
  • All Females 2011-02-23 15:23
    hoodaticus:
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.

    *gag*
  • Tracy Morgan 2011-02-23 15:26
    All Females:
    hoodaticus:
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.

    *gag*


    *gurkle* *gulkle* *gurkle* *GACK!*
  • NOT the original, ORIGINAL by 2011-02-23 15:27
    hoodaticus:
    Nagesh:
    hoodaticus:
    RickD:
    The best way to eliminate trolls is to ignore them, plain and simple.

    Actually, the best way to eliminate trolls is to have a system where moderators tag the troll posts and the system hides the tagged posts from everyone but the poster. The trolls don't realize they've been moderated, they just see that nobody is taking their bait. Eventually they go away because it's no fun for them.

    The downside is you have to require registration and logon to read posts.
    You're all wrong. This is the best way to get rid of trolls. I promise.


    That makes as much sense as the code posted in this WTF.
    As with the code posted here, it helps if you know the language.


    QFT
  • Captain Oblivious 2011-02-23 15:52
    Steve The Cynic:
    Ok, the arrangement of entries is a little wanked, mostly because the names of the functions aren't the same length in the source code as NULL is, but there's nothing particularly wrong with this.

    The declaration is confusing because, although it is accurately declared as an array of constant pointers to functions receiving const u8 * and (const) u16 and returning void, it is unusual to see an array of function pointers declared in a single step like this. I wrote my first C program 26 years ago (and have been writing them ever since, as well as C++, Fortran, assembler, Pascal, VB, Python, OPL, and a few other oddments), and it took me a moment to work out where the "const" was supposed to be binding.

    Other than that, and a lack of hint comments showing what the programmer thinks the indexes are, it's not so bad.


    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))
  • powerlord 2011-02-23 16:04
    All Females:
    hoodaticus:
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.

    *gag*

    Yeah right. Like there are females that read TDWTF comments.
  • fruits 2011-02-23 16:06
    Nagesh:
    It would be so easy, if everyone registered.
    This unregistered commentating is driving up the troll ratio.

    ...

    If you are going to troll, be an entertaining troll. Don't be stick in mud garden vareity troll.


    The comedy here is so sweet, I think I'll be skipping lunch today
  • All Females 2011-02-23 16:10
    powerlord:
    All Females:
    hoodaticus:
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.

    *gag*

    Yeah right. Like there are females that read TDWTF comments.

    It's true! Oprah just put TDWTF comments on her book club!
  • BK 2011-02-23 16:17
    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.
  • rfoxmich 2011-02-23 16:21
    TRWFT is that there isn't really a WTF in this article...just a function dispatch table.
  • smxlong 2011-02-23 16:25
    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
  • Lingerance 2011-02-23 16:30
    BK:
    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.


    Implementing your own vtable in C is stupid since you almost always get a C++ compiler to go with your C compiler.
  • Nagesh 2011-02-23 16:40
    All Females:
    hoodaticus:
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.

    *gag*


    You win "The lamest handle in WTF." award.
  • Spectre 2011-02-23 16:41
    Lingerance:
    BK:
    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.


    Implementing your own vtable in C is stupid since you almost always get a C++ compiler to go with your C compiler.


    Dude, I don't know about that. I think your stupid for begging the question that C++ is a superior language.
  • Mike 2011-02-23 16:41
    For those who say it's not a WTF, you are wrong. Sure it looks like a vtable, but how the hell do you maintain code where data is floating in a sea of NULLs?

    Here's a maintainable implementation. I assume here that there are constants for what the offsets mean, but that's probably optimistic.

    memset( vtable, 0, sizeof( vtable ) );
    vtable[METHOD_START] = &start_diagnostic_session;
    vtable[METHOD_READ_ECU] = &read_ecu_identification;
    vtable[METHOD_READ_DATA] = &rd_data_by_common_identifier;
    vtable[METHOD_SECURITY] = &security_access;
    vtable[METHOD_WRITE_DATA] = &wr_data_by_common_identifier;
  • Nagesh 2011-02-23 16:44
    Spectre:
    Lingerance:
    BK:
    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.


    Implementing your own vtable in C is stupid since you almost always get a C++ compiler to go with your C compiler.


    Dude, I don't know about that. I think your stupid for begging the question that C++ is a superior language.


    My old college teacher said C++ is only superior to C if you consider amount of documents produced by it.
  • Smitty 2011-02-23 16:50
    Mike:
    For those who say it's not a WTF, you are wrong. Sure it looks like a vtable, but how the hell do you maintain code where data is floating in a sea of NULLs?

    Here's a maintainable implementation. I assume here that there are constants for what the offsets mean, but that's probably optimistic.

    memset( vtable, 0, sizeof( vtable ) );
    vtable[METHOD_START] = &start_diagnostic_session;
    vtable[METHOD_READ_ECU] = &read_ecu_identification;
    vtable[METHOD_READ_DATA] = &rd_data_by_common_identifier;
    vtable[METHOD_SECURITY] = &security_access;
    vtable[METHOD_WRITE_DATA] = &wr_data_by_common_identifier;

    I don't like the superfluous memset.
    What's wrong with this?
    static void (*const SID[MAX_NUM_SERVICE_IDENTIFIERS])
    
    ( const u8 *data, const u16 bytes ) = {0};
    vtable[METHOD_START] = &start_diagnostic_session;
    vtable[METHOD_READ_ECU] = &read_ecu_identification;
    vtable[METHOD_READ_DATA] = &rd_data_by_common_identifier;
    vtable[METHOD_SECURITY] = &security_access;
    vtable[METHOD_WRITE_DATA] = &wr_data_by_common_identifier;


  • Nagesh 2011-02-23 16:50
    Abso:
    ¢ÃƒÆ’ƒâ€Ãâ€:
    Nagesh:
    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.


    No, Nagesh, you are not an entertaining troll. Stop wishing that you could be a "good" troll.


    But he's registered, so clearly he's not part of the problem at all.


    That is exactly right.


    If you're not part of problem, you end up being part of the solution provider.

    ...Martin Luthor King.

  • NOT the original, ORIGINAL by 2011-02-23 16:55
    Nagesh:
    Abso:
    ¢ÃƒÆ’ƒâ€Ãâ€:
    Nagesh:
    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.


    No, Nagesh, you are not an entertaining troll. Stop wishing that you could be a "good" troll.


    But he's registered, so clearly he's not part of the problem at all.


    That is exactly right.


    If you're not part of problem, you end up being part of the solution provider.

    ...Martin Luthor King.



    Nagesh, please stop posting... I still have a ringing in my ears from reading your posts. I think I'm going to write up something in Greasemonkey to visually block his posts from my screen.
  • ¢ÃƒÆ’Æâ€à 2011-02-23 16:56
    Nagesh:
    All Females:
    hoodaticus:
    boog:
    Nagesh:
    One troll who has tried to be witty from time to time is hoodacticus.
    Tried and succeeded. Good job hoodie! (btw, can I call you hoodie? how about hoodarino?)
    Thanks, boog! You're one of my few favorites on here, and you can call me whatever you want.

    *gag*


    You win "The lamest handle in WTF." award.

    Nagesh, it doesn't count when you give yourself the award.
  • hoodaticus 2011-02-23 16:56
    Nagesh:
    My old college teacher said C++ is only superior to C if you consider amount of documents produced by it.
    Who cares?
  • PJH 2011-02-23 17:00
    hoodaticus:
    Nagesh:
    My old college teacher said C++ is only superior to C if you consider amount of documents produced by it.
    Who cares?


    I do.
    Dear Internets,

    Please post all of your stories about old teachers, bosses, and parents on this thread.

    Sincerely,
    TDWTF HiveMind(tm)
  • SP 2011-02-23 17:02
    Mike:
    For those who say it's not a WTF, you are wrong. Sure it looks like a vtable, but how the hell do you maintain code where data is floating in a sea of NULLs?

    Here's a maintainable implementation. I assume here that there are constants for what the offsets mean, but that's probably optimistic.

    memset( vtable, 0, sizeof( vtable ) );
    vtable[METHOD_START] = &start_diagnostic_session;
    vtable[METHOD_READ_ECU] = &read_ecu_identification;
    vtable[METHOD_READ_DATA] = &rd_data_by_common_identifier;
    vtable[METHOD_SECURITY] = &security_access;
    vtable[METHOD_WRITE_DATA] = &wr_data_by_common_identifier;


    That's very nice. But in small embedded systems -- which this presumably is -- we tend to favour storing things in program memory (i.e., flash or ROM) rather than in RAM. Firstly RAM's a precious resource (you might have, say, 512K of Flash and only 16K or RAM) so you don't want to waste it on non-varying things. And secondly you want to try and ensure that your code doesn't get corrupted (by cosmic rays or errant pointers elsewhere), and storing your lookup table in flash helps with this -- remember that your system may reset very rarely, perhaps only when the battery is disconnected.

    Incidentally you don't need the ampersand. Some coding standards rule against it. Also, on many automotive systems the standard library (e.g., memset) is not available or its usage is discouraged. Oh yes, and null pointers are not guaranteed to be "all bits zero", so that's going to need a deviation against MISRA-C.

    The original code isn't the tidiest I've ever seen, but it's fairly typical automotive code. The requirements, standards and development principles for this stuff are very different to what is state of the art for non-embedded applications software, but its no WTF.
  • hoodaticus 2011-02-23 17:02
    fruits:
    Nagesh:
    It would be so easy, if everyone registered.
    This unregistered commentating is driving up the troll ratio.

    ...

    If you are going to troll, be an entertaining troll. Don't be stick in mud garden vareity troll.


    The comedy here is so sweet, I think I'll be skipping lunch today
    That sounds... familiar. Yeah, familiar.

    Addendum (2011-02-23 17:14):
    But I wholeheartedly agree and approve.
  • Katy GaGa 2011-02-23 17:04
    Behold:
    Interestingly, this is pretty much how you write Python modules in C (that is, bindings to C code for Python). Except I think the array is even larger there.
    Pretty similar, except that in Python you'd write "spam" instead of "null."
  • Nagesh 2011-02-23 17:13
    Someone has stolen my account here! The impostor has posting in my account and defiling the name of my namesake. I did not notice until now because I was inspire by today's code. I am implementing it in code I am writing for big client, they will be very happy with this. I have shared this code with all my colleagues here in Hyderabad, we all agree this is the best code written. I do not know why you post this code on your site, there is no WTF in it at all. Thanks, Daily WTF!
  • ¢ÃƒÆâ₠2011-02-23 17:18
    Nagesh:
    Someone has stolen my account here! The impostor has posting in my account and defiling the name of my namesake. I did not notice until now because I was inspire by today's code. I am implementing it in code I am writing for big client, they will be very happy with this. I have shared this code with all my colleagues here in Hyderabad, we all agree this is the best code written. I do not know why you post this code on your site, there is no WTF in it at all. Thanks, Daily WTF!

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?
  • hoodaticus 2011-02-23 17:24
    SP:
    Mike:
    For those who say it's not a WTF, you are wrong. Sure it looks like a vtable, but how the hell do you maintain code where data is floating in a sea of NULLs?

    Here's a maintainable implementation. I assume here that there are constants for what the offsets mean, but that's probably optimistic.

    memset( vtable, 0, sizeof( vtable ) );
    vtable[METHOD_START] = &start_diagnostic_session;
    vtable[METHOD_READ_ECU] = &read_ecu_identification;
    vtable[METHOD_READ_DATA] = &rd_data_by_common_identifier;
    vtable[METHOD_SECURITY] = &security_access;
    vtable[METHOD_WRITE_DATA] = &wr_data_by_common_identifier;


    That's very nice. But in small embedded systems -- which this presumably is -- we tend to favour storing things in program memory (i.e., flash or ROM) rather than in RAM. Firstly RAM's a precious resource (you might have, say, 512K of Flash and only 16K or RAM) so you don't want to waste it on non-varying things. And secondly you want to try and ensure that your code doesn't get corrupted (by cosmic rays or errant pointers elsewhere), and storing your lookup table in flash helps with this -- remember that your system may reset very rarely, perhaps only when the battery is disconnected.

    Incidentally you don't need the ampersand. Some coding standards rule against it. Also, on many automotive systems the standard library (e.g., memset) is not available or its usage is discouraged. Oh yes, and null pointers are not guaranteed to be "all bits zero", so that's going to need a deviation against MISRA-C.

    The original code isn't the tidiest I've ever seen, but it's fairly typical automotive code. The requirements, standards and development principles for this stuff are very different to what is state of the art for non-embedded applications software, but its no WTF.
    Thank you for explaining that. I couldn't for the life of me figure out why this code is the way it is.

    A quibble, though. If size is the issue, and the vtable is not dynamic, why the hell would there be nulls?
  • ........................... 2011-02-23 17:37
    Nagesh:
    boog:
    I'm pretty sure I would have strangled the penguin before I got to the 4th NULL.


    What is strangling the penguin? Is this a BATMAN reference?


    Maybe it's something like choking the chicken but more linuxey way?
  • Nagesh 2011-02-23 17:38
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.
  • The Web is the Root of All Info 2011-02-23 17:46
    SnatchThePebblesFromMyHand:
    "Assemblies" in 1998? You're not fooling me, young grasshopper.

    It was *originally* in VB6 (around ~1998), then got ported to VB.Net.

    The free online book on how to do this:
    http://msdn.microsoft.com/en-us/vbasic/ms788236
  • Mike 2011-02-23 17:51
    SP:
    But in small embedded systems -- which this presumably is -- we tend to favour storing things in program memory (i.e., flash or ROM) rather than in RAM. Firstly RAM's a precious resource (you might have, say, 512K of Flash and only 16K or RAM) so you don't want to waste it on non-varying things. And secondly you want to try and ensure that your code doesn't get corrupted (by cosmic rays or errant pointers elsewhere), and storing your lookup table in flash helps with this -- remember that your system may reset very rarely, perhaps only when the battery is disconnected.

    Fair enough. It's unfortunate that C doesn't have better ways of specifying table layouts than buffer stuffing.
  • TheCPUWizard 2011-02-23 18:14
    [quote user="JamesCurran"
    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 :

    if(op == OP_START_DIAGNOSTIC)
    start_diagnostic_session(len, dataptr);


    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.
    [/quote]

    What you (and a bunch of other here are forgetting is there is a world of difference between compile time constants [stored in ROM] and runtime (even startup) calculation [stored in RAM]

    I recendly did an embedded system, 256KB of ROM [Mask, not prom,eerom,etc.] and 2K RAM [radiation hardened RAM is EXPENSIVE].

    There was one class which required about 40 bytes per instance, and had about 500 possible states (valid combinations of the members). Instead of using a conventional implmentation of fields in the clas holding the values, we stored ALL of the possible states in ROM [20KB], and each instance contained a single pointer to the appropriate state. When a calculation was performed on an instance, a "full" version was reconstituted in RAM, then calculations performed, and a search (optimized) of all of the possible values performed to find the appropriate match, we then retained just a "freeze dried" version.
  • An alternate explanation 2011-02-23 19:00
    Childish:
    C3PO:
    Obviously, Brian does not understand C. He probably thinks it's like Java™, where references new arrays are initialized to [n]null[/b] or 0 (depending on type) automatically. In C, if you initialize a structure, it is filled with random bits and bytes. This could be a sparse array or a fixed-state machine, which should in either case contain a valid base-case value.

    I would think that a "real" C programmer would just use 0 here, but maybe that is TRWTF?


    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));


    In that case the real developer might have introduced a bug. It is not safe to memset pointers because a null pointer don't have to be numeric 0(All bits 0).
  • hoodaticus 2011-02-23 19:51
    TheCPUWizard:
    What you (and a bunch of other here are forgetting is there is a world of difference between compile time constants [stored in ROM] and runtime (even startup) calculation [stored in RAM]

    I recendly did an embedded system, 256KB of ROM [Mask, not prom,eerom,etc.] and 2K RAM [radiation hardened RAM is EXPENSIVE].

    There was one class which required about 40 bytes per instance, and had about 500 possible states (valid combinations of the members). Instead of using a conventional implmentation of fields in the clas holding the values, we stored ALL of the possible states in ROM [20KB], and each instance contained a single pointer to the appropriate state. When a calculation was performed on an instance, a "full" version was reconstituted in RAM, then calculations performed, and a search (optimized) of all of the possible values performed to find the appropriate match, we then retained just a "freeze dried" version.
    I have this nagging suspicion that, if you take the enire inheritance hierarchy for this class and superimpose their vtables on overhead projector transparencies (pretending that NULL is just invisible), they all go to the same places. I think they're using vtables to selectively hide base class members. I don't think that's real inheritance, and I don't see why they would need a vtable if the classes they need to dispatch on are so violently different. They could just write separate classes for them and be done with it.

    Or I could be wrong, and they used a random number generator to decide where to put their base class members in the vtable.
  • hoodaticus 2011-02-23 19:54
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.
    I almost lost bladder control from laughing so hard you asshole!
  • hoodaticus 2011-02-23 20:01
    Â)¢ÃƒÆ’Æâ₠(1718 hours):
    Nagesh (unregistered) (1713 hours + immediate, prior comment):
    Someone has stolen my account here! The impostor has posting in my account and defiling the name of my namesake. I did not notice until now because I was inspire by today's code. I am implementing it in code I am writing for big client, they will be very happy with this. I have shared this code with all my colleagues here in Hyderabad, we all agree this is the best code written. I do not know why you post this code on your site, there is no WTF in it at all. Thanks, Daily WTF!

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?
    How many Nageshes are you, honestly? +10 if you answer, "We are Legion."
  • smxlong 2011-02-23 20:02
    Mike:
    For those who say it's not a WTF, you are wrong. Sure it looks like a vtable, but how the hell do you maintain code where data is floating in a sea of NULLs?

    Here's a maintainable implementation. I assume here that there are constants for what the offsets mean, but that's probably optimistic.

    memset( vtable, 0, sizeof( vtable ) );
    vtable[METHOD_START] = &start_diagnostic_session;
    vtable[METHOD_READ_ECU] = &read_ecu_identification;
    vtable[METHOD_READ_DATA] = &rd_data_by_common_identifier;
    vtable[METHOD_SECURITY] = &security_access;
    vtable[METHOD_WRITE_DATA] = &wr_data_by_common_identifier;


    Dude, you just added like, 20 to 30 bytes to the size of the .text section with those stupid assignment instructions. And you caused the vtable to now have to exist in writable memory, which is at a premium on most embedded systems, instead of living on a cheap ROM. You fail.

    Ever read that paper, "Incompetent and Unaware of it?"
  • TheCPUWizard 2011-02-23 20:42
    hoodaticus:
    Or I could be wrong, and they used a random number generator to decide where to put their base class members in the vtable.


    Based on the code, I see no evidence that it is a vtable (i.e. a methodology for dispatching calls for an overridable method in a class). In fact, there is no evidence of any object oriented elements. It is a simple function dispatch table.

    Looking back at the comments, it is quite likely that "vtable' was brought of more as an analogy than as a proper usage of the term.
  • Mr Automotive Man 2011-02-23 21:24
    This is clearly (at least to me) a KWP2000 (Keyword Protocol) dispatcher from an automotive ECU.

    My company usually buys this part of the system from a third party supplier either in the form of source code or a precompiled library, which comes along with a code generator which generates ROM tables like this. This specific table is used to map the SIDs or service IDs (a standard term from the relevant ISO standard) which come in the fist byte of the request message to the function that handles that specific service. Normally this part of the code is generated automatically and is part of the third party module, and it is calling functions in the device specific code (written by us).

    The benefit of writing the SIDs table like this is obviously faster lookup at the expense of a bit of extra ROM being used. Different ECUs would have more services defined so the table would be less sparse. Fortunately the third party solutions that we use are a little smarter and have two columns, one for the service ID and the other for the function pointer!
  • Mike 2011-02-23 23:41
    smxlong:
    Dude, you just added like, 20 to 30 bytes to the size of the .text section with those stupid assignment instructions. And you caused the vtable to now have to exist in writable memory, which is at a premium on most embedded systems, instead of living on a cheap ROM. You fail.

    Ever read that paper, "Incompetent and Unaware of it?"

    Do you know the RAM budget on this project? If it's megabytes, you're prematurely optimizing. If it's kilobytes, you are right: it makes sense to sacrifice some readability. Where I work, the highest cost is paying developers - hardware is dirt cheap in comparison. In this environment, maintainable code is more valuable by many orders of magnitude than 290 bytes of RAM.
  • Alexander 2011-02-24 04:14
    I don't see a WTF here. This is a lookup table to choose functionality based on an opcode. They initialize everything they know at compile time with the real values and everything else cleanly with null. Of course you could write that in a loop, but why waste precious runtime if you can do it at compile time? Computers weren't always as fast as they are now.
  • Not of this Earth 2011-02-24 04:46
    Umm... Where am I?
    Oh, not so much WTFs in articles as in the comments...
  • Bert Glanstron 2011-02-24 05:32
    I have NULLed your array.
    Pray I don't NULL it further.
  • aks 2011-02-24 06:45
    I also don't see the WTF. A function pointer dispatch table is anyday better than a giant fugly switch(){ case : } or a huge if () else if(). Not to mention better maintainablity and way way way more faster than those comparisions can ever dream of becoming (think pipelining on ARMs). Plus I doubt that somebody wrote that by hand, it probably was generated using a tool (or Excel, which is excellent for maintaining such arrays and readability). I guess that the author has not found the tool (or the excel sheet) to do so and is bitching about it.
  • Guest 2011-02-24 07:15
    It really is like I'm looking at the Win32 API!
  • ParkinT 2011-02-24 08:07
    Sing along...
    "99 NULLs in the method call,
    99 NULLs in the call.
    You take one down - pass it around,
    98 NULLs in the method call..."
  • funluvncriminal 2011-02-24 08:29
    Lingerance:
    BK:
    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.


    Implementing your own vtable in C is stupid since you almost always get a C++ compiler to go with your C compiler.

    Dude, considering the function prototype starts with the word static (aren't all functions in C static, variables are a different story, but functions...), I don't think he's working with a vanilla C compiler, and this thing is really as misguided as it looks.

    Addendum (2011-02-24 08:35):
    Lingerance:
    BK:
    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.


    Implementing your own vtable in C is stupid since you almost always get a C++ compiler to go with your C compiler.

    Well, it may seem so, however if you're developing for an embedded environment, without a file system, then it may well be considered best practice.
  • __moz 2011-02-24 09:08
    aks:
    I also don't see the WTF. A function pointer dispatch table is anyday better than a giant fugly switch(){ case : } or a huge if () else if(). Not to mention better maintainablity and way way way more faster than those comparisions can ever dream of becoming (think pipelining on ARMs). Plus I doubt that somebody wrote that by hand, it probably was generated using a tool (or Excel, which is excellent for maintaining such arrays and readability). I guess that the author has not found the tool (or the excel sheet) to do so and is bitching about it.


    Imagine that. Some hotshot knowitall developer submitted something that extends beyond his limited firsthand experience as a WTF.
  • TheCPUWizard 2011-02-24 09:21
    [quote user="funluvncriminalDude, considering the function prototype starts with the word static (aren't all functions in C static, variables are a different story, but functions...), I don't think he's working with a vanilla C compiler, and this thing is really as misguided as it looks.[/quote]

    You need to go learn C.... elements at File Scope can be either extern (visible to other compile units) or static (available only within the compilation unit). In this regard there is no difference between C and C++.
  • Nagesh 2011-02-24 09:28
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.


    Why you force client to buy new server? OUr client still running our super fast quick code on 486 and Pentium machine. He never complain. Truly good code is one that runs on less resources.
  • Lingerance 2011-02-24 09:36
    Nagesh:
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.


    Why you force client to buy new server? OUr client still running our super fast quick code on 486 and Pentium machine. He never complain. Truly good code is one that runs on less resources.

    I'm still not sure why we let Indians write code anyway. Is it some sort of reparations? Isn't giving casinos to you enough?
  • World Traveler 2011-02-24 09:42
    hoodaticus:
    Â)¢ÃƒÆ’Æâ₠(1718 hours):
    Nagesh (unregistered) (1713 hours + immediate, prior comment):
    Someone has stolen my account here! The impostor has posting in my account and defiling the name of my namesake. I did not notice until now because I was inspire by today's code. I am implementing it in code I am writing for big client, they will be very happy with this. I have shared this code with all my colleagues here in Hyderabad, we all agree this is the best code written. I do not know why you post this code on your site, there is no WTF in it at all. Thanks, Daily WTF!

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?
    How many Nageshes are you, honestly? +10 if you answer, "We are Legion."

    Ever visit India? It's impossible to park your car without running over 5 or 6 guys who answer to "Nagesh."
  • Nagesh 2011-02-24 09:47
    Lingerance:
    Nagesh:
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.


    Why you force client to buy new server? OUr client still running our super fast quick code on 486 and Pentium machine. He never complain. Truly good code is one that runs on less resources.

    I'm still not sure why we let Indians write code anyway. Is it some sort of reparations? Isn't giving casinos to you enough?


    What casinos? Gambling is illegal in India.


    True story from Mahabharat. Look up Yudishthira, Draupadi, Gambling, Dice, Shakuni, Pandav.

  • Daniel 2011-02-24 09:47
    Definitely KWP2000. I don't see what's *really* that wrong with the code - maybe it could have been initialised a little more clearly but it's obvious to anyone who's been in the vehicle/automotive/machine control industry for more than 5 minutes what it is and what it does.
  • Nagesh 2011-02-24 09:50
    NOT the original, ORIGINAL by:
    Nagesh:
    Abso:
    ¢ÃƒÆ’ƒâ€Ãâ€:
    Nagesh:
    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.


    No, Nagesh, you are not an entertaining troll. Stop wishing that you could be a "good" troll.


    But he's registered, so clearly he's not part of the problem at all.


    That is exactly right.


    If you're not part of problem, you end up being part of the solution provider.

    ...Martin Luthor King.



    Nagesh, please stop posting... I still have a ringing in my ears from reading your posts. I think I'm going to write up something in Greasemonkey to visually block his posts from my screen.


    You have failed! Why make so much noise about writing some script?

    You limp wristed, lack of moral fiber, noise making hypocrite cannot ignore me. That's true WTF.


    We are legion...
    There I said it.. hoodarino.
  • Daniel 2011-02-24 09:53
    Forgot to mention: not necessarily precisely ISO 14230 Keyword Protocol 2000 but possibly a harmonised spec such as Swedish Implementation Standard (SSF) 14230. Either way, it's the same thing in different clothes.
  • jcsalomon 2011-02-24 11:31
    boog:
    It looks like more work from this guy. But today's code appears to be a step up from the other method. That is, at least he's not using a case statement
    Behold:
    Interestingly, this is pretty much how you write Python modules in C (that is, bindings to C code for Python). Except I think the array is even larger there.
    In C99, this would look entirely reasonable:
    static void (*const SID[MAX_NUM_SERVICE_IDENTIFIERS])
    
    ( const u8 *data, const u16 bytes ) =
    {
    [SERV_DIAG /* or whatever identifier they’re using */] = &start_diagnostic_session,
    […] = &read_ecu_identification,
    […] = &rd_data_by_common_identifier,
    […] = &security_access,
    […] = &wr_data_by_common_identifier,
    };
    TRWTF is how long it’s taken for compiler to implement this.
  • hoodaticus 2011-02-24 11:42
    TheCPUWizard:
    hoodaticus:
    Or I could be wrong, and they used a random number generator to decide where to put their base class members in the vtable.


    Based on the code, I see no evidence that it is a vtable (i.e. a methodology for dispatching calls for an overridable method in a class). In fact, there is no evidence of any object oriented elements. It is a simple function dispatch table.

    Looking back at the comments, it is quite likely that "vtable' was brought of more as an analogy than as a proper usage of the term.
    Okay, now it makes way more sense and doesn't seem like a WTF to me. Those nulls are either truly empty or invalid in the pre-computed context that this array serves. Gotcha.
  • hoodaticus 2011-02-24 11:55
    Nagesh:
    Lingerance:
    Nagesh:
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.


    Why you force client to buy new server? OUr client still running our super fast quick code on 486 and Pentium machine. He never complain. Truly good code is one that runs on less resources.

    I'm still not sure why we let Indians write code anyway. Is it some sort of reparations? Isn't giving casinos to you enough?


    What casinos? Gambling is illegal in India.


    True story from Mahabharat. Look up Yudishthira, Draupadi, Gambling, Dice, Shakuni, Pandav.

    His use of "Indian" was a play on words. He meant MY kind of Indian, not your kind of Indian. Your kind of Indian is what Christopher Columbus was looking for when he discovered America for the Europeans. MY kind of Indian is what the Europeans actually found when they got here.

    You're East Indian. I'm West Indian (part Cherokee). Both are swarthy heathens, but your kind didn't chop the scalps off of the invading British horde for trophies. You also probably didn't eat entire British colonies, which is my educated guess as to what happened to Jamestown.

    I bet they were delicious.
  • derp 2011-02-24 12:10
    Mike:
    smxlong:
    Dude, you just added like, 20 to 30 bytes to the size of the .text section with those stupid assignment instructions. And you caused the vtable to now have to exist in writable memory, which is at a premium on most embedded systems, instead of living on a cheap ROM. You fail.

    Ever read that paper, "Incompetent and Unaware of it?"

    Do you know the RAM budget on this project? If it's megabytes, you're prematurely optimizing. If it's kilobytes, you are right: it makes sense to sacrifice some readability. Where I work, the highest cost is paying developers - hardware is dirt cheap in comparison. In this environment, maintainable code is more valuable by many orders of magnitude than 290 bytes of RAM.



    This code is obviously going into a million+ units of embedded car ECUs, so they can't just shit out fifteen minutes worth of Python code and tell the customer to spend more on hardware.

    This just in: sometimes optimization is actually necessary!

    Besides, it's just a sparse array of function pointers forming a dispatch table. I'd consider some common C++ "idioms" far less maintainable.
  • Nagesh 2011-02-24 12:11
    hoodaticus:
    Nagesh:
    Lingerance:
    Nagesh:
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.


    Why you force client to buy new server? OUr client still running our super fast quick code on 486 and Pentium machine. He never complain. Truly good code is one that runs on less resources.

    I'm still not sure why we let Indians write code anyway. Is it some sort of reparations? Isn't giving casinos to you enough?


    What casinos? Gambling is illegal in India.


    True story from Mahabharat. Look up Yudishthira, Draupadi, Gambling, Dice, Shakuni, Pandav.

    His use of "Indian" was a play on words. He meant MY kind of Indian, not your kind of Indian. Your kind of Indian is what Christopher Columbus was looking for when he discovered America for the Europeans. MY kind of Indian is what the Europeans actually found when they got here.

    You're East Indian. I'm West Indian (part Cherokee). Both are swarthy heathens, but your kind didn't chop the scalps off of the invading British horde for trophies. You also probably didn't eat entire British colonies, which is my educated guess as to what happened to Jamestown.

    I bet they were delicious.


    In that he should have just used the term "Red Indian". That's we Indians usually understand very quickly. Thanks for the clarification, though.


    Columbus sailed the ocean blue, (forget the rest)

  • boog 2011-02-24 12:23
    Nagesh:
    hoodaticus:
    His use of "Indian" was a play on words.

    In that he should have just used the term "Red Indian". That's we Indians usually understand very quickly.

    Then it wouldn't have been a play on words.
    </duh>
  • Abso 2011-02-24 12:36
    derp:
    This code is obviously going into a million+ units of embedded car ECUs, [...]
    Then why would they hand it to a single developer who was totally unfamiliar with it for "upkeep 'n such"?
  • Moebius Wilburs 2011-02-24 12:49
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.
  • Nagesh 2011-02-24 12:53
    Moebius Wilburs:
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.


    Huh!!! I never heard that before...
  • hoodaticus 2011-02-24 13:05
    Nagesh:
    Moebius Wilburs:
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.


    Huh!!! I never heard that before...
    That's because he just made it up, and it's freakin badass!
  • hoodaticus 2011-02-24 13:06
    Moebius Wilburs:
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.
    Is this the real Moebius Wilters? I love that guy!
  • hoodaticus 2011-02-24 13:06
    Moebius Wilburs:
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.
    Is this the real Moebius Wilters? I love that guy!
  • NOT the original, ORIGINAL by 2011-02-24 13:38
    hoodaticus:
    Moebius Wilburs:
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.
    Is this the real Moebius Wilters? I love that guy!


    Wow, a double post... Now that's a LOT of love.
  • Hungrybear9562 2011-02-24 14:30
    NOT the original, ORIGINAL by:
    hoodaticus:
    Moebius Wilburs:
    Nagesh:
    Columbus sailed the ocean blue, (forget the rest)

    ...looking to steal from you,
    Instead he found the Caribean,
    and raped the Red Indian.
    Is this the real Moebius Wilters? I love that guy!


    Wow, a double post... Now that's a LOT of love.

    What does it mean?
  • dposluns 2011-02-24 16:36
    I'll join the contingent that agrees this kind of system is perfectly acceptable and normal, especially in embedded systems.

    Two changes I would make to make it less WTFy:

    1. Typedef the function pointer type to make the code more readable. Function pointer semantics are a black art to a lot of people to begin with, so declaring an array of them without a typedef isn't being particularly kind to those who aren't C veterans.

    2. Change SID[MAX_NUM_SERVICE_IDENTIFIERS] to just SID[], and add a static assert (compile-time assert) that the size of the SID array == MAX_NUM_SERVICE_IDENTIFIERS. Why? Because just putting MAX_NUM_SERVICE_IDENTIFIERS as the array size doesn't guarantee that you'll have initialized the correct number of values. Instead, it's a far better practice to let the compiler size the array based on what you've entered, and then have it assert that the size it arrived at matches your expected value. That way if either the array contents change or MAX_NUM_SERVICE_IDENTIFIERS changes it will be caught on the next build attempt.

    For bonus points, I would replace the NULLs with a function that asserts in debug builds.

    Dan.
  • MarkG 2011-02-24 16:45
    Well,

    It's not the most ideal way to do it but it isn't unheard of. It's for processing messages for automotive protocols. I'm willing to bet that start_diagnostic_session is at position 0x10 and security_access is at position 0x21.

    The RWTF here is that you should understand the nature of the thing you are maintaining. I'm not saying a table full of NULL pointers is the best approach -- but I could see how it could be useful. Especially if there are multiple tables like this and the current state or mode of communication adjusts the table used.

    Having worked on this kind of stuff I tend to use switch/cases for these since the messages you deal with are sparse.


  • jcsalomon 2011-02-24 17:53
    Or my C99 version above, which will initialize exactly the fields which are meaningful to initialize, and set the rest to NULL. Trouble is the lack of C99 in the embedded C market.

    (Does this thread belong on comp.lang.c instead?)
  • smxlong 2011-02-24 18:41
    Abso:
    derp:
    This code is obviously going into a million+ units of embedded car ECUs, [...]
    Then why would they hand it to a single developer who was totally unfamiliar with it for "upkeep 'n such"?


    I doubt that's what happened. More likely, the submitter went poking through the codebase, found this thing, didn't immediately have a clue what it was for, and assumed it must therefore be a WTF.

    What makes it doubly hilarious is that this code was most likely automatically generated, rendering any maintenance argument moot and making the suggestions here of how to make it more "maintainable" look completely ridiculous.
  • an 2011-02-24 18:57
    TRWTF is the lack of typedefs, useless use of ampersand and sparse array initialization.

    typedef void (*sid_callback_t)(const u8 * data, const u16 bytes);
    static const sid_callback_t SID[MAX_NUM_SERVICE_IDENTIFIERS] = {
    [16] = start_diagnostic_session,
    [26] = read_ecu_identification,
    [34] = rd_data_by_common_identifier,
    [39] = security_access,
    [46] = wr_data_by_common_identifier
    };

    Captcha: eros -- C is only for real men.
  • hoodaticus 2011-02-24 19:30
    Daniel:
    Forgot to mention: not necessarily precisely ISO 14230 Keyword Protocol 2000 but possibly a harmonised spec such as Swedish Implementation Standard (SSF) 14230. Either way, it's the same thing in different clothes.
    I'm amazed at how many ECU C programmers we have here. Lurking. Waiting to kill us all with their leetness.

    Seriously, I'm glad they're here.
  • hoodaticus 2011-02-24 19:34
    boog:
    Nagesh:
    hoodaticus:
    His use of "Indian" was a play on words.

    In that he should have just used the term "Red Indian". That's we Indians usually understand very quickly.

    Then it wouldn't have been a play on words.
    </duh>
    Now, if we were actually racist against East Indians, we'd replace "casino" in the prior example with, say, "7-Eleven", and think it more accurate.
  • hoodaticus 2011-02-24 19:49
    Guest:
    It really is like I'm looking at the Win32 API!
    Welcome to the world before objects. What you see before you is the primordial ooze whence they evolved.
  • Stuart 2011-02-24 20:09
    MarkG:

    The RWTF here is that you should understand the nature of the thing you are maintaining.

    Absolutely. I've never worked in the embedded space, or on automotive systems, but I do know C, and after the initial two seconds of "WTF is that" had passed and I actually looked at it, it was very clear it was a dispatch table based on decoding a protocol of some sort. It certainly could have done with more comments, but it's absolutely a valid approach that a real C programmer will understand.
  • Coyne 2011-02-24 22:11
    All I can say is, "NULL, NULL, NULL. NULL, NULL, NULL and NULL."
  • SP 2011-02-25 02:08
    dposluns:

    For bonus points, I would replace the NULLs with a function that asserts in debug builds.


    I expect that if SID[id] is NULL the calling code sends a "service not supported" response.
  • Not of this Earth 2011-02-25 03:10
    I got it!
    TRWTF is Johnny D bitching about pretty standard scalable solution!
  • Design Pattern 2011-02-25 09:28
    smxlong:
    Abso:
    Then why would they hand it to a single developer who was totally unfamiliar with it for "upkeep 'n such"?


    I doubt that's what happened. More likely, the submitter went poking through the codebase, found this thing, didn't immediately have a clue what it was for, and assumed it must therefore be a WTF.

    What makes it doubly hilarious is that this code was most likely automatically generated, rendering any maintenance argument moot and making the suggestions here of how to make it more "maintainable" look completely ridiculous.

    The question still remains why he was poking through the codebase, unaware of the development process / code generation.

    Handing over development/maintenance to an incompetent programmer not knowing standard C practices and not giving him information about the code generation is TRWTF.
  • pjt33 2011-02-25 14:53
    aks:
    I also don't see the WTF. A function pointer dispatch table is anyday better than a giant fugly switch(){ case : } or a huge if () else if(). Not to mention better maintainablity and way way way more faster than those comparisions can ever dream of becoming (think pipelining on ARMs). Plus I doubt that somebody wrote that by hand, it probably was generated using a tool (or Excel, which is excellent for maintaining such arrays and readability). I guess that the author has not found the tool (or the excel sheet) to do so and is bitching about it.

    If you're right that it was in fact created by a tool (and I have already asserted that it *should be*, so I'm in full agreement with the concept), there are two small WTFs.

    1. The tool doesn't include in its output a comment to help the maintainer find it.
    2. It seems highly likely that someone checked the generated code into version control rather than marking it as ignorable.
  • Guest 2011-02-25 19:08
    I really liked this article and comments keep up the good work. Researching function pointers was a very educational way to spend a slow Friday afternoon at work.

    Looks like he is declaring an array of pointers SID. Where the majority of the contents are NULL pointers and the non NULLs are the addresses of functions.

    To me the WTF is the risk of de-referencing a NULL pointer.

  • Joe 2011-02-27 16:48
    an:
    TRWTF is the lack of typedefs, useless use of ampersand and sparse array initialization.

    typedef void (*sid_callback_t)(const u8 * data, const u16 bytes);
    static const sid_callback_t SID[MAX_NUM_SERVICE_IDENTIFIERS] = {
    [16] = start_diagnostic_session,
    [26] = read_ecu_identification,
    [34] = rd_data_by_common_identifier,
    [39] = security_access,
    [46] = wr_data_by_common_identifier
    };

    Captcha: eros -- C is only for real men.


    I was about the post almost identical code, until I saw your post. The only change I would recommend is that the literal subscript values should probably be replaced with the enum values identifying the opcode number or message number (depending on what type of dispatch table this is) that will be used when actually indexing this array.

    One should mention that your code is C99, and thus if for some reason you absolutely must use a C90 compiler, it would not work.
  • anon 2011-02-28 14:04
    hoodaticus:
    I do this same thing in C#. After all, the simplicity of using lambda expressions is made even more simple by passing them around in giant STRUCTS. I dump every lambda I need into a struct and just pass it around everywhere.


    Well, aren't you just the coolest.
  • anon 2011-02-28 14:29
    NOT the original, ORIGINAL by:
    Jenkins:
    NOT the original, ORIGINAL by:
    DOA:
    NOT the original, ORIGINAL by:
    foo:
    NOT the original, ORIGINAL by:
    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.

    At least? So you mean, there's 50 percent or more useful content? I thought it was more like 10/90 or less.


    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.


    hndsafhflk;hds;lfkhodsioudsuhniks ujmdfpdsisd098u9dfsa-]9sadfs9yh[0fsasa bsda0 f dsfba


    See! We need moar of this! ^^

    You mean sock puppeteering?


    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)


    If you say so Mr. Hat.
  • anon 2011-02-28 15:30
    Nagesh:
    hoodaticus:
    Nagesh:
    Lingerance:
    Nagesh:
    Nagesh:
    ¢ÃƒÆââ‚Â:

    Nagesh is TRWTF.

    And you call us racist for saying outsourced code from India sucks?

    You are TWRTF and you are racist. Our code is much better than any USA code you can name, I dare you to prove different. Our last client paid lots of money for our code and they were so happy they got a faster server to run our code. I also wrote 6 thousand lines of code yesterday. I would have coded more but my keyboard is not working well, the keys do not always work so I ut and paste with the mouse.


    Why you force client to buy new server? OUr client still running our super fast quick code on 486 and Pentium machine. He never complain. Truly good code is one that runs on less resources.

    I'm still not sure why we let Indians write code anyway. Is it some sort of reparations? Isn't giving casinos to you enough?


    What casinos? Gambling is illegal in India.


    True story from Mahabharat. Look up Yudishthira, Draupadi, Gambling, Dice, Shakuni, Pandav.

    His use of "Indian" was a play on words. He meant MY kind of Indian, not your kind of Indian. Your kind of Indian is what Christopher Columbus was looking for when he discovered America for the Europeans. MY kind of Indian is what the Europeans actually found when they got here.

    You're East Indian. I'm West Indian (part Cherokee). Both are swarthy heathens, but your kind didn't chop the scalps off of the invading British horde for trophies. You also probably didn't eat entire British colonies, which is my educated guess as to what happened to Jamestown.

    I bet they were delicious.


    In that he should have just used the term "Red Indian". That's we Indians usually understand very quickly. Thanks for the clarification, though.


    Columbus sailed the ocean blue, (forget the rest)



    Nagesh, you are very racist, biggotted, small minded, and xenophobic for referring to native americans as "Red Indian". BTW code from India still sucks.
  • cindy 2011-03-01 02:24
    find for all kinds of watches and handbags

    http://replica038.com
  • cindy 2011-03-02 02:32
  • JoC 2011-03-02 14:53
    The code is self-documenting.

    You count NULLs on each line and convert the numerics to the equivalent ASC chars to get a short succinct comment.
  • SQLDave 2011-03-02 22:56
    It's just NULLs, all the way down.
  • J.D. 2011-03-03 23:08
    Yes, actually, I really had no idea what it was doing. And neither did much anyone else in the company. Finally I found a guy, who told me how that structure works. But that still doesn't explain, why there are 255 cells being used? Wouldn't just five cells be enough? Or, like suggested in an earlier post; five if's or a switch-case?
  • J.D. 2011-03-03 23:41
    Abso:
    derp:
    This code is obviously going into a million+ units of embedded car ECUs, [...]
    Then why would they hand it to a single developer who was totally unfamiliar with it for "upkeep 'n such"?

    Actually, you are now at the heart of the WTF. We've had some people leave the company and I've been used as the tossing bag between random, undocumented projects, that just need someone to make them do what they're supposed to do.
    smxlong:
    I doubt that's what happened. More likely, the submitter went poking through the codebase, found this thing, didn't immediately have a clue what it was for, and assumed it must therefore be a WTF.

    In this case there was a bug in one of those functions that are beyond the vtable. I personally hadn't encountered anything like this before and had no idea how it does what it does. And in any case, there have been more useful ways within these comments to implement this, than to make a complete 255 cell NULL table.
  • Max E. 2011-03-10 14:40
    I think this code looks reasonable... not great, but reasonable. I probably would have used a switch statement with an enum here, but I'm not an embedded programmer and I can see why this would be more reasonable in an embedded context.

    However, if this code is machine-generated, then the input files for the code generator should have been the "real" source code, with the snippet being an incidental part of the build process. So TRWTF is how did Johnny D even see this code!
  • Tiago Cardoso 2011-03-10 21:58
    Nagesh:
    Inside each small problem is a bigger one waiting to get out.

    Best comment I've ever seen here :D
  • Anonymous 2011-03-12 21:05
    frits:
    Who hasn't done something like this?


    Java programmers.