When to give-up changing your code and start over

Lately I have been fighting with a small XSL job in a simple task of alternating rows. I was changing a code that originally wasn’t mine and trying to re-use most of the functions, but sometimes is better just to start all over again.

The schematic of the process was simple:

Get the XML nodes in the date range and for each unique day get all nodes and print. All I needed to do was to change the colors of the tables rows to have a table with alternating rows colors to give a better impression on the information that the table was displaying and to use as guide, but with the current format used (get xml nodes in the date range and for each unique day get all nodes) I could easily swap colors between days, but not between inner nodes.

This seems simple when you are not working with XSL. XSL is a great language to allow different format for the same data coming from a XML, but it’s a very simple language as well. One of the concepts of the language is that variables should be interpreted as constants, therefore you cannot reset a variable. This was one of my issues in order to use the previous methods. I could not reset a flag to tell me what was the color of the last row, before the next set of nodes started.

After trying to work around for a while and getting somehow frustrated with all of this I decided to start over.

Start over should always happen whenever you just can’t work with the current structure and you need to create a new one. The problem with starting over is that it actually takes some time to create all again and in the corporative world that we live today, time is something that you just don’t have.

For my luck I had a couple hours before placing the new format in production and I have created the methods again. The methods now are not as complex as they where before. The concept changed to loop nodes in date range and nodes inside that unique day to loop into all inner nodes inside that date range. Making the structure a bit simpler I could manage to alter the rows inside the XSL.

If you are wondering when to start over with your code, I must say, there is no easy answer, but the best moment is when you truly believe that you have exhausted your options and you still have enough time or can deal more time to rewrite the code.

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: