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
1202123252637

Comments

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


    Not exactly a horror, but it still made me go "huh?":
        switch (isValid)
        {
            case true:
                // do something
                break;
            case false:
                // do something else
                break;
         }
    


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


    Just been handed a new project with what initially seemed like a simple change request but ive had to spend the last two days trying to figure out how the whole project works and its insanely over engineered, I mean it could have been very simple but this guy seems to have written this code like he had to justify the amount of time he quoted for the work.

    And there is no comments, not just few comments or bad comments. There is not one single comment line anywhere in the code. Ahhhhhhh!!


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


    Ahh this project is driving me crazy. The guy who wrote it does everything in such an unintuitive way.

    Take this switch logic for example:
    private bool DoStuff(MyEnum value)
    {
        [B]UploadFilePath = "MyFiles1\PendingUploads";[/B]
    
        switch(value)
        {
            case MyEnum.Option2:
                UploadFilePath = "MyFiles2\PendingUploads\";
                break;
    
            case MyEnum.Option3:
                UploadFilePath = "MyFiles3\PendingUploads\";
                break;
        }
    }
    

    So the line in bold is only valid when its passed with MyEnum.Option1

    WTF, Just add it into the switch. I know its minor but when the code is full of these little quirks it wrecks my head.


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


    So the line in bold is only valid when its passed with MyEnum.Option1

    It's also valid if null is passed. Though this may or may not be desirable.


  • Registered Users Posts: 7,215 ✭✭✭Tow


    WTF, Just add it into the switch. I know its minor but when the code is full of these little quirks it wrecks my head.

    Old school developer style...

    When is the money (including lost growth) Michael Noonan took in the Pension Levy going to be paid back?



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


    UploadFilePath = "MyFiles1\PendingUploads";

    Bug found. Backslash required at end of file path above.


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


    It's also valid if null is passed. Though this may or may not be desirable.

    Enums cant be null. (Well at least they cant in C#)
    Wombatman wrote: »
    Bug found. Backslash required at end of file path above.

    Haha. Actually there is a bigger problem that i didn't escape the first \ and this wouldnt compile!! :D:D


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


    Enums cant be null. (Well at least they cant in C#)

    D'oh! My Java is showing. Though Java would throw a different exception because you can't have null in a switch.


  • Registered Users Posts: 1,463 ✭✭✭Anesthetize


    Wombatman wrote: »
    Bug found. Backslash required at end of file path above.
    Hard-coded file separators are a coding horror in themselves ;) File paths should be compatible with both Windows and Linux.


  • Registered Users Posts: 13,104 ✭✭✭✭djpbarry


    It's also valid if null is passed. Though this may or may not be desirable.
    ALWAYS check for null!!!

    Even if the above were true, default behaviour should be specified with the default keyword in the switch.


  • Advertisement
  • Registered Users Posts: 2,815 ✭✭✭SimonTemplar


    What the hell. WHAT THE HELL.

    Has this guy ever heard of returning an object?! Not to mention those multiple unnecessary db calls when he is only using one field each time! Ugh!
            private void processAddress()
            {           
    
                ....
    
                string addressline1 = getAddressData("addressline1", customerID);
                string addressline2 = getAddressData("addressline2", customerID);
                string addressline3 = getAddressData("addressline3", customerID);
                string addresscity = getAddressData("addresscity", customerID);
                string addresscountry = getAddressData("addresscountry", customerID);
                string addresspostalcode = getAddressData("addresspostalcode", customerID);
    
                ....
    
            }
    
            private string getAddressData(string dataToGet, string customerID)
            {
                string query = "SELECT addressline1, addressline2, addressline3, addresscity, addresscountry, addresspostalcode FROM addresses WHERE customerID = " + customerID;
                string dataToReturn = "";
    
                if (this.OpenConnection() == true)
                {                
                    MySqlCommand cmd = new MySqlCommand(query, connection);                
                    MySqlDataReader dataReader = cmd.ExecuteReader();
                    
                    while (dataReader.Read())
                    {
                        switch (dataToGet)
                        {
                            case "addressline1":
                                dataToReturn = dataReader["addressline1"].ToString();
                                break;
                            case "addressline2":
                                dataToReturn = dataReader["addressline2"].ToString();
                                break;
                            case "addressline3":
                                dataToReturn = dataReader["addressline3"].ToString();
                                break;
                            case "addresscity":
                                dataToReturn = dataReader["addresscity"].ToString();
                                break;
                            case "addresscountry":
                                dataToReturn = dataReader["addresscountry"].ToString();
                                break;
                            case "addresspostalcode":
                                dataToReturn = dataReader["addresspostalcode"].ToString();
                                break;
                        }
                    }                
                    dataReader.Close();
                    this.CloseConnection();
                }
                return dataToReturn;
            }
    
    


  • Registered Users Posts: 1,717 ✭✭✭Raging_Ninja


    found this at work (variable names obfuscated of course):
    bool  wtf =  omg != true ? (ffs != true ? (fml != true ? true : false) : false) : false;
    


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


    found this at work (variable names obfuscated of course):

    They could have at least done
    bool wtf = !omg ? (!ffs ? (!fml ? true : false) : false) : false;
    


  • Registered Users Posts: 778 ✭✭✭pillphil


    They could have at least done
    bool wtf = omg ? false : (ffs ? false : (fml ? false : true));
    


    What are they trying to say here?

    !omg && !ffs && !fml?


  • Registered Users Posts: 1,717 ✭✭✭Raging_Ninja


    pillphil wrote: »
    What are they trying to say here?

    !omg && !ffs && !fml?

    Well, thats what I turned it into anyways.


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


    found this at work (variable names obfuscated of course):
    bool  wtf =  omg != true ? (ffs != true ? (fml != true ? true : false) : false) : false;
    

    Jesus. Haha.


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


    Started a new project last week. Summary of the project would lead you to believe its a very straight forward thing which i can knockout in a few days.

    I just needed to interface to another companies API and they have a published WSDL. What could be easier!!!

    Where to begin:

    1. The API has 1 method defined
    string responseXML DoTransaction(string xmlRequest)
    

    Thats enough to boggle the mind.

    The obvious next problem is getting them to send me detailed information of the xmlRequest and response! Many many emails later with varing spelling and casing in the xml they send me a valid working example.

    Ok Progress.

    2. The responses. Logic would make you think that the response format should be consistent. But no. Depending on the request made the spelling and casing of the xml changes so im going to have to write a specific deserializator for each request type to take into account their xml response with different spelling and casing.

    ahhh!! idiots.

    3. Success and Failure responses. The response contains a response code, response message. You would think that the response message would be error when it fails, but no it says success even when the error code indicates failure.

    4. Jesus, just found another one. Depending on the type of error encountered the casing of the xml in the response changes. FFS. Am i going to have to write some kind of case insensitive deserializer for this ****.

    5. One more, their parser throws a parser error if you include an xml declaration at the start of your xml. F


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


    2369_ccf1_500.jpeg


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


    Wow. Looks like a Java programmer with Python envy.


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


    Wombatman wrote: »
    2369_ccf1_500.jpeg

    WTF is that. That must have been someone leaving the company pissed off.


  • Advertisement
  • Registered Users Posts: 1,717 ✭✭✭Raging_Ninja


    WTF is that. That must have been someone leaving the company pissed off.

    Waste of time if so, most IDEs have an auto indent feature.


  • Registered Users Posts: 428 ✭✭[Rasta]


    My manager for the third/fourth time in a few months sent me some TSQL code and asked whether it was close to following our coding style.
    As I had previously noted to the manager that the stuff they checked in was unreadable.

    This is basically what I was sent:
    select
    	john as Doe,
    	
    	a.jim_meab [hmm]
    ,dat.another_field [an_fi]
    ,dat. RANDOM_STUFF AS [an_fi1]
    ,dat.whatisgoingon [an_fi2]
    		,OHMYGOD 
    		as ineedhelp,
    		dat.makeitstop
    	from mytable a
    inner JOIN dbo.cheese ON cheese.somevalue = a.anothervalue
    	LEFT OUTER JOIN
    	
    	(select morestuff x	
    		, table.copypasta CopyPasta, goodluckreading.THIS
    		from stuff left join table on stuff.x =
    		table.y			
    			LEFT JOIN goodluckreading ON table.y = myotherval
    		
    				) dat on x='1' 
    and copyPasta=otherthing
    	WHERE
    	copypasta IS not null
    


    After, I didn't reply, the manager came over and asked about it, I said NO and I turned my head back at my screen.
    What the hell?


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


    [Rasta] wrote: »
    My manager for the third/fourth time in a few months sent me some TSQL code and asked whether it was close to following our coding style.
    As I had previously noted to the manager that the stuff they checked in was unreadable.

    This is basically what I was sent:
    select
    	john as Doe,
    	
    	a.jim_meab [hmm]
    ,dat.another_field [an_fi]
    ,dat. RANDOM_STUFF AS [an_fi1]
    ,dat.whatisgoingon [an_fi2]
    		,OHMYGOD 
    		as ineedhelp,
    		dat.makeitstop
    	from mytable a
    inner JOIN dbo.cheese ON cheese.somevalue = a.anothervalue
    	LEFT OUTER JOIN
    	
    	(select morestuff x	
    		, table.copypasta CopyPasta, goodluckreading.THIS
    		from stuff left join table on stuff.x =
    		table.y			
    			LEFT JOIN goodluckreading ON table.y = myotherval
    		
    				) dat on x='1' 
    and copyPasta=otherthing
    	WHERE
    	copypasta IS not null
    


    After, I didn't reply, the manager came over and asked about it, I said NO and I turned my head back at my screen.
    What the hell?

    Does your coding style match any auto format tools? Maybe suggest they just run it though an auto format tool.


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


    Just wasted some time trying to workout why i was getting versioning issues. Some muppet put the assembly version into the visual studio csproj file for an unknown reason. Still not sure why this is causing problems because all the version numbers match whats in the assemblyinfo.cs


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


    ExtJS 4.2.1 nuff said!


  • Registered Users Posts: 5,982 ✭✭✭Caliden


    Waste of time if so, most IDEs have an auto indent feature.

    Exactly. Alt+Shift+F would instantly make that mess readable.
    Of course the repo entry would record a ****load of formatting changes


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


    0631_ca84_960.jpeg


  • Registered Users Posts: 2,781 ✭✭✭amen


    love it


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


    Hate to be that guy. But a find and replace would fix that fairly easily.


  • Advertisement
  • Registered Users Posts: 1,717 ✭✭✭Raging_Ninja


    Nah, just examine the IL code or whatever it is compiled into.


Advertisement