Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on [email protected] for help. Thanks :)
Hello All, This is just a friendly reminder to read the Forum Charter where you wish to post before posting in it. :)

Coding Horror

145791036

Comments

  • Registered Users Posts: 3,396 ✭✭✭ dnme


    DELETE * FROM tbl_Customers
    

    What?

    WHAT??

    WHAT DO YOU MEAN BY A "Where Clause".....???


  • Registered Users Posts: 1,645 ✭✭✭ k.p.h


    Jesus, 10 min of my life wasted and I have no one to blame, I am a tit..! :o
    if (pts < pts-buffer)
    


  • Registered Users Posts: 3,981 ✭✭✭ Korvanica


    string[] SupervisorArray = new string[1];
    int i = -1;
    
    while (RS2.Read())
    {
        i++;
        SupervisorArray[i] = RS2["SignedByEmplNo"].ToString();
    }
    

    :eek:
    Worst piece of coding i've seen in a long time.


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


    Korvanica wrote: »
    string[] SupervisorArray = new string[1];
    int i = -1;
    
    while (RS2.Read())
    {
        i++;
        SupervisorArray[i] = RS2["SignedByEmplNo"].ToString();
    }
    

    :eek:
    Worst piece of coding i've seen in a long time.
    Here's a loop-unrolled optimised version :p
    RS2.Read();
    string Supervisor = RS2["SignedByEmplNo"].ToString();
    if(RS2.Read())
      throw new ArrayIndexOutOfBoundsException("YAAAAY!!!!");
    


  • Closed Accounts Posts: 2,117 ✭✭✭ Defiler Of The Coffin




  • Advertisement
  • Closed Accounts Posts: 619 ✭✭✭ Boards.ie: Paddy


    Thought I'd share a real beauty from the boards codebase. This was one of the first things I read when I was taking over from Conor. I'm yet to understand how anyone could ever have thought that this was a good idea:
    /**
    * Essentially a wrapper for the ternary operator.
    *
    * @deprecated	Deprecated as of 3.5. Use the ternary operator.
    *
    * @param	string	Expression to be evaluated
    * @param	mixed	Return this if the expression evaluates to true
    * @param	mixed	Return this if the expression evaluates to false
    *
    * @return	mixed	Either the second or third parameter of this function
    */
    function iif($expression, $returntrue, $returnfalse = '')
    {
    	return ($expression ? $returntrue : $returnfalse);
    }
    

    I guess some people just find ternary operators too confusing?


  • Moderators, Sports Moderators Posts: 40,055 Mod ✭✭✭✭ Sparks


    Ugh. Love the @deprecated note's subtle way of saying "cop the blank on" :D


  • Closed Accounts Posts: 619 ✭✭✭ Boards.ie: Paddy


    Oh the WTFs pile up the longer your stare at this...

    "Essentially" a wrapper? No, it's "just" a wrapper.

    $expression isn't an expression. It's a variable.

    $expression is expected to be a string... so if used strictly this function only evaluates the truthiness of strings.

    The default false value isn't FALSE, it's an empty string?!

    A small window into the joys of working with the vbulletin core.


  • Moderators, Sports Moderators Posts: 40,055 Mod ✭✭✭✭ Sparks


    Even better, in C++ any decent compiler would just optimise it away, but in PHP that may not hold...


  • Registered Users Posts: 695 ✭✭✭ DaSilva


    Thought I'd share a real beauty from the boards codebase. This was one of the first things I read when I was taking over from Conor. I'm yet to understand how anyone could ever have thought that this was a good idea:
    /**
    * Essentially a wrapper for the ternary operator.
    *
    * @deprecated	Deprecated as of 3.5. Use the ternary operator.
    *
    * @param	string	Expression to be evaluated
    * @param	mixed	Return this if the expression evaluates to true
    * @param	mixed	Return this if the expression evaluates to false
    *
    * @return	mixed	Either the second or third parameter of this function
    */
    function iif($expression, $returntrue, $returnfalse = '')
    {
    	return ($expression ? $returntrue : $returnfalse);
    }
    

    I guess some people just find ternary operators too confusing?

    Looks like a VB programmer, almost exact same parameter names even http://msdn.microsoft.com/en-us/library/27ydhh0d%28v=vs.90%29.aspx


  • Advertisement
  • Closed Accounts Posts: 619 ✭✭✭ Boards.ie: Paddy


    Hah good guess, you get a cookie. The developers of VBulletin were indeed originally VB programmers. I guess it's the same mentality that leads people to write monstrosities like this:

    http://phpjs.org/functions/substr:558


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


    the best thing about iif() is the @deprecated comment :)

    php.js should also die in a fire and should be quick and painful so less people use it before it dies.


  • Registered Users Posts: 113 ✭✭ lenovoguy


    Working on a Win32/MFC app at the moment which also has a COM/ActiveX control inside it. Adding text field to the control required changing 41.cpp files, 21.h files & a couple of others, because our software supports lots of file formats and each file format's class (of which all derive from the same parent) individually has to be updated so copy constructors, overloaded operators, data serialisation functions etc., successfully copy the new text value. We may be missing the point of OOP.


  • Registered Users Posts: 1,235 ✭✭✭ Odaise Gaelach


    Not exactly coding horror, but I'm working on something in C# and Visual Studio 2010. So...
    string[] infoSplits = [I]**some initialisation here**[/I]
    
    for (int secondaryIndex = 5; secondaryIndex < infoSplits.Length; secondaryIndex++)
    [B]{[/B]
       string[] moreInfoSplits = infoSplits[secondaryIndex].Split('|');
    

    Don't worry too much about code itself or the variable names; they make sense to me. :D

    Anyway, I just spent the last 30 minutes wondering why secondaryIndex would jump from 5 to 13 in between the for-loop declaration and the moreInfoSplits[] declaration. Where the curly bracket is.

    For a while I thought I was going mad. Every time I went across those three lines it would change. Over and over and over again, without fail. Well it turned out that I had a conditional breakpoint set at that bracket. I had the condition set as:
    secondaryIndex = 13
    

    Instead of:
    secondaryIndex == 13
    


    Sometimes I'm an absolute dumbass. At least I'm not insane. :o


  • Registered Users Posts: 11,908 ✭✭✭✭ Giblet


    Another reason why
    13 == secondaryIndex
    

    is the master syntax ;)


  • Registered Users Posts: 3,945 ✭✭✭ Anima


    Giblet wrote: »
    Another reason why
    13 == secondaryIndex
    

    is the master syntax ;)

    I dunno, it just looks bad to me. I think it ruins the flow when reading it. Also any decent compiler will warn you about it (c++ anyway).


  • Registered Users Posts: 1,861 ✭✭✭ Colonel Panic


    And we all have warnings as errors enabled, right? :D Some of the code I work with has thousands of warnings, each one a bug waiting to happen.

    I think he'd put that into a conditional breakpoint as opposed to code btw!

    Regarding 13 == secondaryIndex. It's more readable when dealing with constants and stuff!


  • Registered Users Posts: 2,013 ✭✭✭ SirLemonhead


    i'm a fan of doing

    const int kSomeMagicNumber = 13;

    then doing "if (kSomeMagicNumber = 13) " should throw up a compiler error


  • Registered Users Posts: 2,013 ✭✭✭ SirLemonhead


    i'm a fan of doing

    const int kSomeMagicNumber = 13;

    then doing "if (kSomeMagicNumber = 13) " should throw up a compiler error

    edit: just came back and re-read my post. WHAT was I thinking... disregard it :pac:


  • Registered Users Posts: 5,417 ✭✭✭ Slutmonkey57b


    Is there a particular reason why there are so many variants of SQL, and why there are so many application-specific addendums? Was someone offering a bounty on these things in the 90's?

    "Syntax error on subquery"
    *searches for syntax guide for this particular variant, comes up with nothing*


  • Advertisement
  • Registered Users Posts: 20 lowlifer


    Giblet wrote: »
    Another reason why
    13 == secondaryIndex
    

    is the master syntax ;)

    I hate it when my teachers are right. :mad:

    Anyway, I'd rather run into a blocker like this and lose 5 minutes on it rather than using the quoted syntax each and every single day.


  • Registered Users Posts: 11,908 ✭✭✭✭ Giblet


    Imagine it making it into production code on a falsey value which because truthy. You'd lose more than 5 mins. Anyway, you wouldn't use magic numbers, just comparisons against values that cannot be assigned to. (consts etc)


  • Registered Users Posts: 20 lowlifer


    I like to think it wouldn't, I test all my work meticulously; we also have internal standards about magic numbers and values that *should* keep us from getting in this situation.

    The problem with standards is that they're sadly not always followed and eventually we run into some guy's work who isn't even with the company anymore. But that's besides the point.

    I will take my chances with not using this ugly syntax.


  • Registered Users Posts: 11,908 ✭✭✭✭ Giblet


    lowlifer wrote: »
    I like to think it wouldn't, I test all my work meticulously; we also have internal standards about magic numbers and values that *should* keep us from getting in this situation.

    No such thing as meticulous testing, doesn't exist or is a fairy tale. Anyway arguing about syntax is low hanging fruit, it's what every tom dick and harry coder can argue about. The real issues are the ones to be solved, and this is one of them.


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


    Not Coding Horror, per se, but Horror none the less.

    One of my clients, a very big organisation, had a small app developed by one of the 'Big 6' consultancies a while back.

    They needed to pull data out of the app to integrate it into another in-house app.

    They employed the original Big-6 consultancy to come in and code the work - essentially a SQL-statement piped out to a text file.

    The invoice came in last week for the work - €32,000. I kid you not.


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


    They employed the original Big-6 consultancy to come in and code the work - essentially a SQL-statement piped out to a text file.

    The invoice came in last week for the work - €32,000. I kid you not.
    Ouch. Nice work when you can get it... :pac:


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


    The "consultants" for those big companies are just guys straight out of college not getting paid very much. Their managers/salespeople etc are the ones creaming it.


  • Registered Users Posts: 20 lowlifer


    How much do those "Big 6" charge for an hour?

    I hope the invoice was given before implementing. :D


  • Registered Users Posts: 1,645 ✭✭✭ k.p.h


    The Big 6 ..??? :confused: Could someone clarify/identify ..? Through PM if necessary.?


  • Advertisement
  • Registered Users Posts: 5,246 ✭✭✭ conor.hogan.2


    k.p.h wrote: »
    The Big 6 ..??? :confused: Could someone clarify/identify ..? Through PM if necessary.?

    I think they are talking about 6 of the bigger consultancy firms. Delloitte and Accenture being 2 of them afaik. A lot of them do accountancy/audit etc type work.


Advertisement