Encapsulation, who needs it?



  •  I recently took over a project from a guy who had been working at our company, he'd managed to create a "proof of concept" which actually "worked" but he'd subsequently been let go before the end of his trial period.  When i fired up the project to take a look at the code i decided it was a throw out and rewrite kind of deal. 

    Our product has a fairly substantial API written for it which caters for operations like saving and loading our objects to various sources etc.  This guy just didn't seem to get the whole include a dll and reference it then call methods on it.  Instead he would check out the API source from the repository then just cut and paste it into his project.  We're talking 200 lines of code pasted straight from our data access layer into a button click event, need to call it from the file menu?  That's cool just cut and paste it again, after all methods are for suckers.

      Apparently all his code was like this, no matter how much he was shown that instead of copying code from the API etc. you could include it and do stuff like SqlDataAccessLayer.Save(someObject) he would just continue to copy and paste code into his forms.  The sad thing is this guy wasn't a graduate programmer, he obviously just missed some fundamentals of programming along the way and just wasn't willing to learn a better way.  In the end his style of coding ended up being the main reason he left.

    When looking through his source(which was massive) and all conveniently dumped in one class called "Form1" I did find this line in his source which made me laugh and reminded me of our old friend paula. 

    wordDoc.PackageProperties.Title = "STAN IS AWESOME!"; 

    Yes you are, almost as brilliant as Paula

     another gem i found:

    Why do this

    string month = DateTime.Now.ToString("MMMM"); 

    when you can do this

    private string getMonth(int month)
            {
                string returnMonth = "";

                if(month == 1)
                    returnMonth = "January";
                else if (month == 2)
                    returnMonth =  "February";
                else if (month == 3)
                    returnMonth =  "March";
                else if (month == 4)
                    returnMonth =  "April";
                else if (month == 5)
                    returnMonth =  "May";
                else if (month == 6)
                    returnMonth =  "June";
                else if (month == 7)
                    returnMonth =  "July";
                else if (month == 8)
                    returnMonth =  "August";
                else if (month == 9)
                    returnMonth =  "September";
                else if (month == 10)
                    returnMonth =  "October";
                else if (month == 11)
                    returnMonth =  "November";
                else if (month == 12)
                    returnMonth =  "December";

                return returnMonth;
            }

     

    I got the impression from reading his code he just didn't trust code he couldn't see.  



  • the REAL wtf is not using a switch to decide which month to fetch



  • Let me guess: the only part where getMonth() was used was in a loop that counts from 1 to 12?



  • @element[0] said:

    In the end his style of coding ended up being the main reason he left.

    The guy copy-and-pasted API methods instead of calling them and you feel it necessary to explain that his style of coding was the main reason he left?  I mean, if that's just the "main reason", I'd hate to ask if there were other personal problems, like him coming to work in a bathrobe and doing bong rips in the copy room. 



  • @morbiuswilters said:

    personal problems, like him coming to work in a bathrobe and doing bong rips in the copy room. 
    Which reminds me.  I need to make sure I wear pants to work tomorrow.  Fucking slavedriver boss says I have to wear pants or I'll be fired.



  • @belgariontheking said:

    Which reminds me.  I need to make sure I wear pants to work tomorrow.  Fucking slavedriver boss says I have to wear pants or I'll be fired.

     

    Yeah but walk around with your fly undone anyway just to stick it to the man 



  • @element[0] said:

    Yeah but walk around with your fly undone anyway just to stick it to the man 

    Knowing btk, he's more likely to be sticking to shreds of Kleenex and used hypodermic needles.



  • @morbiuswilters said:

    Knowing btk, he's more likely to be sticking to shreds of Kleenex and used hypodermic needles.
    You think that would work?  cuz I got loads of those sitting around.  It certainly would be easier than mugging someone for a pair of pants.



  • @belgariontheking said:

    Which reminds me.  I need to make sure I wear pants to work tomorrow.  Fucking slavedriver boss says I have to wear pants or I'll be fired.
     

    Thanks for derailing another thread.



  • @MasterPlanSoftware said:

    Thanks for derailing another thread.
    You're welcome, kind sir.



  • @Pjotr G said:

    the REAL wtf is not using a switch to decide which month to fetch

    A static array would be, IMHO, a better choice.



  • Ah, yes!

    case 1:
        returnMonth = monthArray[1];

Log in to reply