Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Coding Horror

1679111237

Comments

  • Registered Users Posts: 1,889 ✭✭✭evercloserunion


    Without PHP you wouldn't have anywhere to write that post, lets leave the language wars for another thread?
    I agree about leaving the language wars to another thread, but it's hardly the case that if PHP did not exist nobody would write online forums.


  • Closed Accounts Posts: 3,609 ✭✭✭Boards.ie: Danny


    That's not what I was implying at all. My point was (and is) that for 12 years now boards has been running on PHP, clearly it's not all a coding horror.

    But again, this begins to fall into a language debate so I'll bow out of this discussion :)


  • Administrators Posts: 53,125 Admin ✭✭✭✭✭awec


    People who write:
    if(var == true) { return true; } else { return false; }
    

    should have their nipples wired to an electric fence.

    I've also recently seen:
    public string MyFunc()
    {
        try
        {
             DoWork();
             return "success";
        }
        catch(Exception e)
        {
            return e.Message;
        }
    }
    
    and then with a nice:
    
    if MyFunc == "success"
    


    Le sigh....


  • Registered Users Posts: 2,003 ✭✭✭Colonel Panic


    Big time. Another one is functions/methods that return a boolean for success that look like this
    bool GodClass::MakeTheMagicHappen() 
    { 
    	/* loads of stuff with no error checking or exception handling */ 
    	return true; 
    }
    

    Except marks when the function takes no params and touches lots of member variables and a couple of globals too.


  • Closed Accounts Posts: 2,930 ✭✭✭COYW


    awec wrote: »
    People who write:
    if(var == true) { return true; } else { return false; }
    

    should have their nipples wired to an electric fence.

    That is an absolute belter, I have to admit. I just finished on the most demoralizing project ever. Stuck with a lead who only ever learned .Net 2.0 and thinks all future frameworks, generics, programming against interfaces and LINQ are "a load of sh1te". They were Agile too, meaning that they documented nothing. I was told not to comment my code, as it was a "waste of time". Apparently, that is classic Agile!


  • Advertisement
  • Registered Users Posts: 7,157 ✭✭✭srsly78


    COYW wrote: »
    Apparently, that is classic Agile!

    I'm glad it has a name.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    COYW wrote: »
    I was told not to comment my code, as it was a "waste of time". Apparently, that is classic Agile!

    Hide the simplest of error with a code segment and send him on a goose chase. Drive commenting into him!


  • Registered Users Posts: 40,055 ✭✭✭✭Sparks


    COYW wrote: »
    They were Agile too, meaning that they documented nothing.
    If I ever go postal, I suspect that this may well play a major role in why.

    ObHorror from my past, paraphrased for NDA reasons:
    ...
    // Using if/then here instead of switch as it's more efficient
    if () 
    {
    ...
    } 
    else if ()
    {
    ...
    }
    else if ()
    ...[b][i]repeats for approximately 14,000 lines of code[/b][/i]...
    

    Not a typo. Fourteen Thousand Lines in an if/then/else structure, done because an earlier programmer thought that that was more efficient than switch().

    There wasn't a brick in a sock large enough to beat them with...


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,537 Mod ✭✭✭✭Capt'n Midnight


    Sparks wrote: »
    Not a typo. Fourteen Thousand Lines in an if/then/else structure, done because an earlier programmer thought that that was more efficient than switch().

    There wasn't a brick in a sock large enough to beat them with...
    I had to change a switch to nested if

    But that was in Power Basic back in 1990 and needed to run on an 8MHz 8086.


  • Registered Users Posts: 40,055 ✭✭✭✭Sparks


    I had to change a switch to nested if
    But that was in Power Basic back in 1990 and needed to run on an 8MHz 8086.
    BASIC?

    #define ALLBETS 0 /* :D */

    But my horror was in C++ (well, C---- really)


  • Advertisement
  • Registered Users Posts: 1,529 ✭✭✭zynaps


    Sparks wrote: »
    BASIC?

    #define ALLBETS 0 /* :D */
    Most (structured) Basics I encountered were awesome... at least, from the perspective of someone coming directly from C64 Basic, which was horrendous... Only the first two letters of variable names were considered, line numbers were mandatory and there was no auto-renumber function, so you had to space the numbers in increments that were proportional to your uncertainty about how much various sections of code would need refactoring or expansion later...

    And even that was probably a big improvement to writing in assembly on a cassette tape based system with the most rudimentary editor (or "monitor").

    The most arbitrary disappointing experiences were when you typed in a "Basic" program from a magazine listing, which was actually just a small for loop which would read bytes from the data section and poke them into memory. The bytes were machine code opcodes, so you might have to type in 10 or 20 lines of these numbers, and you just knew it wasn't going to work, because a single error would almost certainly ruin the whole thing.
    The ~30% of the time that you managed to do it without making an error or giving up halfway through, the program would be rubbish anyway and the only enjoyment would be a kind of "I escaped from prison with a toothpick and it only took 35 years" grim satisfaction... :D


  • Registered Users Posts: 7,515 ✭✭✭matrim


    Was looking through some of our old libraries (which are still used for some core stuff) today and behind the scenes had what was basically a factory called farm, which created objects called moo_cow, with no comments or explaination of what either did.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,537 Mod ✭✭✭✭Capt'n Midnight


    zynaps wrote: »
    Most (structured) Basics I encountered were awesome...
    Know someone who had to program in BASIC , but space was limited. So no REM statements, liberal use of : to put as many statements on a single line as possible to save space - printouts would have been a wall of text.


  • Registered Users Posts: 26,960 ✭✭✭✭GreeBo


    a class called
    NumericConstants.java
    containg over 100 definitions similar to
    /*
    * Constant for one hundred
    */
    public static final int ONE_HUNDRED = 100;
    /*
    * Constant for one hundred twelve
    */
    public static final int ONE_HUNDRED_TWELVE = 112;

    Thank heavens for the comments or it would have been so confusing.

    /edit now that I think about it, Im not even sure they were final...


  • Closed Accounts Posts: 503 ✭✭✭Boards.ie: Neil


    another beauty courtesy of vbulletin...

    ever wonder how those stars to the <<< left are calculated?

    [php]
    for ($x = $rank; $x--; $x > 0)
    {
    if (empty($rank))
    {
    $userrank .= "<img src=\"http://b-static.net/vbulletin/$rank\" alt=\"\" border=\"\" />";
    }
    else
    {
    $userrank .= 'http://b-static.net/vbulletin/' . $rank;
    }
    }
    [/php]

    and where is this string of html used you say? oh yes it's inserted into the database...


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    COYW wrote: »
    [..] I was told not to comment my code, as it was a "waste of time". Apparently, that is classic Agile!

    A good code doesn't need comments; a bad code doesn't need comments either - it needs to be fixed! ;)


  • Registered Users Posts: 40,055 ✭✭✭✭Sparks


    PrzemoF wrote: »
    A good code doesn't need comments; a bad code doesn't need comments either - it needs to be fixed! ;)

    Hm. Even in jest, that brings my need to strangle to the fore...


  • Registered Users Posts: 2,003 ✭✭✭Colonel Panic


    I don't know how I feel about comments. I mostly use C and C++ and think of header files as de facto documentation of code, albeit documentation that relies heavily on the actual quality of the code itself, I must admit.

    I find that Doxygen comments in headers (or worse still, some custom nonsense with lots of ascii formatting) just ends up being noise. Especially when it's superfluous stuff telling me what the function definition already tells me in less text.

    Where I like to see comments is in the actual implementations where sometimes the motivation of the developer might not be clear. Be it some sort of optimisation, an apology to other developers or perhaps a reference to where that piece of code is used.

    Where I do use comments in headers is to basically say a little about the basic usage of the code defined in the file, any potential side effects, references to dependencies, comments about compiler flags, hacks or future work etc.

    An example I found a couple of days ago is in RIM's Gameplay framework for cross platform game dev. IMO, it's a pretty solid framework. Well written with APIs that make sense, but look at all the noise in this file...

    https://github.com/blackberry/GamePlay/blob/master/gameplay/src/Game.h

    If you took out the comments, the whole thing would be more compact and make just as much sense! Hell, some of the functions have params that need explaining in the comments but they aren't mentioned! RenderOnce takes a void pointer param called cookie. What is that for? Better look at the implementation...

    Now, I recognise that this is more for the benefit of tools that generate documentation, but the cost is pretty high imo!


  • Registered Users Posts: 40,055 ✭✭✭✭Sparks


    It's a matter of degree; if I saw, say:
    int i; // Declare variable i
    i = 0; //Define variable i
    i++; //Increment variable i
    
    Then that'd set off some alarms and I'd wind up reading that person's code very carefully for mistakes.

    If, on the other hand, I see ten lines of dense code without a single comment giving an overview, I'm going to refuse to pass it through code review. It might be obvious to the coder today what they meant; in a month's time, they may not remember; when some other poor schmuck has to debug it in two years time, the original coder may not even be with the company anymore. One line of comment saying "here we do X" is not onerous, and it's the easiest line to write.

    edit: Here's a quick test for you; go back to code you wrote ten years ago (you still have your code from college exercises, right? No? You don't keep a private archive of old code you wrote? So... how do you tell if you're improving or getting worse without a baseline?). Now, see if you can read it in one pass and understand what it was doing. That's a pretty object lesson right there.

    And if someone does something for optimisation reasons and doesn't have comments in the code stating what they're doing, and what they're assuming when doing it, then someone's getting the engineering version of a kick in the fork for being the person that keeps someone else working till 0200 on a weekend instead of sleeping/eating/playing with their kids.

    Comments are the bit in the code that says "not only can I code, but I'm professional enough to realise that I work with other peons". Not commenting appropriately is just downright obnoxious...


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Sparks wrote: »
    It's a matter of degree; if I saw, say:

    If, on the other hand, I see ten lines of dense code without a single comment giving an overview, I'm going to refuse to pass it through code review. It might be obvious to the coder today what they meant; in a month's time, they may not remember; when some other poor schmuck has to debug it in two years time, the original coder may not even be with the company anymore. One line of comment saying "here we do X" is not onerous, and it's the easiest line to write.
    ...
    Not commenting appropriately is just downright obnoxious...

    +Infinity squared, your code could be present in the code base of the company for years and the maintainer of your code may be under pressure to resolve an issue that your code touches, clear explanation of what you think your code is doing is essential for maintainability.


  • Advertisement
  • Closed Accounts Posts: 2,930 ✭✭✭COYW


    PrzemoF wrote: »
    A good code doesn't need comments; a bad code doesn't need comments either - it needs to be fixed! ;)

    I presume this is a joke, so I will. :D


  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    PrzemoF wrote: »
    A good code doesn't need comments; a bad code doesn't need comments either - it needs to be fixed! ;)


    Do you work as a Developer ?

    Maybe you worked with Mircosoft for the Vista OS !!! yeah that could be it,

    All Code needs to be Commented on, What if i Wrote about 500 lines of Code in C, and 4 years later some one comes in to update some of the code, how is he meant to know what section of Code does what ?

    Thats where Commments come into play, every program i do, i have about 3 lines of Comment over every Method/Function telling what its doing and where its pointing to if i was using Pointers or Abstract Coding in Java.


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    Cork24 wrote: »
    Do you work as a Developer ?

    Maybe you worked with Mircosoft for the Vista OS !!! yeah that could be it,

    All Code needs to be Commented on, What if i Wrote about 500 lines of Code in C, and 4 years later some one comes in to update some of the code, how is he meant to know what section of Code does what ?

    Thats where Commments come into play, every program i do, i have about 3 lines of Comment over every Method/Function telling what its doing and where its pointing to if i was using Pointers or Abstract Coding in Java.

    I do not, however some of my patches landed in the linux kernel (check my boards public profile and then search for commits signed with the same server name as my home page if you want to check their quality). I treat suggestion that I worked for MS as an insult ;)

    I prefer good procedure/function/variable names then something like (commented!):
    int lo; /* this is main counter*/

    Anyway, my post about good code/bad code was a JOKE! :D

    Some really funny comments


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    I got some good ones from a makefile:

    ## What is truth?
    ! := :
    !no := :
    yes := :


  • Registered Users Posts: 9,555 ✭✭✭DublinWriter


    Pseudo-code:

    function is_pc_switched_on (boolean)

    return true;


  • Registered Users Posts: 2,144 ✭✭✭dazberry


            Try
                m_bIndexing = configReader.GetValue("Indexing", GetType(Boolean))
            Catch ex As Exception
                m_bIndexing = True
            End Try
    
            If Not m_bIndexing Then
                mnuSeparator.Visible = False
                mnuSearch.Visible = False
            End If
    

    I don't know which annoys me more:
    • the fact that it's in vb.net
    • the fact that m_bIndexing is declared as a field in the form class and used only in one place (as shown)
    • the fact that the configReader.GetValue() pattern is repeated f**king everywhere in the project, including for the "Index" value again...
    • the fact that m_bIndexing is assigned true when declared, so the assignment in the exception handler is pointless
    • the If Not m_bIndexing .... = False
    • the fact that all the code is like this... muck
    • the fact that when this was being written, I was writing enterprise level code in a language that no one uses anymore so this is what I'm resigned to
    • the fact that my career has ended up scraping the seedy underbelly of the irish software industry

    D.


  • Closed Accounts Posts: 3,298 ✭✭✭Duggys Housemate


    dazberry wrote: »
            Try
                m_bIndexing = configReader.GetValue(&#34;Indexing&#34;, GetType(Boolean))
            Catch ex As Exception
                m_bIndexing = True
            End Try
    
            If Not m_bIndexing Then
                mnuSeparator.Visible = False
                mnuSearch.Visible = False
            End If
    

    I don't know which annoys me more:
    • the fact that it's in vb.net
    • the fact that m_bIndexing is declared as a field in the form class and used only in one place (as shown)
    • the fact that the configReader.GetValue() pattern is repeated f**king everywhere in the project, including for the "Index" value again...
    • the fact that m_bIndexing is assigned true when declared, so the assignment in the exception handler is pointless
    • the If Not m_bIndexing .... = False
    • the fact that all the code is like this... muck
    • the fact that when this was being written, I was writing enterprise level code in a language that no one uses anymore so this is what I'm resigned to
    • the fact that my career has ended up scraping the seedy underbelly of the irish software industry

    D.

    Surely he's correct to not assume that m_bindexing = true all the time.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,537 Mod ✭✭✭✭Capt'n Midnight




  • Registered Users Posts: 2,144 ✭✭✭dazberry


    Surely he's correct to not assume that m_bindexing = true all the time.

    I appreciate what you're getting at and why but in this case no it's not needed.

    And after that I had to try trace a partial stack trace from a log file where the methods names were obfuscated, and for that product the obfuscation maps were never saved by the build system - that's what I get for moaning :)

    D.


  • Advertisement
Advertisement