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

Options
1242527293037

Comments

  • Closed Accounts Posts: 22,651 ✭✭✭✭beauf


    Your colleagues brother must work in my place. we have leading zeros in numbers stored as strings.


  • Closed Accounts Posts: 22,651 ✭✭✭✭beauf


    We also have ASCII characters that look like white space but aren't.


  • Registered Users Posts: 3,337 ✭✭✭Wombatman


    Pelvis wrote: »
    Search for your road and stick a space at the end. :rolleyes:

    https://www.dublincity.ie/votersregistration/PublicPages/ereg.aspx?CID=
    <script type="text/javascript">
    //<![CDATA[
    var MainContent_TextBoxTownlandRegularExpressionValidator = document.all ? document.all["MainContent_TextBoxTownlandRegularExpressionValidator"] : document.getElementById("MainContent_TextBoxTownlandRegularExpressionValidator");
    MainContent_TextBoxTownlandRegularExpressionValidator.controltovalidate = "MainContent_TextBoxTownland";
    MainContent_TextBoxTownlandRegularExpressionValidator.errormessage = "At least 2 letters required.";
    MainContent_TextBoxTownlandRegularExpressionValidator.display = "Dynamic";
    MainContent_TextBoxTownlandRegularExpressionValidator.validationGroup = "SearchVal";
    MainContent_TextBoxTownlandRegularExpressionValidator.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
    MainContent_TextBoxTownlandRegularExpressionValidator.validationexpression = "^[^?]{2,}$";
    var MainContent_TextBoxTownlandRegularExpressionValidator1 = document.all ? document.all["MainContent_TextBoxTownlandRegularExpressionValidator1"] : document.getElementById("MainContent_TextBoxTownlandRegularExpressionValidator1");
    MainContent_TextBoxTownlandRegularExpressionValidator1.controltovalidate = "MainContent_TextBoxTownland";
    MainContent_TextBoxTownlandRegularExpressionValidator1.errormessage = "Your search string cannot start with a space.";
    MainContent_TextBoxTownlandRegularExpressionValidator1.display = "Dynamic";
    MainContent_TextBoxTownlandRegularExpressionValidator1.validationGroup = "SearchVal";
    MainContent_TextBoxTownlandRegularExpressionValidator1.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
    MainContent_TextBoxTownlandRegularExpressionValidator1.validationexpression = "^[^\\s#](?:[^#]*[^#])?$";
    var MainContent_TextBoxTownlandRegularExpressionValidator2 = document.all ? document.all["MainContent_TextBoxTownlandRegularExpressionValidator2"] : document.getElementById("MainContent_TextBoxTownlandRegularExpressionValidator2");
    MainContent_TextBoxTownlandRegularExpressionValidator2.controltovalidate = "MainContent_TextBoxTownland";
    MainContent_TextBoxTownlandRegularExpressionValidator2.errormessage = "Your search string cannot end with a space.";
    MainContent_TextBoxTownlandRegularExpressionValidator2.display = "Dynamic";
    MainContent_TextBoxTownlandRegularExpressionValidator2.validationGroup = "SearchVal";
    MainContent_TextBoxTownlandRegularExpressionValidator2.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
    MainContent_TextBoxTownlandRegularExpressionValidator2.validationexpression = "^[^#](?:[^#]*[^\\s#])?$";
    var MainContent_PostcodeRegularExpressionValidator1 = document.all ? document.all["MainContent_PostcodeRegularExpressionValidator1"] : document.getElementById("MainContent_PostcodeRegularExpressionValidator1");
    MainContent_PostcodeRegularExpressionValidator1.controltovalidate = "MainContent_textboxPostCode";
    MainContent_PostcodeRegularExpressionValidator1.errormessage = "Please enter a valid Eircode (Note: Eircode should contain NO spaces).";
    MainContent_PostcodeRegularExpressionValidator1.display = "Dynamic";
    MainContent_PostcodeRegularExpressionValidator1.validationGroup = "SearchVal";
    MainContent_PostcodeRegularExpressionValidator1.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
    MainContent_PostcodeRegularExpressionValidator1.validationexpression = "^$|(?i)D6W[0-9,A,C,D,E,F,H,K,N,P,R,T,V,W,X,Y]{4}|(?i)[A,C,D,E,F,H,K,N,P,R,T,V,W,X,Y]{1}[0-9]{2}[0-9,A,C,D,E,F,H,K,N,P,R,T,V,W,X,Y]{4}";
    var MainContent_PostcodeRegularExpressionValidator2 = document.all ? document.all["MainContent_PostcodeRegularExpressionValidator2"] : document.getElementById("MainContent_PostcodeRegularExpressionValidator2");
    MainContent_PostcodeRegularExpressionValidator2.controltovalidate = "MainContent_textboxPostCode";
    MainContent_PostcodeRegularExpressionValidator2.errormessage = "Your search string cannot start with a space.";
    MainContent_PostcodeRegularExpressionValidator2.display = "Dynamic";
    MainContent_PostcodeRegularExpressionValidator2.validationGroup = "SearchVal";
    MainContent_PostcodeRegularExpressionValidator2.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
    MainContent_PostcodeRegularExpressionValidator2.validationexpression = "^[^\\s#](?:[^#]*[^#])?$";
    var MainContent_PostcodeRegularExpressionValidator3 = document.all ? document.all["MainContent_PostcodeRegularExpressionValidator3"] : document.getElementById("MainContent_PostcodeRegularExpressionValidator3");
    MainContent_PostcodeRegularExpressionValidator3.controltovalidate = "MainContent_textboxPostCode";
    MainContent_PostcodeRegularExpressionValidator3.errormessage = "Your search string cannot end with a space.";
    MainContent_PostcodeRegularExpressionValidator3.display = "Dynamic";
    MainContent_PostcodeRegularExpressionValidator3.validationGroup = "SearchVal";
    MainContent_PostcodeRegularExpressionValidator3.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
    MainContent_PostcodeRegularExpressionValidator3.validationexpression = "^[^#](?:[^#]*[^\\s#])?$";
    //]]>
    </script>
    


  • Registered Users Posts: 6,490 ✭✭✭daymobrew


    (Note: Eircode should contain NO spaces
    But finder.eircode.ie returns eircodes with a space and the little card from eircode contains a space.


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


    beauf wrote: »
    Your colleagues brother must work in my place. we have leading zeros in numbers stored as strings.

    Be careful with leftpad, it can break ... everything ... :D


  • Advertisement
  • Moderators, Education Moderators, Technology & Internet Moderators Posts: 35,046 Mod ✭✭✭✭AlmightyCushion


    GreeBo wrote: »
    Or detect them...

    It does, that's the frustratingly stupid part. Instead of just trimming it, it returns an error message. They've actually done something that it worse, more annoying and more difficult than just trimming the input value. It's kind of impressive when you think about it.


  • Registered Users Posts: 27,033 ✭✭✭✭GreeBo


    It does, that's the frustratingly stupid part. Instead of just trimming it, it returns an error message. They've actually done something that it worse, more annoying and more difficult than just trimming the input value. It's kind of impressive when you think about it.

    I was being sarcastic! :(:o


  • Registered Users Posts: 17,498 ✭✭✭✭Mr. CooL ICE


    Not something I'm working on, but a colleague is currently working on what sounds like a nightmare project.

    The customer's system was originally designed by an in-house student on placement (in the customer's office) who set up an Access database for his own needs, which his colleagues thought was a great idea and they all built on it. It got out of hand and they hired an external contractor to 'handle' it. The result? Two sql databases; one with over 700 tables and the other with over 200. And 41m records in the 200 table db.

    I'm hoping I'm not getting roped into helping out with that one.


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    Not something I'm working on, but a colleague is currently working on what sounds like a nightmare project.

    The customer's system was originally designed by an in-house student on placement (in the customer's office) who set up an Access database for his own needs, which his colleagues thought was a great idea and they all built on it. It got out of hand and they hired an external contractor to 'handle' it. The result? Two sql databases; one with over 700 tables and the other with over 200. And 41m records in the 200 table db.

    I'm hoping I'm not getting roped into helping out with that one.

    Nows the perfect time to take some holidays.


  • Registered Users Posts: 66 ✭✭belfe


    if (result.equals(true)) {
    return true;
    } else {
    return false;
    }


  • Advertisement
  • Registered Users Posts: 1,459 ✭✭✭Anesthetize


    belfe wrote: »
    if (result.equals(true)) {
    return true;
    } else {
    return false;
    }
    While I haven't seen people in work do that, I have seen even experienced developers do the following:
    return result.equals(true) ? true : false;
    


  • Registered Users Posts: 20 heyitsfranklin


    <tr class="desc">
    	<td>
    		<span>Please ensure you complete the address section thoroughly.
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    		 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    	</td>
    	<td>
    	</td>
    </tr>
    

    SMH :mad:


  • Registered Users Posts: 27,033 ✭✭✭✭GreeBo


    <tr class="desc">
    	<td>
    		<span>Please ensure you complete the address section thoroughly.
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    		 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    	</td>
    	<td>
    	</td>
    </tr>
    

    SMH :mad:

    Auto-generated/GUI builder?


  • Registered Users Posts: 1,290 ✭✭✭meep


    While I haven't seen people in work do that, I have seen even experienced developers do the following:
    return result.equals(true) ? true : false;
    

    But in a non-strictly typed language, that has potential uses. If result can be boolean or integer, it's filtering cases of 1/true from (n<>1)/false.

    I've written code like that myself at times. Bad practice I know as I should know they type returned but soemthing like this can provide some flexibility in scripting. Maybe earlier, based on soem state, I called one of two functions, one of which returns boolean, the other, integer results. This structure allows a single check to process both.

    I'm not a programmer though, just a hobbyist so am likely taking through my proverbial. Please be gentle.


  • Registered Users Posts: 5,404 ✭✭✭CalamariFritti


    What he means its the same as

    return result.equals(true);

    and therefore totally redundant.

    Ah the days when you could cast anything to anything and when it was just zero or not.


  • Registered Users Posts: 1,290 ✭✭✭meep


    What he means its the same as

    return result.equals(true);

    and therefore totally redundant.

    Ah the days when you could cast anything to anything and when it was just zero or not.

    Indeed, sorry, it was actually the previoys if/then construct I was really referencing but I haven't bother to figure out boards multiquotes.

    Been dabbling with Perl for a project and that's loads of fun in this regard!


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


    8878_27ae_712.jpeg


  • Registered Users Posts: 17,498 ✭✭✭✭Mr. CooL ICE


    public class GonnaKillMyself {
        // a bunch of helper methods
    }
    

    And nope. Not an alternative method name based in Close() or 'killing' connections or anything like that. The dev just appeared to have been experiencing a breakdown when writing the above. He left about two months after this class was written.


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    public class GonnaKillMyself {
        // a bunch of helper methods
    }
    

    And nope. Not an alternative method name based in Close() or 'killing' connections or anything like that. The dev just appeared to have been experiencing a breakdown when writing the above. He left about two months after this class was written.

    I have to say ive been guilty of naming classes with weird names when im having a bad day. ****ingLogger comes to mind. haha. I wonder if anyone has renamed that. :D:D:D


  • Registered Users Posts: 66 ✭✭belfe


    I've tried to avoid weird names, but always ended with this long or unaccurate name issues.

    The most typical that I've seen several times is a test like:
    validateThatFirstElementOfTheListIsTheBiggest() {
        // Code
        // Assertion that validates that the first element is the smallest
    }
    

    This happens when you change the functionality, then change the test but forget about the test name.


  • Advertisement
  • Moderators, Politics Moderators Posts: 38,871 Mod ✭✭✭✭Seth Brundle


    Just saw this (not horror code but just humourous)...
    459394.jpg


  • Registered Users Posts: 255 ✭✭mooonpie


    Took me a while to dig out ... but I knew that concept seemed familiar: https://thedailywtf.com/articles/The-Speedup-Loop


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    mooonpie wrote: »
    Took me a while to dig out ... but I knew that concept seemed familiar: https://thedailywtf.com/articles/The-Speedup-Loop

    I thought of that when i read the post but i couldn't find it.
    Its hilarious if its true.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Updated an interface, but it's redundant and will be removed in my next commit

    *Somebody* did this today *cough* :pac:


  • Registered Users Posts: 768 ✭✭✭14ned


    Just saw this (not horror code but just humourous)...

    Interestingly, in multithreaded C++ code it would not be uncommon to scatter around code of the form:
    #ifndef NDEBUG
    std::this_thread::sleep_for(std::chrono::milliseconds(random_testing_sleep()));
    #endif
    

    The idea is that under Monte-Carlo testing under the thread sanitiser, you're deliberately introducing stochastic variation to increase the combinatorial variations for the sanitiser to test upon.

    The fun begins when somebody forgets to #define NDEBUG in the release builds, and even better when customers don't notice for over a year :)

    Niall


  • Registered Users Posts: 1,611 ✭✭✭victor8600


    14ned wrote: »
    #ifndef NDEBUG
    std::this_thread::sleep_for(std::chrono::milliseconds(random_testing_sleep()));
    #endif
    

    The fun begins when somebody forgets to #define NDEBUG in the release builds, ...

    This is horrific. I nearly choked on my coffee. I would be surprised if somebody remembers to define NDEBUG after a couple of years. The program should warn about the activation of the debugging code and the debug flag must be explicitly set
    #define DEBUG 0
    #if DEBUG
    Log.print("Warning -- debugging is active. Performance will be negatively affected");
    #endif
    
    #if DEBUG
    std::this_thread::sleep_for(std::chrono::milliseconds(random_testing_sleep()));
    #endif
    


  • Registered Users Posts: 27,033 ✭✭✭✭GreeBo


    victor8600 wrote: »
    This is horrific. I nearly choked on my coffee. I would be surprised if somebody remembers to define NDEBUG after a couple of years. The program should warn about the activation of the debugging code and the debug flag must be explicitly set
    #define DEBUG 0
    #if DEBUG
    Log.print("Warning -- debugging is active. Performance will be negatively affected");
    #endif
    
    #if DEBUG
    std::this_thread::sleep_for(std::chrono::milliseconds(random_testing_sleep()));
    #endif
    

    +1
    Your code should (pretty much) always run in production mode unless configured otherwise. Its annoying when it runs expecting prod infra in a small test env, but its usually much worse if its runs in test mode in prod.

    Granted there are some caveats (i.e. you wouldnt configure it to run against a prod DB by default) but performance wise default should be prod settings.


  • Registered Users Posts: 768 ✭✭✭14ned


    victor8600 wrote: »
    This is horrific. I nearly choked on my coffee. I would be surprised if somebody remembers to define NDEBUG after a couple of years.

    In fairness, if you're using cmake or any other modern build tool, NDEBUG gets defined for you in release builds by default. It's only when somebody writes a cmake flags stripper routine, and forgets to whitelist NDEBUG ...
    victor8600 wrote: »
    The program should warn about the activation of the debugging code and the debug flag must be explicitly set

    Ah, but NDEBUG is not the opposite to DEBUG! Asserts always fire, debug and release builds, unless NDEBUG is defined. Been that way since C89. Similarly, for Monte-Carlo testing under the thread sanitiser, you're almost always compiling a release build but with asserts enabled. So it makes total sense to introduce random waits into a release, non-debug, build.

    I would emphasise the fact that no customer noticed for over a year, and even then it was actually a BR by someone who had been stepping through our code, and went "WTF?" and asked if this was correct? Not that anybody had or found an issue with the performance loss.

    C++ is often fast enough that if it runs 20% slower, or even 50%, nobody notices. It's "fast enough".

    Niall


  • Moderators, Society & Culture Moderators Posts: 15,708 Mod ✭✭✭✭smacl


    14ned wrote: »
    C++ is often fast enough that if it runs 20% slower, or even 50%, nobody notices. It's "fast enough".

    Hmmm,in the process of porting some performance critical C++ code that isn't fast enough (already multi-threaded via OMP) to HLSL to leverage the GPU. To say C++ is fast enough is meaningless. You need to say what exactly C++ is fast enough for, because fast enough for everything it aint. If you're in any doubt about this, ask yourself why there's a dedicated overclocking forum on boards? ;)


  • Advertisement
  • Registered Users Posts: 5,552 ✭✭✭Slutmonkey57b


    It's a permanent problem with coders though. "good enough, don't have the time /energy /knowledge to fix it, the hardware will pick up the slack". We've all done it!


Advertisement