Tuesday, July 14, 2009

Refactoring - Sometimes it gets messy before it gets clean

Recently I tweeted.
About to put my refactoring skillz to the test. The challenge a 27,000+ line "class" for a delphi CGI.


I am still working on this little side project and it has been pretty fun so far. One thing for sure is that just like many cleaning projects it always seems like it gets a bit dirtier as you throw stuff around before the project gets cleaner. Right now if I just checked in my code it would be bad, very bad. The code is brittle at best and the coupling between modules is so high it might reach into space. But hey it is just a first step and what does this first step look like?

It follows the general advice to look for similar functions and put them in their own code files. Note I did not say class. Since I have so much code to wade through I did not want to figure out on my first step all of the places I had to instantiate a new object and call it, plus I would have probably gotten the class wrongly designed in the first place. So, I mainly just referenced the different code files in the main class and made them static methods for the time being. Some of the code files turned into what would be expected like file utilities (deleting temporary files, writing to common locations, etc..), HTML utility methods, etc... I am not a huge fan of utility "classes" but wading through 800 lines of utility code and figuring out a design for common items is tons easier than wading through the gigantic mud-ball that currently exists.

Once I moved a few of these general functions around I started on something that would make a bigger impact and would be a little tougher. You have to understand one thing about Delphi is that it is a RAD language I don't mean it is cool I mean it is a Rapid Application Development language, what does that really mean? It means it turns into a huge event-driven mess that makes grown men cry when a button event, updates a field, which fires an update event, which updates a field which updates some dataset which then fires another event, you get the idea. All of these reports had events tied to them which meant a lot of code to move and a lot of interdependencies that would be "fun" to move, but hey I was up the challenge :). I did what any sane code-junky would do I copied the report objects into a new class and then leaned on the compiler like I had just finished a fifth of vodka on my own. To get the code to compile and be functional I had to pass in a reference to the monster class. This means there was now a recursive dependency between the two which is not prime but like said earlier it is a start and this was one of the messy parts of the code. To give you an idea on the interdependencies I tried to pass in the needed parameters for a method but I gave up after the parameter list grew to 15! Once I got this area to compile I then did some quick functional testing to make sure the program was you know still usable.

At this point I had shuffled around 4,000+ lines of code and things where looking slightly better and there was at least a glimmer of hope. What are my future steps? I plan to continue to look at the methods in the monster class and bucket them out to code files. After that I will start to move them into classes, implementing interfaces and hopefully writing some tests. I will write about my progress at each step of the way. If there are any questions on how I am doing something or advice from other people who have tackled similar monster classes that would be awesome.

Labels:

Sunday, June 28, 2009

Good times ahead

As many/all people who read this blog know I have been doing freelance work on the side for the past five years. Many of those years I would say stupid shit like "once it gets a little bit busier I will go on my own." Realizing that is a bit like saying "once I get XXX amount of money I will be fine" (which is never true, btw) I worked out a middle ground with my lovely fiancee and am going on my own as a freelance developer/hacker starting on Wednesday. It is pretty exciting and scary all at the same time.

What does this mean for whoever reads this blog? Not too much. I will still post here but I am also going to be creating a company blog in the next few weeks. I am not sure if I will cross-post or what but I would expect that this blog will have a bit more of a personal flavor to it. Well wish me luck because I will need it! :)

Labels:

Thursday, May 28, 2009

Do you care what you are doing?

I have had this exact phrase being bounced around in my head for the last month or so. As I am out in the working world more it seems that the people who go farther and have a better attitude have one similar thing in common. That thing in common is caring about the work they are doing. Sure, they might not exactly like the task they are currently doing but over all they care about the overall goal of their work. It is very easy to just get a job and not move it forward and complain about how it is and not improve anything. It is another thing to try and push it forward or bring some positive influence into what you are doing. I know people who even think the profession they are in is B.S. but they want to change the field. Sure it might take them 10+ years but even moving one little step closer will keep them energized. I get this way at my day job, the development environment sucks and I will have my bad days where I am cynical but the majority of days I try and remember to improve it in some little way. I don't even think technical skills are as important as actually caring in a field, however, I have a hunch anyone who cares is not lacking in the technical area as well.

I am not saying everyone has to care about their job I am just saying this seems to be what I have noticed for the people who draw people together, seem to create the "cool" things and are known as being very good. Maybe this is what some people use the term "passion" for but I feel they are different. Passion to me seems more like someone who won't give up on an idea and that is the only thing they are focused on and will talk about it all of the time. Whereas caring just means you want to improve a specific thing and don't want to see it get any worse.

Well, it is just a thought that I have had for a bit it might be crap or it might be good, I am sure it isn't original but I figure I would write about it any ways :). Time for another coffee!

Labels: , ,

Wednesday, March 18, 2009

TED Talk - Why we should play

If you are stuck up or just need an excuse to play around watch this video:


Maybe I should show this video to my boss when he looks at me funny for doing cart wheels or skipping down the hall. But it is sure fun :). I know you can't play / goof off all of the time but I find that people are way too damn serious all the time. It is like most people think they should be conservative and not goof off once they leave high school and/or college give me a break. Especially in this day and age we should all laugh at stuff and goof off. Ok enough of my personal philosophy :).

Back to work..

Labels: , ,

Sunday, March 08, 2009

Cult of Done Manifesto

This is just awesome...

http://www.brepettis.com/blog/2009/3/3/the-cult-of-done-manifesto.html

Sunday, February 01, 2009

Article on Solitude

I just finished reading this article on solitude. I found it gave me something to chew on for a bit. I am still trying to figure out if I completely agree with his ideas or not. I can understand where he makes his conclusions from. Well if you have a few minutes it might be worth the read.

Labels: ,

Friday, December 19, 2008

Funny TED Video

My Dad introduced me to TED and I have been watching the videos off and on, many are great and a few just stick with me. Like the one below:





It is only 9 minutes and will at least make you crack a smile.