Advertisement
How to add spoiler tags, edit posts, add images etc. How to - a user's guide to the new version of Boards
Mods please check the Moderators Group for an important update on Mod tools. If you do not have access to the group, please PM Niamh. Thanks!

Coding Horror

145791036

Comments



  • DELETE * FROM tbl_Customers
    

    What?

    WHAT??

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




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




  • 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.




  • 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!!!!");
    


  • Advertisement


  • 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?




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




  • 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.




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




  • 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


  • 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




  • 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.




  • 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.




  • 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




  • Another reason why
    13 == secondaryIndex
    

    is the master syntax ;)




  • 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).




  • 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!




  • i'm a fan of doing

    const int kSomeMagicNumber = 13;

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




  • 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:




  • 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


  • 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.




  • 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)




  • 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.




  • 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.




  • 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.




  • 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:




  • 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.




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

    I hope the invoice was given before implementing. :D




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


  • Advertisement


  • 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