My Mental Laziness Mistakes

0 comments suggest edit

It wouldn’t be fair to point out the mistakes of other developers being lazy without pointing out that I have been very guilty of this myself. The point of the post is not to trash another person’s coding habits, but to present an ideal to work towards. Sometimes, intellectual “laziness” is absolutely necessary as in the example presented in the comments of that post.

When I started off as an ASP developer (remember VBScript?) I needed to store name value pairs within a cookie. So I started off storing a string like so in the cookie.

Response.Cookies("ChocolateChip") = "name1=value1,name2=value2,..."

But I ran into an issue that some of the values contained commas, so I chose a delimiter I was sure would never be in the content…

Response.Cookies("ChocolateChip") = "name1=value1*&*name2=value2*&*..."

And proceeded to write a butt load of string parsing code to insert and extract values from the string, making sure not to insert duplicate names, etc…

Of course later, I got around to reading more about Cookies in ASP.NET and I discovered that you can create cookies with keys. So the ugly code above became…

Response.Cookies("ChocolateChip")("name1") = "value1" Response.Cookies("ChocolateChip")("name2") = "value2" '...

Had I spent a few extra minutes up front reading about cookies rather than programming by intellisense, I would have saved myself a lot of time. In the end I ripped out my code and used the built in mechanism.

<blatantLie>To my defense, I was only five at the time and I had been hit by a bat earlier that day so I was seeing double.</blatantLie>

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

2 responses

  1. Avatar for Marty Thompson
    Marty Thompson September 18th, 2005

    I made a somewhat similar mistake when I was 5(what a coincedence!). I implemented a Split method in C#(although I called it a tokenize method, having come from a heavily java-based computer science program). It did exactly the same thing that the built-in String.Split method did, but worse. I remember having a bug somewhere in my algorithm, and a co-worker of mine took a look at my code to help me, replaced about 15 lines of code with:



    stringVariable.Split(',');



    I was of course embarassed at my gaffe, even more so now looking back on it.

  2. Avatar for Haacked
    Haacked September 19th, 2005

    Well we'll keep that one between ourselves. ;) We can start a therapy group, "Developers who have implemented methods that already exist."