Unconditionally Useless

  • meow 2012-07-03 15:08
    meow is the meow meow

    yep
  • octavio 2012-07-03 15:18
    These comments are useful. The original programmers realized how hard it would be to figure out which closing brace was for which conditional.
  • Robo 2012-07-03 15:19
    Bah, it makes total sense, they visually created a staircase, and the less likely the condition is, the steeper the slope - brillant!
  • iMalc 2012-07-03 15:24
    // Ffith
    // Forth
    // Thrid
    // Sekond
    // Frist!
  • DCRoss 2012-07-03 15:27
    Looks like they were using the Waterfall model.
  • null 2012-07-03 15:38
    I guess a switch statement was too much trouble...
  • Captain Obvious 2012-07-03 15:43
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional
  • Nagesh 2012-07-03 15:49
    This is very much common scenario for all legacy code. It is intentional on part of author and further succession of developers is also required mandatory to follow same pattern.

  • Nagesh 2012-07-03 16:04
    This ain't much uncomon scenario for scarecrow code. It is intent on part of author and further massage of programer is also required mandatory to massage same patern.
  • J-L 2012-07-03 16:07
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Or you could just not update the comments at all (I have a feeling that updating comments weren't a priority with these programmers), and just let those comments rot away, forever referring to incorrect line numbers.

    At least with your style of comment you can mentally tell which code block is ending without resorting to multiple keyboard presses and mouse clicks.
  • Nagesh 2012-07-03 16:08
    I ain't be massaging multiple keyboards.
  • Coyne 2012-07-03 16:10
    I worked on a program like this once. Around 50 levels of nested IF; nested so deeply that, from time to time, the authors were "out-denting" the code, to keep it from getting indented too much.

    It took weeks to unravel that mess.
  • Recursive Reclusive 2012-07-03 16:11
    J-L:
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Updating what line numbers? The conditional the endbracket is the end of, haven't changed.
  • Rawling 2012-07-03 16:18
    I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.
  • swschrad 2012-07-03 16:29
    it's a gust front in code, leading to a storm of uncontrollable random numbers.
  • Ben L. 2012-07-03 16:42
    TRWTF is the invalid octal number at the end. If you're going to write bad code, at least write syntactically correct comments!
  • PiisAWheeL 2012-07-03 17:02
    I can think of about 3 different ways to write that depending on what the actual necessity of it was... switch, loops, ||...

    Should I consider myself lucky that I have never needed to solve a problem with 26 nested if statements?
  • Sizik 2012-07-03 17:03
    Rawling:
    I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.


    It's probably nested if statements.
  • Christopher P Clark 2012-07-03 17:04
    It's quite beautiful actually
  • AGray 2012-07-03 17:09
    The best part of those closing braces is that they form a (nearly) perfect curve. It's (almost) pleasing to the eye.

    CAPTCHA: laoreet - the next Pokemon!
  • MarkJ 2012-07-03 17:18
    Nagesh:
    I ain't be massaging multiple keyboards.
    You may return to your bridge now.
  • Charles 2012-07-03 17:40
    J-L:
    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.
    You mean your OS2/WARP IDE doesn't do that for you automatically?
  • anony-mouse 2012-07-03 17:42
    Context of this sucks, does the comment above at if block 15 say what the code is for/does?

    Even then, shouldn't you be happy they added those? Yeah all the if blocks suck but at least you have a map.
  • Karel 2012-07-03 18:03
    They probably didn´t have a switch statement at that time.
  • J-L 2012-07-03 18:05
    Recursive Reclusive:
    J-L:
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Updating what line numbers? The conditional the endbracket is the end of, haven't changed.

    Oh, I thought those numbers were line numbers. I can't quite tell for sure, but maybe they're level of nested if-blocks.

    At any rate, if someone decides to add another nested if-block somewhere in the middle, then they'll be stuck with updating all the numbers inside the new one.

    Or not. They could just put a new number (greater than the others) and allow the nested blocks to simply degrade into no particular order.
  • Kasper 2012-07-03 18:07
    Rawling:
    I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.
    My thought exactly. A sequence like
    if (var == 1) {
    
    } else if (var == 2) {
    } else if (var == 3) {
    Would only be a minor WTF in a language supporting a switch statement. But let's assume this is a company that has a coding standard, and that coding standard requires the use of a compound statement after an if and after an else to avoid cases where you accidentally have a conditional not covering exactly what you expected it to. In other words constructions like
    if (x==1)
    
    y=2
    else
    y=10;
    might have been banned in favor of constructions like:
    if (x==1) {
    
    y=2;
    } else {
    y=10;
    }
    This is a sensible requirement in many cases. However if it is applied to else if constructions it becomes ugly. If you apply this coding standard to the above sequence of else if statements you get
    if (var == 1) {
    
    } else {
    if (var == 2) {
    } else {
    if (var == 3) {
    } // if (var == 3)
    } // if (var == 2) { } else {
    } // if (var == 1) { } else {


    Commenting close brackets can be a good idea in some cases. If you do so, then indicate what sort of block you are closing. The comment is supposed to help not confuse even further. And such comments are mostly useful at the end of a long block.
    while (something_to_do) {
    
    for (i=0; i<10 ; ++i) {
    if (i == 5) {
    // Code here
    } else {
    // More code here
    } // if (i == 5) { } else
    } // for (i=0; i<10; ++i)
    } // while (something_to_do)
  • Jack 2012-07-03 18:11
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.
  • Recursive Reclusive 2012-07-03 18:39
    J-L:
    Recursive Reclusive:
    J-L:
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Updating what line numbers? The conditional the endbracket is the end of, haven't changed.

    Oh, I thought those numbers were line numbers. I can't quite tell for sure, but maybe they're level of nested if-blocks.

    I don't really know what the comments in the original code whas supposed to be, but the suggestion from Captain Obvious was along these lines:

    if (irish_girl) {
    if (paula) {
    if (!frist) {
    WTF
    WTF
    WTF
    WTF
    WTF
    WTF
    WTF
    } // endif !frist
    } // endif paula
    } // endif irish_girl

    If your nested blocks gets longer than a page (I know the shouldn't, but sometimes...) this is actually a good way to make the code more readable.
  • dogmatic 2012-07-03 18:57
    You see? This is why java needs case switch statements for strings!
  • Nobody in particular 2012-07-03 21:34
    Rawling:
    I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.


    They do if you're anal about bracing everything:

    if(foo){
    
    bar;
    }else{
    if(baz){
    qux;
    }else{
    if(quux){
    etc;
    }
    }
    }


    Technically,
    else if
    is a "one-line" unbraced else.
  • Muwaah 2012-07-04 00:28
    I want to see the code around it. What is it supposed to do? The number 26 makes me think it has something to do with alphabetizing, but the "09" at the bottom REALLY makes me wonder.
  • Federico 2012-07-04 02:45
    Now that's a bad case of else-if-heimer.
  • Severity One 2012-07-04 02:53
    This is all nonsense. The following is perfectly valid C:
    if (1) {
    
    if (2) {
    if (3) {
    if (4) {
    /* ... */
    } /* end if 4 */
    } /* end if 3 */
    } /* end if 2 */
    } /* end if 1 */


    OK, so it's not perfectly useful C, but that's really a triviality.
  • Steve The Cynic 2012-07-04 03:07
    I think the story's title, "Unconditionally Useless", is intended as a predictive description of the majority of the comments...
  • Guran 2012-07-04 03:22
    OK, just to point out the obvious here:

    Commenting close brackets helps. Esp if the function is long. Yes the en-brackened code should not span a hundred lines, but we all know that happens, and if you at least made some decent comments, refactoring your mess becomes easier.

    But, as usual, these comments should be a direct translation of the code they are commenting. ( i = 1; //set i to one)

    if you do something like this

    if (i > 5) // explanation of why the first five are special
    {
    //long messy code here
    }
    else // we are no longer in the special case
    {
    //more messy code here
    }


    You might still have written crap code, but at least cleanable crap. Big difference.
  • TheSHEEEP 2012-07-04 03:37
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.


    The good thing is, though, that we don't need three years to master a 100% unintuitive writing system to write code faster than in normal IDEs.

    And besides, every useful IDE can do what you just described in few keystrokes.
  • Your Name 2012-07-04 04:29
    J-L:
    Recursive Reclusive:
    J-L:
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Updating what line numbers? The conditional the endbracket is the end of, haven't changed.

    Oh, I thought those numbers were line numbers. I can't quite tell for sure, but maybe they're level of nested if-blocks.

    At any rate, if someone decides to add another nested if-block somewhere in the middle, then they'll be stuck with updating all the numbers inside the new one.

    Or not. They could just put a new number (greater than the others) and allow the nested blocks to simply degrade into no particular order.


    It's not an unsolvable problem, is it?


    } // else if 17
    } //else if 16.75
    } //else if 16.5
    } //else if 16


    That's the beauty of this approach. If used correctly, you will never run out of numbers (in the correct order) for your blocks.
  • Honnza 2012-07-04 05:07
    Your Name:
    J-L:
    Recursive Reclusive:
    J-L:
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Updating what line numbers? The conditional the endbracket is the end of, haven't changed.

    Oh, I thought those numbers were line numbers. I can't quite tell for sure, but maybe they're level of nested if-blocks.

    At any rate, if someone decides to add another nested if-block somewhere in the middle, then they'll be stuck with updating all the numbers inside the new one.

    Or not. They could just put a new number (greater than the others) and allow the nested blocks to simply degrade into no particular order.


    It's not an unsolvable problem, is it?


    } // else if 17
    } //else if 16.75
    } //else if 16.5
    } //else if 16


    That's the beauty of this approach. If used correctly, you will never run out of numbers (in the correct order) for your blocks.


    In that case, I suggest octal:

    } // else if 17
    } // else if 16.6
    } // else if 16.4
    } // else if 16.2
    } // else if 16


    captcha: ACSI - any strict subset of ASCII, jumbled (such as EBC-DIC).
  • dkf 2012-07-04 05:31
    An indentation level of (at least) 19? Refactor it from orbit, it's the only way to be sure.
  • Mike 2012-07-04 06:12
    It looks like a clumsy fudge to compensate for the bad tooling of the day.
  • Cbuttius 2012-07-04 06:13
    It reminds you how many more braces you need to close.

    I came across bunches of nested-ifs when writing in C and you have to check the return value of every function call you make. Not sure it came to as many as 26 but certainly can get to 5 or 6.

    At each stage though the else would handle what failed and you would possibly need to clean-up the last thing that was properly allocated (the hidden "finally") after the if..else block.

    C++ is so much nicer for this.
  • RandomGuy 2012-07-04 06:42
    Maybe it was the frist version of this earlier WTF.


    if(r == "IX") {
    r = "9";
    } else {
    if(r=="X") {
    r = "10";
    } else {
    if(r=="XI") {
    // etc.
    } //if 11
    } // else if 10
    } else if 09

  • Annon Too 2012-07-04 07:09
    Right. Who's for just ripping it out and seeing what breaks? Anyone? Just me then?

    I'd say a refactoring is in order here.
  • Najeff 2012-07-04 07:49
    TheSHEEEP:
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.


    The good thing is, though, that we don't need three years to master a 100% unintuitive writing system
    Don't be ridiculous! I've been using vi for 28 years and I still haven't mastered it.
  • TGV 2012-07-04 07:56
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.

    Cry for me. I am an emacs user, where it takes one keystroke, not two, and where you can also jump to the enclosing brace with a single keystroke, not to mention differentiate an expression with 4.

    Have pity!
  • F 2012-07-04 09:06
    TGV:
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.

    Cry for me. I am an emacs user, where it takes one keystroke, not two, and where you can also jump to the enclosing brace with a single keystroke, not to mention differentiate an expression with 4.

    Have pity!


    I'm waiting for the editor that takes no keystrokes to do anything. Whoever is supposed to be producing it is certainly taking his time, and I wish he'd get a move on - I have stuff to get done.
  • no laughing matter 2012-07-04 09:24
    dogmatic:
    You see? This is why java needs case switch statements for strings!

    The current java does have Strings in switch-statements.

    Degrading one step further down to PHP in every new release...
  • no laughing matter 2012-07-04 09:31
    no laughing matter:
    dogmatic:
    You see? This is why java needs case switch statements for strings!

    The current java does have Strings in switch-statements.

    Degrading one step further down to PHP in every new release...

    UPDATE: The example in chapter "Using Strings in switch Statements" is an epic fail of indeed nearly PHP-like dimensions.

    String.toLowerCase() uses the rules of the default locale. So set default locale to "tr TR" and test with:

    month="APRIL";

  • RandomGuy 2012-07-04 09:49
    F:
    TGV:
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.

    Cry for me. I am an emacs user, where it takes one keystroke, not two, and where you can also jump to the enclosing brace with a single keystroke, not to mention differentiate an expression with 4.

    Have pity!


    I'm waiting for the editor that takes no keystrokes to do anything. Whoever is supposed to be producing it is certainly taking his time, and I wish he'd get a move on - I have stuff to get done.


    This cries for the obligatory XKCD.
  • C-Octothorpe 2012-07-04 09:49
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional
    Protip: if you're doing it this way, you're doing something wrong...
  • notchulance 2012-07-04 10:07
    Oh nooo, brace yourselves..
    :)
    Special significance of the number 26 anyone?
    Zero padding?

    That's right folks, they were switching on letters, and decided to use string versions of numbers to represent that.
    Please post the rest of the code..
  • PiisAWheeL 2012-07-04 11:32
    J-L:
    Recursive Reclusive:
    J-L:
    Captain Obvious:
    Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional

    It would be easy to find until the day you decide to add some lines of code above the first condition. Then you'll be stuck updating all those line numbers.

    Updating what line numbers? The conditional the endbracket is the end of, haven't changed.

    Oh, I thought those numbers were line numbers. I can't quite tell for sure, but maybe they're level of nested if-blocks.

    At any rate, if someone decides to add another nested if-block somewhere in the middle, then they'll be stuck with updating all the numbers inside the new one.

    Or not. They could just put a new number (greater than the others) and allow the nested blocks to simply degrade into no particular order.
    Wow... Thats a terrible idea. For suggesting something so terrible, go home and sit in a corner and think about what you've done.
  • Yazeran 2012-07-04 13:13
    Rawling:
    I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.


    Yep, but you might have a lot of nested

    if (foo)
    {
    * branch 1 *
    }
    elseif (bar)
    {
    * branch 2 *
    } // end elseif


    Which incidently just makes the code even MORE of a WTF
    (My brain hurts just thinking about that possible monstrosity)

    Yazeran

    Plan: To go ot mars one day with a hammer
  • mightybaldking 2012-07-04 13:18
    Wrap that in a for loop and you'd have something.
  • @Deprecated 2012-07-04 13:50
    Severity One:
    This is all nonsense. The following is perfectly valid C:
    if (1) {
    
    if (2) {
    if (3) {
    if (4) {
    /* ... */
    } /* end if 4 */
    } /* end if 3 */
    } /* end if 2 */
    } /* end if 1 */


    OK, so it's not perfectly useful C, but that's really a triviality.



    This is what the official Amiga programming examples looked like, back in 1990 or so.

    EG.,

    resource_1 = allocate_resource();
    if (resource_1)
    {
    initialize(resource_1);
    resource_2 = allocate_resource(resource1);
    if (resource_2)
    {
    initialize(resource_2);
    etc...

    destroy(resource_2);
    }
    destroy(resource_1);
    }

    where resource_1 might be memory, resource_2 is a bitplane based on resource 1, resource 3 is a viewport, etc...

    And that was back when monitors were substantially less than 1920 pixels wide.
  • Lost (inthe spaghetti) 2012-07-04 17:10
    Rawling:
    I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.


    I imagine it is something like the following:

    if($somevar == "something") {
    if($somevar2 == $somevar3) {
    if($somevar3 == "someplace") {
    if($somevar4 == "someone") {
    if($somevar5 == "somethingelse") {
    doSomething();
    } // end if 5
    else { // begin else if 5
    doSomethingElse();
    } // end else if 5
    else { // begin else if 4
    doSomethingTotallyDifferent();
    } // end else if 4
    } // end if 3
    } // end if 2
    } // end if 1


    Are your eyes starting to bleed yet?

    Ooh, and about the "line number" changing when adding code, it would only happen if some 'programmer' would incorporate a new root level if / else statement.... And that person should have at last 6 of his fingers cut off...
  • Gert 2012-07-04 22:50
    You're such a massive idiot
  • Gert 2012-07-04 22:51
    Nagesh:
    This is very much common scenario for all legacy code. It is intentional on part of author and further succession of developers is also required mandatory to follow same pattern.



    You're an idiot of epic proportions
  • Steve The Cynic 2012-07-05 05:57
    Lost (inthe spaghetti):
    Ooh, and about the "line number" changing when adding code, it would only happen if some 'programmer' would incorporate a new root level if / else statement.... And that person should have at last 6 of his fingers cut off...

    I'd recommend 11 fingers, counting both thumbs and the big finger located on top of his torso, between his shoulders. I believe it's often called a "head".
  • My Name 2012-07-05 06:54
    Steve The Cynic:
    Lost (inthe spaghetti):
    Ooh, and about the "line number" changing when adding code, it would only happen if some 'programmer' would incorporate a new root level if / else statement.... And that person should have at last 6 of his fingers cut off...

    I'd recommend 11 fingers, counting both thumbs and the big finger located on top of his torso, between his shoulders. I believe it's often called a "head".

    You think someone like that can be stopped just by cutting off their head??
  • KEYSTROKE_NOT_FOUND 2012-07-05 07:21
    F:
    TGV:
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.

    Cry for me. I am an emacs user, where it takes one keystroke, not two, and where you can also jump to the enclosing brace with a single keystroke, not to mention differentiate an expression with 4.

    Have pity!


    I'm waiting for the editor that takes no keystrokes to do anything. Whoever is supposed to be producing it is certainly taking his time, and I wish he'd get a move on - I have stuff to get done.


    KEYSTROKE_NOT_FOUND

  • Steve The Cynic 2012-07-05 07:49
    My Name:
    Steve The Cynic:
    Lost (inthe spaghetti):
    Ooh, and about the "line number" changing when adding code, it would only happen if some 'programmer' would incorporate a new root level if / else statement.... And that person should have at last 6 of his fingers cut off...

    I'd recommend 11 fingers, counting both thumbs and the big finger located on top of his torso, between his shoulders. I believe it's often called a "head".

    You think someone like that can be stopped just by cutting off their head??

    No, but at least then everyone around him would know that there is something wrong. What would you do if you found that there was a headless guy bashing on the keyboard with fingerless hands?

    (OK, yes, if he was the sort of person who produced this kind of mess, you probably wouldn't notice much change...)
  • Joe 2012-07-05 07:52
    Kasper:
    while (something_to_do) {
    
    for (i=0; i<10 ; ++i) {
    if (i == 5) {
    // Code here
    } else {
    // More code here
    } // if (i == 5) { } else
    } // for (i=0; i<10; ++i)
    } // while (something_to_do)

    Except that we all know how it will end up looking:
    while (something_to_do) {
    
    for (i=0; i<8 ; --i) {
    if (frobnicate == FILE_NOT_FOUND) {
    // Code here
    } else {
    // More code here
    } // if (i == 5) { } else
    } // for (i=0; i<10; ++i)
    } // while (something_to_do) -- This shoudl never hapen.

    --Joe
  • PedanticCurmudgeon 2012-07-05 08:26
    Guran:
    But, as usual, these comments should be a direct translation of the code they are commenting. ( i = 1; //set i to one)
    Can't tell if trolling or...
  • Captcha:enim 2012-07-05 08:35
    PedanticCurmudgeon:
    Guran:
    But, as usual, these comments should be a direct translation of the code they are commenting. ( i = 1; //set i to one)
    Can't tell if trolling or...

    I think he just missed a "not".
  • Anonymous Coward 2012-07-05 08:40
    F:
    TGV:
    Jack:
    I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.

    Cry for me. I am an emacs user, where it takes one keystroke, not two, and where you can also jump to the enclosing brace with a single keystroke, not to mention differentiate an expression with 4.

    Have pity!


    I'm waiting for the editor that takes no keystrokes to do anything. Whoever is supposed to be producing it is certainly taking his time, and I wish he'd get a move on - I have stuff to get done.


    Sorry it is taking so long, every time I go to test the editor I take my hands off the keyboard and wait for it to do what I want. Bootstraping the editor in self-same editor is a slow process. So far the editor has managed to write 0 lines of its own code... May take some time.
  • Nagesh 2012-07-05 08:59
    MarkJ:
    Nagesh:
    I ain't be massaging multiple keyboards.
    You may return to your bridge now.

    Ain't be played bridge. Prefer physical sports as in cricket.
  • Guran 2012-07-05 09:01
    Captcha:enim:
    PedanticCurmudgeon:
    Guran:
    But, as usual, these comments should be a direct translation of the code they are commenting. ( i = 1; //set i to one)
    Can't tell if trolling or...

    I think he just missed a "not".


    Yup. Sorry.
  • Nagesh 2012-07-05 09:01
    Gert:
    Nagesh:
    This is very much common scenario for all legacy code. It is intentional on part of author and further succession of developers is also required mandatory to follow same pattern.



    You're an idiot of epic proportions

    Ain't be a h8r.
  • Scrummy 2012-07-05 09:48
    This makes as strong a case for paired programming as I've ever seen. It's hard to justify a litany of useless comments when your partner stops you after the first and asks, "WTF are you doing that for?"
  • Nagesh 2012-07-05 10:30
    Scrummy:
    This makes as strong a case for paired programming as I've ever seen. It's hard to justify a litany of useless comments when your partner stops you after the first and asks, "WTF are you doing that for?"

    Ain't will work when both partner are scarecrows.
  • PiisAWheeL 2012-07-05 10:40
    Gert:
    Nagesh:
    This is very much common scenario for all legacy code. It is intentional on part of author and further succession of developers is also required mandatory to follow same pattern.



    You're an idiot of epic proportions
    You must be new here.
  • PedanticCurmudgeon 2012-07-05 10:44
    Nagesh:
    Scrummy:
    This makes as strong a case for paired programming as I've ever seen. It's hard to justify a litany of useless comments when your partner stops you after the first and asks, "WTF are you doing that for?"

    Ain't will work when both partner are scarecrows.
    You used the word "scarecrow" correctly. That sets a bad precedent.
  • Chelloveck 2012-07-05 10:59
    dkf:
    An indentation level of (at least) 19? Refactor it from orbit, it's the only way to be sure.


    I wish I had code from one place I worked. A block of supposedly C++ code (well, we were using a C++ compiler, anyway) was deeply nested. How deep? I set my editor's indent spacing to 1 and reformatted it. On my 80-column display, I couldn't see the start of the text in the innermost block. Nested more than 80 levels deep, baby! Now that's manly-man code!
  • Sir Twist 2012-07-05 11:01
    This is the kind of shit that happens when you blindly follow both “single exit” and the mistaken belief that “goto considered harmful” means “don’t use goto, ever.”
  • dogmatic 2012-07-05 15:04
    Nagesh:
    Scrummy:
    This makes as strong a case for paired programming as I've ever seen. It's hard to justify a litany of useless comments when your partner stops you after the first and asks, "WTF are you doing that for?"

    Ain't will work when both partner are scarecrows.


    TROLLFIGHT!!!
  • sinrtb 2012-07-05 19:11
    Before fancy code highlighting and intellisense sometimes matching braces were not highlighted or given any indication of there match (even today if your brace is more than a page back). what probably happened is during a build there was an error or a bug during testing that all came down to one missing brace or an extra brace, he commented the braces to make find the missing one, and just never bothered to remove the comments.
  • quis 2012-07-06 12:51
    Completely legal code to me and a very useful habit. Picture this: You have this nested if-else-construct and each block has 20+ lines. It's very easy to loose track of which block is now closed by a bracket.
  • dogmatic 2012-07-06 13:17
    quis:
    Completely legal code to me and a very useful habit. Picture this: You have this nested if-else-construct and each block has 20+ lines. It's very easy to loose track of which block is now closed by a bracket.


    There is no method to this madness.
  • unknown 2012-07-07 04:52
    I am new to this site, with issues such as this are we allowed to offer ot look at source for the writer? I am usually goot at tracking sources of data etc.
  • big picture thinker 2012-07-09 09:26
    These are the people that think it's bad practice to use "return" as a logic controller eg:

    if(!x)
    return;
    if(!y)
    return;
    if(z)
    return;
    //do something here

    Rather than:
    if(x)
    {
    if(y)
    {
    if(z)
    {
    //do something here
    }
    }
    }
  • The Great Lobachevsky 2012-07-09 10:11
    Gert, spend some more time here - Nagesh posts are meant to be humourous. The actual registered Nagesh usually is. The unregistered fakes are usually not even close.
  • Paresh 2012-07-09 20:33
    Thats it people getting worked up over 26 nests? I've made deeper nets.

    To keep track though you should add

    Log('entering if #53');

    For each net. Lot easier to debug then step'en through.

    One more thing.... R'nt u writing code using a language then why leave comments in a different language? It just give people who don't know the programming language a chance to break code they can under stand. The compiler won't do what's int the comments but it will always do what's in the code. Developers should spend more time on getting code right and less time formatting comments to bad code tree paths.

    I'm serious about the log() part though.
  • Paresh 2012-07-09 20:49
    0-8 is not there so what's to say it stops at 26?

    What if it goes like this

    If (var >= 1 ){
    Print( "one" )
    If ( var >= 2 ){
    Print("two")
    ...
    If(var >= 1024){
    Print("thousand twenty four")
    }//end 1024
    ...
    }// end 2
    }//end 1


    The program output could be

    Enter a number between 0-1024: 3
    You entered 3: here are the words for each number
    One
    Two
    Three
    Can say each number?

    Could a cool kids learning app.

    Oh they were called applications I guess.
  • HappyGod 2012-07-16 04:27
    So many people commenting on this really scare me. Mostly cause one day, I'm going to have to maintain their code!

    Comments like this are *never* a good idea. I don't care about your coding standards. Don't do it. For the love of God, don't do it!

    * Forget the single-exit crap, and have logic gates, so you don't have nested if statements that look like abstract art.
    * Comments that refer to line numbers (???!) or magic numbers are asking for trouble.

    And while I'm on comments

    <rant>
    <strong>

    Comments are the work of the antichrist. The only time you should ever use a comment is to explain *why* you are doing something. But never *how* you are doing it.

    If you have to write a comment that explains how you're doing something, then you have either written some terrible code, or you are insulting the intelligence of the developer who follows you.

    Sadly, I have to adhere to some pretty rubbish code standards here, and they enforce mandatory comments on public methods. So I have to resort to such insanity as:

    /// <summary>
    /// Gets the username for a user by id
    /// </summary>
    /// <param name="userId">The user id</param>
    /// <returns>The username for the user</returns>
    public string GetUsernameForUserById(int userId)
    {
    var username = <code that gets the username>;
    return username;
    }

    This comment is worse than a waste of time. It's a liability! Not only does it not tell you anything you couldn't have gotten from the method signature, but the second it was written, the comment started becoming stale. Waiting patiently for the day when someone refactors the method without updating the comment.

    </strong>
    </rant>
  • Danielle 2012-07-17 13:56
    I submitted this code.

    It is 26 (and more) nested if

    And sadly, instead of putting comments like those:

    } //endif (Condition bla bla bla)

    They actually put those coments

    } // else if 25
  • Anone 2012-11-08 00:20
    Paresh:

    If(var >= 1024){
    Print("thousand twenty four")
    }//end 1024


    One thousand and twenty-four.