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
1151618202137

Comments

  • Registered Users Posts: 311 ✭✭JackHeuston


    I developed a very simple framework for our company to speed up a bit the development of online surveys, which our R&D department do quite often. I took a few days off one time, but a survey happened and had to be published asap. The "developer" in that department took my framework and worked with it then. It's all good, that's what a framework is for and it's intended to be used.

    The whole framework has only the core, plus some modules coming from past surveys in case they need to be re-used (also this happens very often), you just need to extend stuff, add/remove modules as you see fit, without touching a single line of the framework itself.

    When I came back, I checked out how the guy was doing, I was also requested to "give a hand" asap because the survey was still worked on.

    What I found:
    • The framework folder was used as the survey itself, meaning that the whole thing was modified to work for that particular survey.
    • "entities" folder: all .php files the guy did were in there. Nothing was a class, just files containing pure simple $variables for... data about something? I have no idea.
    • The framework's "Worker" entity (a user doing the survey) wasn't extended but modified with new methods and attributes, of course without a single line of phpDoc. Some code from there? Here's what's in the constructor:
      $check = FALSE;
      while ($check==FALSE) {
          $this->TWO_set = rand ( 1, 4);
          if ($this->ONE_set < 5 ) {
              if ($this->TWO_set != $this->ONE_set) {
                  $check=TRUE;
              }
          }
          else {
              if ($this->ONE_set < 9 ) {
                  if ($this->TWO_set != ($this->ONE_set-4)) {
                      $check=TRUE;
                  }
              }
              else {
                  if (($this->TWO_set == 2) & ($this->TWO_set == 3)) {
                      $check=TRUE;
                  }
                  if (($this->ONE_set == 9) & ($this->TWO_set != 1)) {
                      $check=TRUE;
                  }
                  if (($this->ONE_set == 10) & ($this->TWO_set != 4)){
                      $check=TRUE;
                  }
              }
          }
      }
      
      You may ask what's an attribute for a Worker called ONE_set or TWO_set, I'm still asking myself the same. Loop?? If, if, if, if...
    • The questions for one page were printed starting from an array of questions (in the entities folder, of course). The actual HTML printing was looping through every element of that array. The backend to work on the answers for those questions was looping through them with a "for" from 0 to 6 (six!!!). Of course we had to add a question there just before publishing the survey, and while the survey was live we weren't getting the answer for the last question. But even the whole answer treatment was bonkers anyway.
    • One way to add steps (pages) to do in this framework is making a separate file for each step (with inside a class that extended a core one). We had some sort of naming style too, like DemographicsStep, XxxStep, etc... To tell the developer what a file is all about without looking the code. Files here were called: demographics_one_.php, demographics_one_test.php, demographics_one_final.php, demographics_1.php, video_1.php, video_one.php, video_demo_one.php and so on. And amazingly only one of them was actually displayed by the framework ISTILLDONTKNOWHOW. Anyway, it was impossible to understand what file was actually used and what I had to modify to give this guy a hand.
    • The use of Javascript and jQuery was hilarious.
      Example:
      labelElement.onmouseout = function(){
          LabelMouseOutHandler(this);
      };
      
      [...]
      
      function LabelMouseOutHandler(object){
          var obj = $("#"+object.id);
          if(obj.hasClass( "hover")){
              obj.removeClass('hover');
          }
      }
      
      So.... we have a reference to the element... we pass it to the event handler with the event fired by the same element.... we extract the id.... we get another reference to the element... and then finally we more or less do what we wanted to...

    And of course indentation mixed between tabs, 8 spaces, 4 spaces, phpDoc and jsDoc randomly written, php/js documentation written with this style:
    /* This is a method                            <--- JESUS
     *
     * @returns {type}                             <--- eh. can be passed as being lazy...
     */
    

    I still have suicidal tendencies after having worked on that specific survey and I might need some support.

    This person was hired as a developer at my same level.

    Sorry for the long post, but I tried to be brief, there's lot more. I hope I didn't go against any rule of this thread, I'm not making names nor my company is traceable from my account here.


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


    Here's one that's absolutely jaw-dropping.

    I'm a member of a Facebook community for a certain high-end Data Warehousing tool.

    In recent years, it's been taken over by staff from Indian software development companies asking the most basic of questions.

    One guy asked a question about the best way to convert a numeric value to a string representation, e.g. 120 to "One-Hundred and twenty".

    Here's the suggestion he got back from a fellow outsourcing professional:

    "But if you know the values, then you can try writing case condition on the dataitem.. like when '120' then 'one hundred twenty'"


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


    believe it or not, there's programmers out there that have and will never come across localisation :eek:
    ...they call it 'localization'.


  • Registered Users Posts: 1,829 ✭✭✭lil_lisa


    "But if you know the values, then you can try writing case condition on the dataitem.. like when '120' then 'one hundred twenty'"

    That hurts my brain...


  • Moderators, Politics Moderators Posts: 38,893 Mod ✭✭✭✭Seth Brundle


    "But if you know the values, then you can try writing case condition on the dataitem.. like when '120' then 'one hundred twenty'"

    That is just so wrong.
    It's, like, "one hundred *and* twenty! :pac:


  • Advertisement
  • Registered Users Posts: 13,080 ✭✭✭✭Maximus Alexander


    lil_lisa wrote: »
    That hurts my brain...

    But, like, it's not wrong. :pac:


  • Registered Users Posts: 14,715 ✭✭✭✭Earthhorse


    But, like, it's not wrong. :pac:
    A lot of the worst code isn't.


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


    It would increase how much the computer has to do to compare strings significantly, and it would not always be desirable behaviour from a functional point of view.

    If you want to do case-neutral string comparison just use something like this: string1.ToUpper().Equals(string2.ToUpper)

    Don't use ToUpper to get rid of casing issues. :)

    This will break functionality in some locales like Turkish (the Turkish "i" problem).

    There is probably a way to do it properly in Java. In .NET you'd tell it to use the Invariant Culture, and to compare case-insensitive you'd do an Ordinal Ignore Case comparison.


  • Moderators, Technology & Internet Moderators Posts: 1,333 Mod ✭✭✭✭croo


    It would increase how much the computer has to do to compare strings significantly, and it would not always be desirable behaviour from a functional point of view.

    If you want to do case-neutral string comparison just use something like this: string1.ToUpper().Equals(string2.ToUpper)
    awec wrote: »
    Don't use ToUpper to get rid of casing issues. :)
    This will break functionality in some locales like Turkish (the Turkish "i" problem).

    There is probably a way to do it properly in Java. In .NET you'd tell it to use the Invariant Culture, and to compare case-insensitive you'd do an Ordinal Ignore Case comparison.
    That's interesting, I'd not heard of the Turkish "i" problem. I'm not aware if Java has a culturally aware equals but I've tended towards string.equalsIgnoreCase() myself. From reading the linked api I suspect that it just does an upper or lower case internally so it probably is not much better. Perhaps this is what we're supposed to be using!?


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    croo wrote: »
    That's interesting, I'd not heard of the Turkish "i" problem. I'm not aware if Java has a culturally aware equals but I've tended towards string.equalsIgnoreCase() myself. From reading the linked api I suspect that it just does an upper or lower case internally so it probably is not much better. Perhaps this is what we're supposed to be using!?

    Yes, the collator will work, but I've tended to use ICU both for Java and for C/C++.


  • Advertisement
  • Administrators Posts: 53,372 Admin ✭✭✭✭✭awec


    croo wrote: »
    That's interesting, I'd not heard of the Turkish "i" problem. I'm not aware if Java has a culturally aware equals but I've tended towards string.equalsIgnoreCase() myself. From reading the linked api I suspect that it just does an upper or lower case internally so it probably is not much better. Perhaps this is what we're supposed to be using!?

    Yea it's pretty high profile.

    A lot of people think they can ignore it just because they don't localize their app into Turkish language, but the bug affects the Turkish locale and locale != language.

    That is why .NET (and presumably java) has two culture properties:

    1. CurrentCulture - this is the locale. It dictates things like date format, number format, and character case conversion.
    2. CurrentUICulture - this dictates what language the UI appears in.

    It's perfectly normal for example for someone who is from Germany to want to see the UI in English, but have their calendar format, date format etc in their native German format. This is especially common among developers because English is usually the language of code.


  • Moderators, Technology & Internet Moderators Posts: 1,333 Mod ✭✭✭✭croo


    awec wrote: »
    Yea it's pretty high profile.

    A lot of people think they can ignore it just because they don't localize their app into Turkish language, but the bug affects the Turkish locale and locale != language.

    That is why .NET (and presumably java) has two culture properties:

    1. CurrentCulture - this is the locale. It dictates things like date format, number format, and character case conversion.
    2. CurrentUICulture - this dictates what language the UI appears in.

    It's perfectly normal for example for someone who is from Germany to want to see the UI in English, but have their calendar format, date format etc in their native German format. This is especially common among developers because English is usually the language of code.
    I found it interesting because I work (well more worked these days I don't make much contributions) on an open source Business Application and while I know there are plenty of English speaking users there are also many many more people using it through German, Spanish & Portuguese (it's popular in Brazil) there are many also using it via non-Latin alphabet based languages (Persian, Thai, some Greek and I did see some screen shots of a Japanese version). Nobody ever raised this issue with me, so I wonder now is it a problem people using other languages just "put up with" or did the non-English speakers just fix the problem and I simply never noticed. I'll have to have a look in the code... when I get a chance.


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    croo wrote: »
    I found it interesting because I work (well more worked these days I don't make much contributions) on an open source Business Application and while I know there are plenty of English speaking users there are also many many more people using it through German, Spanish & Portuguese (it's popular in Brazil) there are many also using it via non-Latin alphabet based languages (Persian, Thai, some Greek and I did see some screen shots of a Japanese version). Nobody ever raised this issue with me, so I wonder now is it a problem people using other languages just "put up with" or did the non-English speakers just fix the problem and I simply never noticed. I'll have to have a look in the code... when I get a chance.

    The Turkish i is just one of the many problems you'll run into in localization. You mentioned Thai - how do you do word breaks with that? There are no spaces or other indications. That's why you need to assume the worst - all text should be Unicode (preferably UTF-16) inside the program (text in the UI or in files can be something else), always use library functions to move to the next boundary, i.e. character, word, sentence, line, etc., to compare characters and strings, in fact to do anything with text. And, of course, there are the real locale items, such as data/time formats, currencies, first day of the week, weekend days, etc.


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


    croo wrote: »
    I found it interesting because I work (well more worked these days I don't make much contributions) on an open source Business Application and while I know there are plenty of English speaking users there are also many many more people using it through German, Spanish & Portuguese (it's popular in Brazil) there are many also using it via non-Latin alphabet based languages (Persian, Thai, some Greek and I did see some screen shots of a Japanese version). Nobody ever raised this issue with me, so I wonder now is it a problem people using other languages just "put up with" or did the non-English speakers just fix the problem and I simply never noticed. I'll have to have a look in the code... when I get a chance.

    Well, Turkish i can actually lead to a lot of functional breaks so chances are if your users were seeing issues you'd know about it.

    It can also be a problem in SQL if your collation is Turkish depending on case sensitivity settings. You can get errors in scripts or you might not get the results you expect to get.


  • Moderators, Technology & Internet Moderators Posts: 1,333 Mod ✭✭✭✭croo


    bpmurray wrote: »
    The Turkish i is just one of the many problems you'll run into in localization. You mentioned Thai - how do you do word breaks with that? There are no spaces or other indications. That's why you need to assume the worst - all text should be Unicode (preferably UTF-16) inside the program (text in the UI or in files can be something else), always use library functions to move to the next boundary, i.e. character, word, sentence, line, etc., to compare characters and strings, in fact to do anything with text.
    Well, in Adempiere's case the UI is all defined in something we call the Application Dictionary rather than in the java code itself. I don't speak Thai myself but I was aware that some have translated the UI.
    %E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B9%80%E0%B8%A0%E0%B8%97%E0%B9%80%E0%B8%87%E0%B8%B4%E0%B8%99%E0%B9%84%E0%B8%94%E0%B9%89.png

    bpmurray wrote: »
    And, of course, there are the real locale items, such as data/time formats, currencies, first day of the week, weekend days, etc.
    Yes, these are all defined by Language, there is a base Language for the entire system, for the organisation, for user and also for end client (for want of a better phrase) - so an Invoice is in the Language/locale of the customer, a purchase order the locale of the Supplier etc.

    It is a very tricky, though fundamental, problem indeed... I will have to enquire about the comparison/equals functionality. A quick check, earlier, did revealed that the sorting uses the collator class but I suspect that there might well be lots of instances in the code base where a string.equals is used!


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    croo wrote: »
    Well, in Adempiere's case the UI is all defined in something we call the Application Dictionary rather than in the java code itself. I don't speak Thai myself but I was aware that some have translated the UI

    Actually I had forgotten about the most fundamental part of all - the externalizing of all strings. If you have translations, do you ever display them in such a way as to have to break the text across a line? If so, you'll need a word break solution. And never, ever combine pieces of a string to make a phrase: ["there are " + count " cows in the field"] != [count + " cows are in the field"] (assume that they're the ways different languages say the same thing), so you have to use "there are %d cows in the field" so that the string can be changed but retain the usage.

    And do you handle directionality correctly? Displaying text left to right or right to left isn't too bad - it's the bidirectionality that's awkward (that's why it's called BiDi). When you have dates or numbers, they are displayed left to right, even in Arabic or Hebrew, even though they're Arabic numbers.

    Oh, this localization stuff has so many gotchas.


  • Technology & Internet Moderators Posts: 28,791 Mod ✭✭✭✭oscarBravo




  • Banned (with Prison Access) Posts: 963 ✭✭✭Labarbapostiza


    bpmurray wrote: »
    And never, ever combine pieces of a string to make a phrase: ["there are " + count " cows in the field"] != [count + " cows are in the field"] (assume that they're the ways different languages say the same thing), so you have to use "there are %d cows in the field" so that the string can be changed but retain the usage.


    Oh, this localization stuff has so many gotchas.

    Yeah, I've seen these actual bugs

    If buttonYesPressed( variable = ButtonYesLabel), if buttonNoPressed(variable =ButtonNoLabel).

    No and Yes, are often defined as being 0 and 1, but Oui and Non, or your other local combinations are not. I have no idea why someone would use the labels since TRUE and FALSE or even 1 and 0 would more than suffice.....but I have witnessed it.

    The worst combination is when the programmer hard codes their strings, then uses those strings for logical operations, and even labels. And they may even use Windows labels for logical operations; it might work like a dream on an English version of Windows, it crashes the instant you put it on a German machine.


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


    Have you ever felt physically sick after looking at some code? Haha.

    Opened up a few classes im supposed to add a feature to. What a pile of garbage. Ugly ugly messy code.


  • Registered Users Posts: 6,250 ✭✭✭Buford T Justice


    Not quite a horror, but in the midst of thousands of lines of obfuscated "I'm clever so I'll not bother commenting code, and use ternary operators with evaluations that run to three lines " I found this
    // if you change submit label I'll break your legs => change it on InvoiceController > create_log too ;)
    


  • Advertisement
  • Registered Users Posts: 63 ✭✭ThrowinShapes


    A couple of years ago, a place I used to work for had to outsource work for an eCommerce site. The company doing the work had some incredible work under their belt, and they were in charge of everything from front-end to back-end development.

    We had meetings every couple of days with reports that all is going great. With a week to go, we received the site for testing. Of course, absolutely nothing was done on the back-end, and the front-end was in shambles (h3 tags for paragraphs, CSS was a specificity minefield). I worked until 11pm most nights rebuilding everything from scratch to get it ready for the launch date.

    It was to be launched on a Saturday (of course) so I was on-call from 8am that morning. Everything was going great, then we get information that pricing changes weren't working. After some frantic digging around, we discovered that the core of a plugin was modified with a hardcoded price meaning many people were being overcharged.

    Part of me died that week. I still haven't fully recovered.


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


    I found this on the interwebs.


    xx: OK, so, our build engineer has left for another company. The dude was literally living inside the terminal. You know, that type of a guy who loves Vim, creates diagrams in Dot and writes wiki-posts in Markdown... If something - anything - requires more than 90 seconds of his time, he writes a script to automate that.

    xxx: So we're sitting here, looking through his, uhm, "legacy"

    xxx: You're gonna love this

    xxx: smack-my-bitch-up.sh - sends a text message "late at work" to his wife (apparently). Automatically picks reasons from an array of strings, randomly. Runs inside a cron-job. The job fires if there are active SSH-sessions on the server after 9pm with his login.

    xxx: kumar-asshole.sh - scans the inbox for emails from "Kumar" (a DBA at our clients). Looks for keywords like "help", "trouble", "sorry" etc. If keywords are found - the script SSHes into the clients server and rolls back the staging database to the latest backup. Then sends a reply "no worries mate, be careful next time".

    xxx: hangover.sh - another cron-job that is set to specific dates. Sends automated emails like "not feeling well/gonna work from home" etc. Adds a random "reason" from another predefined array of strings. Fires if there are no interactive sessions on the server at 8:45am.

    xxx: (and the oscar goes to) ****ingcoffee.sh - this one waits exactly 17 seconds (!), then opens an SSH session to our coffee-machine (we had no frikin idea the coffee machine is on the network, runs linux and has SSHD up and running) and sends some weird gibberish to it. Looks binary. Turns out this thing starts brewing a mid-sized half-caf latte and waits another 24 (!) seconds before pouring it into a cup. The timing is exactly how long it takes to walk to the machine from the dudes desk
    .


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


    It should be in the thread "Genius at work" not "Coding Horror" ;-)


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


    PrzemoF wrote: »
    It should be in the thread "Genius at work" not "Coding Horror" ;-)

    I think the more appropriate term is "Cowboy Coder".

    XtRz6.gif


  • Registered Users Posts: 506 ✭✭✭Ant695


    I found this on the interwebs.


    xx: OK, so, our build engineer has left for another company. The dude was literally living inside the terminal. You know, that type of a guy who loves Vim, creates diagrams in Dot and writes wiki-posts in Markdown... If something - anything - requires more than 90 seconds of his time, he writes a script to automate that.

    xxx: So we're sitting here, looking through his, uhm, "legacy"

    xxx: You're gonna love this

    xxx: smack-my-bitch-up.sh - sends a text message "late at work" to his wife (apparently). Automatically picks reasons from an array of strings, randomly. Runs inside a cron-job. The job fires if there are active SSH-sessions on the server after 9pm with his login.

    xxx: kumar-asshole.sh - scans the inbox for emails from "Kumar" (a DBA at our clients). Looks for keywords like "help", "trouble", "sorry" etc. If keywords are found - the script SSHes into the clients server and rolls back the staging database to the latest backup. Then sends a reply "no worries mate, be careful next time".

    xxx: hangover.sh - another cron-job that is set to specific dates. Sends automated emails like "not feeling well/gonna work from home" etc. Adds a random "reason" from another predefined array of strings. Fires if there are no interactive sessions on the server at 8:45am.

    xxx: (and the oscar goes to) ****ingcoffee.sh - this one waits exactly 17 seconds (!), then opens an SSH session to our coffee-machine (we had no frikin idea the coffee machine is on the network, runs linux and has SSHD up and running) and sends some weird gibberish to it. Looks binary. Turns out this thing starts brewing a mid-sized half-caf latte and waits another 24 (!) seconds before pouring it into a cup. The timing is exactly how long it takes to walk to the machine from the dudes desk
    .

    Saw that on reddit this morning. That guy is a genius. No time wasted at all.


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


    Ant695 wrote: »
    Saw that on reddit this morning. That guy is a genius. No time wasted at all.

    I read that and thought, this man is a genius and how I particularly loved the last script. No messing there when it comes to Coffee.


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


    Ant695 wrote: »
    Saw that on reddit this morning. That guy is a genius. No time wasted at all.

    https://github.com/narkoz/hacker-scripts


  • Banned (with Prison Access) Posts: 963 ✭✭✭Labarbapostiza


    A slight reverse.....Horror with Coders

    Me a support role over the phone, getting a bad response from a customer with my baby steps.

    "...Stop speaking to me like I'm a child.....I have 20 years experience as a network programmer"

    "...Okay then.....Telnet onto the device"

    "........Telnet?........Ah, um, what's Tel...How do I do that"

    I was holding a pen at the time ......And I wanted to drive it through my eyeball and into my skull to end my suffering.


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


    A slight reverse.....Horror with Coders

    Me a support role over the phone, getting a bad response from a customer with my baby steps.

    "...Stop speaking to me like I'm a child.....I have 20 years experience as a network programmer"

    "...Okay then.....Telnet onto the device"

    "........Telnet?........Ah, um, what's Tel...How do I do that"

    I was holding a pen at the time ......And I wanted to drive it through my eyeball and into my skull to end my suffering.

    All that springs to mind!

    58687594.jpg


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


    I have 20 years experience as a network programme
    Remind me of a conversation I had a long time ago.

    The "programmer" didn't know that both .com and .exe were executables in DOS


Advertisement