Bad Code – Snippets from production

True, false … or maybe?

Lets start with something on the funny side. Some of the code that I have come across in our system.

boolean isFutureDeal = Boolean.parseBoolean(request.getParameter("loadFuture"));
if(isFutureDeal != true){
       isFutureDeal = false;

If it’s not true, set it to false. I guess this is to make sure it isn’t set to that other boolean value – true, false, maybe.

Give me that.  What?!  I don’t need that.

public ShoppingCart createNewCart(ShoppingCart cart, HttpSession session,
                     MiniUserBean member) throws Exception {

              if (cart == null) {
                     session.setAttribute("shoppingCart", new ShoppingCart());
                     cart = (ShoppingCart) session.getAttribute("shoppingCart");
              cart = (ShoppingCart) session.getAttribute("shoppingCart");

The cart object is passed in, but the first thing we do is read it from the session, so why even pass it?

Day of the week calculation

[pseudo-code...actually seen in production]
if (date == "11/28/2016" || date == "12/5/2016" || date == "12/12/2016" 
     || date == "12/19/2016" ...) {
          dayOfWeek = "Monday";
} else if ( date=="11/29/2016"...

You get the idea.  There were about 1/2 year’s dates in the if statements.  I found out about this gem when a customer called and complained that their script was not setting the day of the week any longer.  This was in perl, and I replaced that huge block with a few lines that would forever compute the day of the week.


Merry Christmas & Happy Holidays

Happy Holidays to all of my readers out there!

I really enjoy writing the blog posts, but I have simply not been making the time to do them.  I tell myself it is because I am very busy, but that is a lie to make me feel better about not doing it.  I am simply not making the time.

In the new year, I am going to be the kind of blogger that posts at least once per month.  I hope to be the type of blogger that posts more often, but I want to make sure that what I am posting is of quality.

Podcast Quickie: Some podcasts I have been listening to

I am always searching for good podcasts to listen to, especially technical ones.  So, I thought I would share the few that I am listening to on a regular basis (technical and non-technical).

Ruby Rogues: Even though I am a Java developer (and they have a rather negative opinion of Java), I have found this podcast quite good.  They talk a lot about Ruby and related technologies, but they very often talk about things that go broader, like testing in general, being a good developer, etc.  Highly recommend.

Skeptics’ Guide to the Universe: This is a general science-y podcast.  They talk about new things happening in science, about the “forgotten superheroes of science” and have a contest where they try to trick one another with fake science stories.  Fun to listen to.

Wait Wait… Don’t tell me: While I am not generally a fan of NPR (dry and boring) I really enjoy this show.  It is funny and informative.  Give it a listen.

If you have any podcasts that you would recommend, please feel free to leave them in the comments.

And so it begins…

This will be a place to post our musings of software development and working in the software development industry.  We are software developers and husband and wife.

About Blair –
I work at a loyalty and incentive company that provides programs similar to what credit card companies have (earn points by using your card, and redeem the points for a variety of rewards). I started with the company early in its’ life, before they actually had a product to sell, and helped build the application platform from the ground up. I have grown with the company over the last 10 years. In the early days we were really focused on getting the application working and adding new functionality – really without regard for code quality, capacity planning, maintenance time, etc. Now we are much more concerned with these things and spend quite a bit of time optimizing for increased capacity, making maintenance easier, etc.
I also helped move the development process from waterfall to an Agile (Scrum) methodology. I’m a strong believer in Agile processes and I’ve been working to improve our processes and empower the team members – which is not always as easy at it sounds (and it doesn’t sound easy).

About Becky-
I have been developing software professionally since 1998.  I have worked in a number of industries using both waterfall and agile methodologies.  When I started working, I simply wrote the code needed to get the job done.  I didn’t understand a lot about good architecture, clean coding, etc.  I sometimes considered myself a ninja coder, because I could sneak in and make the change without disturbing the rest of the code.Nearly a decade ago, I started learning more about agile methodologies, clean coding, design patterns, etc.  I was lucky enough to land a job with a couple of amazing developers who had been practicing these things for a while.  Working with them doing extreme programming really accelerated my learnings and my passion for this approach.
I consider myself a software craftsman now.  I am very passionate about creating quality code that is well tested and maintainable.  I also believe very strongly in the agile methodologies as a way to help ensure that the work that is done is done well.

What’s Covered in this Blog?
We don’t want to limit ourselves to one specific topic, so we’ll have posts about Agile/Scrum, Code Craftsmanship (code quality, clean code) – including examples of what NOT to do, and anything else that we think might be useful to others.