• Ouch! (unregistered)

    Did Emil at least hunt down the perpetrator?

  • Cbuttius (cs)

    Yes, bad use of magic number:

    enum { SEVEN = 7; }

    or whatever in your favourite language, is much better!

  • anon (unregistered) in reply to Cbuttius
    Cbuttius:
    Yes, bad use of magic number:

    enum { SEVEN = 7; }

    or whatever in your favourite language, is much better!

    enum { THIRTEEN = 7; } FTFY

  • Steve The Cynic (cs) in reply to anon
    anon:
    Cbuttius:
    Yes, bad use of magic number:

    enum { SEVEN = 7; }

    or whatever in your favourite language, is much better!

    enum { THIRTEEN = 7; } FTFY

    No, no, you mean enum { SEVEN = 13; }

  • Hasteur (cs)

    Must not put hand through monitor in attempt to forcibly sterilize coder who wrote that.

  • The Nerve (unregistered)

    Why not post the code where it sets Iselecvariablelst[7]? That would probably give you some clue what it's supposed to be.

  • snoofle (cs)

    So we've got 2 rows of 3 rectangles over a larger rectangle, on which a user can click to make something happen. Without context, who knows what this is... or even if its a bad thing. Maybe given context, the meaning of 7 is obvious.

  • bill lumbergh (unregistered)

    No more magic numbers. I'm making this an action item and we will have a code review at the end of the day. You will then verify your unit tests with me and fill out your PTR for quality control. Oh, I'll also need you to come in this Saturday.....and Sunday.

  • Adrian (unregistered)

    Aside from the use of a hard coded magic number, I'm not sure what was so confusing about the code. I work a lot with GUI systems and while I don't know what library that's from, it looks like it's simply designed to create 3xN button layout of some sort.

    It's not great code, and I'm not crazy about the formatting style choices, but if there's a WTF in there, it's really subtle.

  • millimeep (cs) in reply to anon

    Hmmm.... couldn't resist, so here's the new values of rect.x and rect.y:

    i      x      y
    0      -      -      
    1      4     75
    2    110     75
    3    216     75
    4      4    135
    5    110    135
    6    216    135
    

    So the initial values seem to be random, assuming they're x, y, w, h?

    So the default value for i=0 matches the new height, but not the width, y doesn't match and x matches for i=3 and i=6

    there's a WTF, but that does explain the null test later...

    Adding a changed event to a 3x2 grid of some sort of control???

    yep, this is TRWTF... I can see why he stopped there.

  • Anonymous (unregistered)

    Not thrilled by that magic number but beyond that there is not enough context here to really appreciate what's going on. It looks pretty dumb, there's no denying that, but all we can really do is guess. More info would have been nice.

  • vt_mruhlin (cs) in reply to Anonymous
    Anonymous:
    Not thrilled by that magic number but beyond that there is not enough context here to really appreciate what's going on.

    I'm pretty sure that's part of the point. If you're writing code like that you either don't have a good reason, or you need to put a shitload of comments explaining what your good reason is.

  • Bus Logic (unregistered) in reply to vt_mruhlin
    vt_mruhlin:
    Anonymous:
    Not thrilled by that magic number but beyond that there is not enough context here to really appreciate what's going on.

    I'm pretty sure that's part of the point. If you're writing code like that you either don't have a good reason, or you need to put a shitload of comments explaining what your good reason is.

    I agree with your assertion but playing devil's advocate one could argue that it's easy to produce an example of "unreadable" code if you take a sufficiently small portion of a sufficiently complex system. I'm pretty sure this is a WTF but you can't rule out the possibility that it genuinely is a sufficiently small portion of a sufficiently complex system.

  • Fernando (unregistered) in reply to The Nerve

    Setting Iselecvariablelst[7] would raise an array subscript error. Valid subscripts are 0 through 6.

  • frits (cs)

    Seven deadly sins Seven ways to win Seven holy paths to hell, and your trip begins

    Seven downward slopes Seven bloodied hopes Seven are your burning fires Seven your desires

  • Matt Westwood (unregistered)

    [OK, so it has to be relevant to the article. I understand...]

    Ah, magic number 7. I personally don't like magic numbers in my code but it is interesting to note that 7 is the number of cocks I've had in my mouth today since 7:00am. I don't know if this is some sort of sign or just a completely random coincidence but I must say that it's given me a boost and I'm very excited to think that my cock-munching will continue as soon as I've finished my break.

    So then, back to it...

  • amischiefr (cs) in reply to Adrian
    Adrian:
    Aside from the use of a hard coded magic number, I'm not sure what was so confusing about the code. I work a lot with GUI systems and while I don't know what library that's from, it looks like it's simply designed to create 3xN button layout of some sort.

    It's not great code, and I'm not crazy about the formatting style choices, but if there's a WTF in there, it's really subtle.

    I tend to agree with you on this one. Yes yes, we're all told magic numbers = the devil which = M$ which = Apple which = Osama. Personally I don't give a crap whether NUM_ELEMENTS (or whatever cool name you come up with) is in a .properties file, configurable at run time, some final static constant or hard coded in. I would "like" to see it as some variable with a nice, meaningful name to it, but is this really worthy of front page WTF-ery?

  • DrJDX (cs) in reply to Matt Westwood
    Matt Westwood:
    [OK, so it has to be relevant to the article. I understand...]

    Ah, magic number 7. I personally don't like magic numbers in my code but it is interesting to note that 7 is the number of cocks I've had in my mouth today since 7:00am. I don't know if this is some sort of sign or just a completely random coincidence but I must say that it's given me a boost and I'm very excited to think that my cock-munching will continue as soon as I've finished my break.

    So then, back to it...

    Hey Pal, we don't use that kinda language on this board. 7:00 AM is simply inappropriate subject matter, and I'll have to ask you to refrain from mentioning it in further discussion.

  • The Nerve (unregistered) in reply to Fernando
    Fernando:
    Setting Iselecvariablelst[7] would raise an array subscript error. Valid subscripts are 0 through 6.
    I'm assuming it's covered under "snip". That was a bad snip, and if Emil doesn't know that, he needs to go back to his cooking program.
  • Bosshog (unregistered)

    As I was going to St Ives, I met a man with seven wives. And every wife had seven sacks, and every sack had seven cats. And every cat had seven rats, with tiny little ratty hats. "Turn back!" said he with seven wives: "It is a silly place, St Ives."

  • Bosshog (unregistered) in reply to amischiefr
    amischiefr:
    NUM_ELEMENTS (or whatever cool name you come up with)
    NUMB_ELEPHANTS
  • Buck Dharma (unregistered) in reply to frits

    Here's some lyrics about the magical number 7...

    Along the world axis The Empress lay sleeping To the rhyme of the, of the, of the star clock Seven sleepers Seven sages Seven ladders to the, to the Seventh heaven

    Seven stars Had Ursa Major Tables turning, turning And rain maker While the seven The visitors All went, all went A drumming

    And for the record, I like using constants named like this:

    const int n1 = 1; const int n2 = 2; const int n3 = 3; const int n4 = 4; const int n6 = 5; const int n7 = 13;

    'cause it's better imho, you know, less confusion when you type Something[SEVEN] but you meant TEN, so my way, you type Something[n7] and you know, you are not BOUND to the value...right?

  • icebrain (unregistered) in reply to Bus Logic
    Bus Logic:
    vt_mruhlin:
    Anonymous:
    Not thrilled by that magic number but beyond that there is not enough context here to really appreciate what's going on.

    I'm pretty sure that's part of the point. If you're writing code like that you either don't have a good reason, or you need to put a shitload of comments explaining what your good reason is.

    I agree with your assertion but playing devil's advocate one could argue that it's easy to produce an example of "unreadable" code if you take a sufficiently small portion of a sufficiently complex system. I'm pretty sure this is a WTF but you can't rule out the possibility that it genuinely is a sufficiently small portion of a sufficiently complex system.
    No, the code should be locally self-explanatory, either by local comments or preferably by refactoring. You shouldn't have to go around to understand why do you need a Rectangle of (216,12,110,60), nor why do you need to apply those calculations if i > 0.

  • Forget Steve Reich (unregistered)

    There is no mystery here : the first time the enclosing function (or the file) is entered, the guy just draws 7 rectangles with GUI events attached inside, hence : buttons. On the subsequent iterations, some GUI interaction may be somehow handled in the snipped/uncopied portion of code.

    Now, why 7 ? That's straightforward enough : the guy is a fan of Webern and has written some code to play seralised music with the standard C scale.

    TRWF is that true dodecaphonism is f**ucking more fascinating than some melody in C.

  • nibh (unregistered) in reply to The Nerve
    The Nerve:
    Why not post the code where it sets Iselecvariablelst[7]? That would probably give you some clue what it's supposed to be.
    No seriously, Alex. Could you post the rest of the code here? At least the part that sets the 8th element (index = 7).
  • Forget Typos (unregistered)

    "seralised music" -> I meant 'serail music', of course :o\

  • frits (cs) in reply to nibh
    nibh:
    The Nerve:
    Why not post the code where it sets Iselecvariablelst[7]? That would probably give you some clue what it's supposed to be.
    No seriously, Alex. Could you post the rest of the code here? At least the part that sets the 8th element (index = 7).

    I doubt that happens. I think Emil was wondering why the fixed-size array had seven elements. The obvious answer is that's how many objects the code needs. Nothing more to see here.

  • Mike (unregistered)

    The real WTF is not using brackets for an if statement.

  • Max Guernsey, III (unregistered)

    It's not that bad. That is to say: I've seen substantially worse. This one seems a little weak. On the other hand, maybe we need a break after the truly enraging installment from yesterday.

  • dubbreak (cs) in reply to frits
    frits:
    Seven deadly sins Seven ways to win Seven holy paths to hell, and your trip begins

    Seven downward slopes Seven bloodied hopes Seven are your burning fires Seven your desires

    7's the key number here. Think about it.

    7-Elevens. 7 dwarves. 7, man, that's the number. 7 chipmunks twirlin' on a branch, eatin' lots of sunflowers on my uncle's ranch. You know that old children's tale from the sea... It's like you're dreamin' about Gorgonzola cheese when it's clearly Brie time, baby.

    Step into my office!

  • Guardian Bob (unregistered) in reply to millimeep
    millimeep:
    Hmmm.... couldn't resist, so here's the new values of rect.x and rect.y:
    i      x      y
    0      -      -      
    1      4     75
    2    110     75
    3    216     75
    4      4    135
    5    110    135
    6    216    135
    

    So the initial values seem to be random, assuming they're x, y, w, h?

    So the default value for i=0 matches the new height, but not the width, y doesn't match and x matches for i=3 and i=6

    there's a WTF, but that does explain the null test later...

    Adding a changed event to a 3x2 grid of some sort of control???

    yep, this is TRWTF... I can see why he stopped there.

    The key is with the widths/heights to understand what's happening: Basically, it looks like this a 3x3 grid, with the header (element 0) being in the 2nd column of the top row.

     -  HDR  - 
     1   2   3
     4   5   6
    

    Could be better documented, but it isn't the worst thing I've seen this week.

  • FuBar (unregistered) in reply to frits
    frits:
    Seven deadly sins
    Seven, seven, seven--deadly sins That's how the world begins Watch out when you step in For seven deadly sins Seven deadly sins That's when the fun begins [snip] (Sin number one) was when you left me (Sin number two) you said goodbye (Sin number three) was when you told me a little white lie (Sin number four) was when you looked my way (Sin number five) was when you smiled (Sin number six) was when you let me stay Sin number seven was when you touched me and drove me wild

    Thanks to Boo Wilbury!

  • Gondolf (unregistered)

    TRWTF is naming. The first line looks like he's instantiating an interface...

    I'm in ur base, Selecing your variablelst.

  • Loren Pechtel (unregistered) in reply to Guardian Bob
    Guardian Bob:
    millimeep:
    Hmmm.... couldn't resist, so here's the new values of rect.x and rect.y:
    i      x      y
    0      -      -      
    1      4     75
    2    110     75
    3    216     75
    4      4    135
    5    110    135
    6    216    135
    

    So the initial values seem to be random, assuming they're x, y, w, h?

    So the default value for i=0 matches the new height, but not the width, y doesn't match and x matches for i=3 and i=6

    there's a WTF, but that does explain the null test later...

    Adding a changed event to a 3x2 grid of some sort of control???

    yep, this is TRWTF... I can see why he stopped there.

    The key is with the widths/heights to understand what's happening: Basically, it looks like this a 3x3 grid, with the header (element 0) being in the 2nd column of the top row.

     -  HDR  - 
     1   2   3
     4   5   6
    

    Could be better documented, but it isn't the worst thing I've seen this week.

    Agreed. Other than the lack of documentation and the magic number this looks like what one very well might expect of code written in an environment that doesn't give you a visual designer.

    This doesn't rise to anything like the level of a WTF.

  • BV (unregistered)

    Not sure if this is how Java works, but isn't the 7 in the first line declaring the length of the Iselecvariablelst array? Similar to this C code:

    ISelecteVariableProperties Iselecvariablelst[7];

    So he sets up an array with 7 elements (0..6) and then loops over them. No WTF here.

  • WthyrBendragon (cs) in reply to snoofle
    snoofle:
    So we've got 2 rows of 3 rectangles over a larger rectangle, on which a user can click to make something happen. Without context, who knows what this is... or even if its a bad thing. Maybe given context, the meaning of 7 is obvious.

    I suspect the client code iterates through this structure 6 times to acquire the answer to the ultimate question of life, the universe, and everything.

    For those of you who don't already know that would be 42.

    Now, what was the question?

  • RBoy (unregistered)

    This magic number so different and so new

    (Sung without any hint of ill aptent)

  • jk (unregistered)

    hey that is the code i wrote!

  • nasch (unregistered)

    For people defending this, you really wouldn't mind writing this code and leaving it without any comments?

    rect.X = 4+((i-1) % 3)*106;
    rect.Y = 75+((int)((i-1)/3))*60 ;
    

    Six (possibly seven, if you count the 1) undocumented literal numbers in two lines of code? I don't care if it's a UI or a SQL statement or what, that is just terrible. Really, I would be interested in an explanation (if I can remember to come back and check for it) of why this is OK.

  • Mythran (unregistered) in reply to WthyrBendragon
    WthyrBendragon:
    snoofle:
    So we've got 2 rows of 3 rectangles over a larger rectangle, on which a user can click to make something happen. Without context, who knows what this is... or even if its a bad thing. Maybe given context, the meaning of 7 is obvious.

    I suspect the client code iterates through this structure 6 times to acquire the answer to the ultimate question of life, the universe, and everything.

    For those of you who don't already know that would be 42.

    Now, what was the question?

    WTH! Now everybody knows and life, the universe, and everything must come up with a new answer! Thanks a lot.

  • Anon (unregistered)

    Okay so aside from the cryptically named Iselecvariablelst of equally cryptically named interface ISelecteVariableProperties[]. TRWRF is hard-coding the condition in the for loop instead of using Iselecvariablelst.Length.

  • w007 (unregistered) in reply to Steve The Cynic

    or to be precise enum { SEVEN = 11; }

  • whiskeyjack (unregistered) in reply to Bosshog
    Bosshog:
    As I was going to St Ives, I met a man with seven wives. And every wife had seven sacks, and every sack had seven cats. And every cat had seven rats, with tiny little ratty hats. "Turn back!" said he with seven wives: "It is a silly place, St Ives."

    It's just the guy! Dial 555-0001, quick!

  • Harrow (unregistered) in reply to The Nerve
    The Nerve:
    Why not post the code where it sets Iselecvariablelst[7]? That would probably give you some clue what it's supposed to be.
    There is no Iselecvariablelst[7]. There are only 7 "Iselecvariablelst"s, numbered 0 thru 6.

    -Harrow.

  • adunn (unregistered) in reply to nasch
    nasch:
    For people defending this, you really wouldn't mind writing this code and leaving it without any comments?
    rect.X = 4+((i-1) % 3)*106;
    rect.Y = 75+((int)((i-1)/3))*60 ;
    

    Six (possibly seven, if you count the 1) undocumented literal numbers in two lines of code? I don't care if it's a UI or a SQL statement or what, that is just terrible. Really, I would be interested in an explanation (if I can remember to come back and check for it) of why this is OK.

    Because the formula should look familiar to anyone who has ever generated any kind of graphical grid (likely to happen in GUIs). The code should at least be using meaningfully named variables, both for readability and for the likeliness that these number will be reused to line other things up. I don't think the formula needs a comment in the context of a GUI.

    rect.X = offsetX + ((i - 1) % numColumns) * cellWidth;
    rect.Y = offsetY + ((int)((i - 1) / numColumns)) * cellHeight;
    

    Make more sense?

  • Harrow (unregistered) in reply to nasch
    nasch:
    For people defending this, you really wouldn't mind writing this code and leaving it without any comments?
    rect.X = 4+((i-1) % 3)*106;
    rect.Y = 75+((int)((i-1)/3))*60 ;
    

    Six (possibly seven, if you count the 1) undocumented literal numbers in two lines of code? I don't care if it's a UI or a SQL statement or what, that is just terrible. Really, I would be interested in an explanation (if I can remember to come back and check for it) of why this is OK.

    The first line is a scaled sawtooth function, and the second is a scaled step function. Anyone who has done a buttload of two-dimensional layout would instantly recognize these functions. Anyone who has not done a buttload of two-dimensional layout should stay the hell out of this codebase.

    -Harrow.

  • Guardian Bob (unregistered) in reply to nasch

    There's no excuse for not documenting it, which is why I said it needs to be better documented (okay I was a little less forceful than that in my language).

    The code isn't too insane, I mean I ran across this last week:

    int foo(int bar)
    {
      if(some_long_condition(bar))
        return 0;
      return 0;
    }

    The submitted CodeSOD doesn't make me question my own moral and ethical liability if I let the author touch a compiler again. I mean training some to document better isn't as hard as training someone to think about what their doing.

  • Nails (unregistered) in reply to Harrow

    First glance it seemed the functions that the rectangle is being passed to might 'find' buttons that already exist and adding listeners to the controls which would be very WTF, but it could simply be creating them.

    If they were being created then the only reason to layout static controls programatically in C# is to provide something more than what wysiwyg will give you. Either in features or flexibility I don't think this code does either.

    And nasch one thing to remember as far as magic numbers go in GUI code, if you use a wysiwyg editor you get a ton of them in the code behind the scenes and almost any layout code will have to have them. Comments on layout code generally are useless, like '//This makes it look like I want'

    This code is WTFy but it's hard to see how bad without the rest.

  • Fister (unregistered)

    Seems like it creates something like a grid of 3 wide, 2 tall, with a header element, of some kind of control. Could probably be traced to whatever the screen was that ran this code. So, what's the problem? Would you prefer a sequence of seven hard-coded rectangle values?

  • Herby (unregistered)

    Attempted comment WTF'd into spam. This is all I could get.

Leave a comment on “Magic Number 7”

Log In or post as a guest

Replying to comment #:

« Return to Article