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

1262729313237

Comments

  • Banned (with Prison Access) Posts: 172 ✭✭devlinio


    WTF is that.

    I work on a project and one of the controllers is 3500 lines. There's absolutely no need. My job in the new year if refactoring this.


  • Registered Users Posts: 132 ✭✭elvis83


    Im starting to think i work with a bunch of cowboys with the amount i post in this thread. haha.

    You are definitely not alone.

    And as to why these jokers are still employed? You have to remember who had the control here. The business side have to deliver X by some date. They don't care about code, at all. That might be hard to hear but it's true. They don't even care about quality. They just want X by date. If X fails after date - well that's where the support contract kicks in...


  • Registered Users Posts: 132 ✭✭elvis83


    Im starting to think i work with a bunch of cowboys with the amount i post in this thread. haha.

    You are definitely not alone.

    And as to why these jokers are still employed? You have to remember who have the control here. The business side have to deliver X by some date. They don't care about code, at all. That might be hard to hear but it's true. They don't even care about quality. They just want X by date. If X fails after date - well that's where the support contract kicks in...


  • Registered Users Posts: 1,298 ✭✭✭off.the.walls


    Trying to make vuejs modular... that is all.


  • Registered Users Posts: 98 ✭✭haskellgeek


    not production code but for C someone recommended *(p+2) rather than p[2].


  • Advertisement
  • Registered Users Posts: 2,089 ✭✭✭henryporter


    This week was a bad week for the world of contributions to Java...

    someVariable = checkIfTrueOrFalse(some parameter) ? true : false (result = major facepalm - even Elvis would wish himself dead at that one)

    Asked a 'developer' as part of a code review to move the parts of the code that won't throw an exception outside the try-catch block I'm told that:

    if(x != null){
    blah
    }

    might cause a null so it should stay.

    Also asked to make sure a declared variable was finalized, was asked what?

    Aargh!!!!

    Said developer is considered (by the company) and considers themselves senior.


  • Banned (with Prison Access) Posts: 172 ✭✭devlinio


    No code to share, but in my last job we had a "Dashboard" controller that was 3500 lines. It controlled nearly everything on the user side. It was insane.

    By the time me and my manager finished refactoring it, we reduced it to 300/400 lines. Everything was reconfigured to spit out JSON. It was very nice to read at the end.


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


    ^^^^
    Reminded me of

    5824_a3d7_800.jpeg


  • Moderators, Computer Games Moderators, Social & Fun Moderators Posts: 79,825 Mod ✭✭✭✭Sephiroth_dude


    Would the following be considered a "Coding Horror"
    public void setFirstName(String firstName){
    	  
    	  if(firstName.length() < 5){
    		 
    		  throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! ");
    	  }
    	  this.firstName = firstName;
      }
    


  • Registered Users Posts: 1,042 ✭✭✭Rulmeq


    Would the following be considered a "Coding Horror"
    public void setFirstName(String firstName){
          
          if(firstName.length() < 5){
             
              throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! ");
          }
          this.firstName = firstName;
      }
    




    I worked with a guy who was tasked to code something similar, his first name was 2 letters (Wu), and I think they had the min set to 3 or 4. He wrote the code, because "it was a requirement" but the stupid really burns sometimes.


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


    Would the following be considered a "Coding Horror"
    public void setFirstName(String firstName){
    	  
    	  if(firstName.length() < 5){
    		 
    		  throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! ");
    	  }
    	  this.firstName = firstName;
      }
    

    Depends if you're handling the exception or allowing it to bubble up and blow the app up really.....


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


    Would the following be considered a "Coding Horror"
    public void setFirstName(String firstName){
    	  
    	  if(firstName.length() < 5){
    		 
    		  throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! ");
    	  }
    	  this.firstName = firstName;
      }
    
    It really depends on what sort of code you are writing.
    If its part of a gui app then above is fine, you'll have a handler for these situations and display an error to the user, since there is nothing that can be done in code to handle the error.

    If it's a shared component then I'd probably either add a throws to the signature or create my own exception class and again add the throws. It wouldn't be obvious that calling set on a pojo could explode since, typically, validation would be done earlier in the flow.


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


    Would the following be considered a "Coding Horror"
    public void setFirstName(String firstName){
    	  
    	  if(firstName.length() < 5){
    		 
    		  throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! ");
    	  }
    	  this.firstName = firstName;
      }
    

    A lot of Microsoft framework code in MFC does this kind of thing, though personally I avoid it where possible as the stack unwinds can cause a serious performance hit. I don't like the idea of exceptions for bad parameters but would use them at times to cancel out of very deeply nested code where the user hits a cancel button. Pressing the cancel button is a valid exception in this case as it is not the normal flow of events and the stack unwind is desirable. In this case, I place my try..catch blocks just below UI loop / main controller level such that the exception leaves me in a good default place to be. This depends on RAII to clean up via stack unwind, which won't always be the case, so memory and other resource leaks can arise.


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


    GreeBo wrote: »
    If its part of a gui app then above is fine...
    No, it's gick. PLUS it's not even trimming the white spaces out of the right side of the string. PLUS the exception isn't stating specifically if the first or surname is too short.


  • Registered Users Posts: 4,757 ✭✭✭cython


    Several hundred log statements along the lines of the below added in the last few days:
    logger.error("ClassName.methodName started");
    //Do some stuff
    logger.error("ClassName.methodName completed");
    

    Yup, debug/trace log messages being logged with severity of error. :mad:


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


    cython wrote: »
    Several hundred log statements along the lines of the below added in the last few days:
    logger.error("ClassName.methodName started");
    //Do some stuff
    logger.error("ClassName.methodName completed");
    

    Yup, debug/trace log messages being logged with severity of error. :mad:

    And your coding horror shows up a bug in boards. You wrote

    482141.png

    Chrome shows

    482142.png


    Nested coding horrors :pac:


  • Posts: 0 Jaxton Happy Pope


    smacl wrote: »
    Nested coding horrors :pac:

    Bugception


  • Registered Users Posts: 4,757 ✭✭✭cython


    smacl wrote: »
    And your coding horror shows up a bug in boards. You wrote

    482141.png

    Chrome shows

    482142.png


    Nested coding horrors :pac:
    And there I thought it was just my browser being an ass. Was also too f*cked off to dig further after finding that steaming pile of horse manure!


  • Registered Users Posts: 772 ✭✭✭pillphil


    Weird, it displays fine in my chrome browser on mint, but on mobile the original text looks wrong and the quote displays fine.

    Edit: Removed massive image


  • Registered Users Posts: 772 ✭✭✭pillphil


    Ha, it's an advertising thing, skimlinks, it reads the something dot something and tries to create a link. which ****s up the display


  • Advertisement
  • Registered Users Posts: 3,739 ✭✭✭johnmcdnl


    public class RandomGenerator {
      public static String generateRandomString(int numberOfCharacters) {
        String newStr = "";
        for (int i = 1; i < numberOfCharacters; i++) {
          int numericValue = (int)Math.round((Math.random() * 61.0) + 1.0);
          if (numericValue > 52) {
            numericValue = (0x2F + numericValue) - 52;
          } else if (numericValue > 26) {
            numericValue = (0x60 + numericValue) - 26;
          } else {
            numericValue = 0x40 + numericValue;
          }
          newStr += (char)numericValue;
        }
        return newStr;
      }
    

    It's really old legacy code, that is far away from the critical path, so fine maybe back in the 00s there wasn't any easier way to generate a random string than rolling your own?

    1) But why would you use hexadecimal in the addition of the numbers -- because who can't read hexadecimal right?
    2) And why does the returned string have length 1 less than 'numberOfCharacters' -- generateRandomString(4) returns a 3 letter string
    3) And just why would you not double check that the string returned is actually random. If you spend 2 minutes doing a quick test you'd spot that the letters 'A' and '9' are only returned half as often as all the other chars.


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




  • Registered Users Posts: 1,349 ✭✭✭GhostyMcGhost




  • Registered Users Posts: 24,211 ✭✭✭✭lawred2


    Would the following be considered a "Coding Horror"
    public void setFirstName(String firstName){
    	  
    	  if(firstName.length() < 5){
    		 
    		  throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! ");
    	  }
    	  this.firstName = firstName;
      }
    

    it would be the work of an idiot for sure

    where did he pull that business rule from?


  • Registered Users Posts: 4,325 ✭✭✭iLikeWaffles


    lawred2 wrote: »
    it would be the work of an idiot for sure

    where did he pull that business rule from?

    Must not like people named Paul


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


    Must not like people named Paul
    Worse still it's not cryptographically secure if Alice can't talk to Bob.


  • Closed Accounts Posts: 9,046 ✭✭✭Berserker


    lawred2 wrote: »
    it would be the work of an idiot for sure

    where did he pull that business rule from?

    Likely that he works in an organisation that has poor business analysis and people make up rules on the fly from time to time. The most senior dev in the place I work is a terror for it. Even makes up business rules based on her experience and logs them as bugs. Some of the rules are daft.


  • Registered Users Posts: 3,532 ✭✭✭swampgas


    Worse still it's not cryptographically secure if Alice can't talk to Bob.

    On the upside, looks like Eve won't get a look in either.


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


    https://www.theregister.co.uk/2020/01/08/boeing_737_ng_cockpit_screen_blank_bug/
    Boeing's 737 Next Generation airliners have been struck by a peculiar software flaw that blanks the airliners' cockpit screens if pilots dare attempt a westwards landing at specific airports.

    this comment


    270 degrees ?

    hmmmm

    tan(270) error infinite result?


  • Advertisement
  • Registered Users Posts: 6 typesafe


    Rulmeq wrote: »
    I worked with a guy who was tasked to code something similar, his first name was 2 letters (Wu), and I think they had the min set to 3 or 4. He wrote the code, because "it was a requirement" but the stupid really burns sometimes.

    Famous 40 Falsehoods Programmers Believe About Names:
    1. People have exactly one canonical full name.
    2. People have exactly one full name which they go by.
    3. People have, at this point in time, exactly one canonical full name.
    4. People have, at this point in time, one full name which they go by.
    5. People have exactly N names, for any value of N.
    6. People’s names fit within a certain defined amount of space.
    7. People’s names do not change.
    8. People’s names change, but only at a certain enumerated set of events.
    9. People’s names are written in ASCII.
    10. People’s names are written in any single character set.
    11. People’s names are all mapped in Unicode code points.
    12. People’s names are case sensitive.
    13. People’s names are case insensitive.
    14. People’s names sometimes have prefixes or suffixes, but you can safely ignore those.
    15. People’s names do not contain numbers.
    16. People’s names are not written in ALL CAPS.
    17. People’s names are not written in all lower case letters.
    18. People’s names have an order to them. Picking any ordering scheme will automatically result in consistent ordering among all systems, as long as both use the same ordering scheme for the same name.
    19. People’s first names and last names are, by necessity, different.
    20. People have last names, family names, or anything else which is shared by folks recognized as their relatives.
    21. People’s names are globally unique.
    22. People’s names are almost globally unique.
    23. Alright alright but surely people’s names are diverse enough such that no million people share the same name.
    24. My system will never have to deal with names from China.
    25. Or Japan.
    26. Or Korea.
    27. Or Ireland, the United Kingdom, the United States, Spain, Mexico, Brazil, Peru, Russia, Sweden, Botswana, South Africa, Trinidad, Haiti, France, or the Klingon Empire, all of which have “weird” naming schemes in common use.
    28. That Klingon Empire thing was a joke, right?
    29. Confound your cultural relativism! People in my society, at least, agree on one commonly accepted standard for names.
    30. There exists an algorithm which transforms names and can be reversed losslessly. (Yes, yes, you can do it if your algorithm returns the input. You get a gold star.)
    31. I can safely assume that this dictionary of bad words contains no people’s names in it.
    32. People’s names are assigned at birth.
    33. OK, maybe not at birth, but at least pretty close to birth.
    34. Alright, alright, within a year or so of birth.
    35. Five years?
    36. You’re kidding me, right?
    37. Two different systems containing data about the same person will use the same name for that person.
    38. Two different data entry operators, given a person’s name, will by necessity enter bitwise equivalent strings on any single system, if the system is well-designed.
    39. People whose names break my system are weird outliers. They should have had solid, acceptable names, like 田中太郎.
    40. People have names.


Advertisement