- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Did Emil at least hunt down the perpetrator?
Admin
Yes, bad use of magic number:
enum { SEVEN = 7; }
or whatever in your favourite language, is much better!
Admin
enum { THIRTEEN = 7; } FTFY
Admin
Admin
Must not put hand through monitor in attempt to forcibly sterilize coder who wrote that.
Admin
Why not post the code where it sets Iselecvariablelst[7]? That would probably give you some clue what it's supposed to be.
Admin
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.
Admin
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.
Admin
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.
Admin
Hmmm.... couldn't resist, so here's the new values of rect.x and rect.y:
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.
Admin
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.
Admin
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.
Admin
Admin
Setting Iselecvariablelst[7] would raise an array subscript error. Valid subscripts are 0 through 6.
Admin
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
Admin
[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...
Admin
Admin
Admin
Admin
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."
Admin
Admin
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?
Admin
Admin
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.
Admin
Admin
"seralised music" -> I meant 'serail music', of course :o\
Admin
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.
Admin
The real WTF is not using brackets for an if statement.
Admin
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.
Admin
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!
Admin
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.
Could be better documented, but it isn't the worst thing I've seen this week.
Admin
Thanks to Boo Wilbury!
Admin
TRWTF is naming. The first line looks like he's instantiating an interface...
I'm in ur base, Selecing your variablelst.
Admin
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.
Admin
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:
So he sets up an array with 7 elements (0..6) and then loops over them. No WTF here.
Admin
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?
Admin
This magic number so different and so new
(Sung without any hint of ill aptent)
Admin
hey that is the code i wrote!
Admin
For people defending this, you really wouldn't mind writing this code and leaving it without any comments?
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.
Admin
WTH! Now everybody knows and life, the universe, and everything must come up with a new answer! Thanks a lot.
Admin
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.
Admin
or to be precise enum { SEVEN = 11; }
Admin
It's just the guy! Dial 555-0001, quick!
Admin
-Harrow.
Admin
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.
Make more sense?
Admin
-Harrow.
Admin
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:
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.
Admin
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.
Admin
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?
Admin
Attempted comment WTF'd into spam. This is all I could get.