Just found this comment in some code



  • I just found this code:

    // @todo refactor this bullshit

    I agree. The code below was bullshit and needed refactoring. Accurate comment FTW!



  • Like a ninja in the night, Arantor, AKA Arantoro, stalks across SMF campus. The go-to man in the PHP department, he fixes the messes that others leave behind. This is one of his stories.



  • @hungrier said:

    Like a ninja in the night, Arantor, AKA Arantoro, stalks across SMF campus. The go-to man in the PHP department, he fixes the messes that others leave behind. This is one of his stories.

    This one's not even SMF.



  • I think I have better to show you.

    //Why commented the following line? Because it's unsigned integer.
    ...
            // build a large buffer for the moment.
            // definately may need to srink the buffer
    ...
     //this section of code is suspicious. guess it's useless.
    ...
    //The following (mode == 2) seems to be unnecessary and error-prone
    

  • ♿ (Parody)

    @Arantor said:

    This one's not even SMF.

    Front page anonymization doesn't care.



  • I know, but I was being accurate 😛



  • You found my code?!?!?!?!?!!?!



  • I assume most people here are familiar with the "Funny Things Seen In Source Code And Documentation" page at Ward's Wiki? This belongs there. Or maybe just on the Bad Code page.

    The Bad Code page has some truly scary things. A 230 line Java method with a CCM of 150? A 10,000 line C function? A FORTRAN function with 292 parameters? A tortoise playing football? That last is an anomaly, of course.



  • @Arantor said:

    // @todo refactor this bullshit

    So many times I've written that. I don't think I got to refactor once.

    My personal best was creating a resource file for strings at the beginning of a project, scraping up some quick code with <!-- TODO put strings in res file --> at the top, then a week later realizing that I should probably extract half my codebase now.


    Filed under: fuck you, I can read my code



  • @ScholRLEA said:

    A 10,000 line C function?

    That's like, one image exported by GIMP.



  • Another one dredged out of the Bad Code Page:

    I was recently hired by a client to try to optimize a huge VB6
    application. A windows explorer search on all VB source files which can
    contain code (.bas;.cls;*.frm + a couple of more unusual ones) gave me
    20MB!

    One of the VB projects contains 13 classes. A rather small project would
    you think? The file sizes are 2k x 5, 4k x 4, 5k, 6k, 40k and (hold
    your breath) 1,474k!!!

    Aivosto has a nice VB project analyzer, the various reports reveals the following of that giant class:

    • There are 309 dead code related 309 problems, most of them are dead
      variables or variables only written to (how is it even possible?)
    • total logical line count is 29,251 - 8,449 of them are
      comments - 4,252 are white space. You would think well, at least this
      beast is well documented. Dream on! Most of the comments are
      out-commented code which should be removed. The rest is empty function
      headers, wrong function headers, meaningless function headers and
      uninforming block descriptions.
    • 20 public and 303 private procedures. Average size is 92 lines, the largest has 501 lines
    • Half of it has a Cyclomatic Complexity Metric
      from 1 - 5, which isn't bad (I guess), but a third of it ranges from 6 -
      15, while the rest lies between 16 to 51+. This is bad.
    • Max depth of conditional nesting is 16! I am not even attempting to guess what this one does, or should do.
    • 73% has a structural fan-in of 0 - 1, which indicates almost no reuse. This is an achievment in itself.


  • @ScholRLEA said:

    * 73% has a structural fan-in of 0 - 1, which indicates almost no reuse. This is an achievment in itself.

    I should find a tool to measure structural fan-in in the codebase I'm dealing with.



  • @ScholRLEA said:

    40k and (hold your breath) 1,474k!!!

    That finale seems.........underwhelming.



  • @ScholRLEA said:

    Half of it has a Cyclomatic Complexity Metric from 1 - 5, which isn't bad (I guess), but a third of it ranges from 6 - 15, while the rest lies between 16 to 51+. This is bad.

    I hate how often that metric is misused.



  • I dunno, that's a jump of two orders of magnitude. A 1.5M executable is one thing; 1.5M of source code in a single file is something else again. Especially when talking about Visual Basic 6, where source files would often start to get incomprehensible at around the 250 LOC mark. A 29 KLOC class in VB6 is staggering.



  • No, I'm just saying that based on how he chose to label it, it makes it look like it's less. 1.4M might have been better, but it would open us all up to pedantry.



  • @chubertdev said:

    ScholRLEA said:
    Half of it has a Cyclomatic Complexity Metric from 1 - 5, which isn't bad (I guess), but a third of it ranges from 6 - 15, while the rest lies between 16 to 51+. This is bad.

    I hate how often that metric is misused.


    I haven't seen it used much at all, actually, which from what you are saying could be a very good thing or a very, very bad one. I am curious how you've seen it misused, though, so I can be aware of it in the future.

    In this case, though, I think the author only wanted to give a very rough idea of the range of complexity in the code, and how bad it got to in the worst case. I don't know if that constitutes misuse or not, but I would like to hear your opinion.



  • @ScholRLEA said:

    I haven't seen it used much at all, actually, which from what you are saying could be a very good thing or a very, very bad one. I am curious how you've seen it misused, though, so I can be aware of it in the future.

    In this case, though, I think the author only wanted to give a very rough idea of the range of complexity in the code, and how bad it got to in the worst case. I don't know if that constitutes misuse or not, but I would like to hear your opinion.

    A former co-worker (he was pretty much forced out before I left the company) used it as a metric, and pretty much had 500 methods in each class, with no more than 10 lines in each method. He completely missed the point of it.

    I do try to keep things simple, but I draw the limits based on what the code should touch (.NET code shouldn't affect the view, hit the DB, etc), and it should only Do One Thing. So a client-side method to handle the Reply button click should invoke the code to show the window, set the focus, etc.......but not do things like check to see if new replies have been posted, unless that's necessary at that time.

    Basically, the method should do its job, nothing more, where it applies.


  • kills Dumbledore

    @ScholRLEA said:

    CCM of 150

    Contemporary Christian Music?


  • 🚽 Regular

    Completely Clueless Metrics?


  • ♿ (Parody)

    Credence Clearwater Meetup?


  • BINNED

    Customized Cunt Mover?

    Sounds like a hole in the Sex Toy Market ...


  • I survived the hour long Uno hand

    I can't get anyone to care about complexity in any form, let alone what measure we use.



  • @Yamikuronue said:

    I can't get anyone to care about complexity in any form, let alone what measure we use.

    Always the first battle, find people that actually care...


Log in to reply