Sunday, April 10, 2005

TDD Bash scripting

I've decided to finally start writing some scripts for the mundane tasks that I seem to have to perform from time to time. I really haven't written many Bash scripts, though I've been hanging out on Linux for more than 10 years now. But I'm sick of the time wasted on a few tasks recently, so its time to do something about the lack of scripting.

Now, I'm not exactly doing TDD as such. I'm not writing any automated tests. But I am approaching the script writing as if I were. I've taken a specific task and scripted it. Made sure that it performs in the way I expect it to. Then I've refined it. Makes this all too easy. The script is barely a screenful with comments, so I'm not fussed about the lack of testing. If it were more, I'd be getting a bad feeling in my gut, I'm sure.

So now I can type one command and save time and effort. The script smells a little bit, but I can live with the smell for the time being (at least until my knowledge of Bash improves, which may be never...).

Thursday, April 07, 2005

Site Feed

Now that I'm getting a bit of traffic, I should mention that there actually is a site feed for this bog. I've turned it on, but it isn't showing up on any pages that I can see. Do I have to change my template?!? Can anyone point me on the right direction for this?

Wednesday, April 06, 2005

No longer just a backwater blog...

A bit of an exaggeration, but I've noticed a bit of traffic from Rob Harwood's blog, from this post in particular. I feel the need to respond to Rob.

Firstly, I wouldn't say that I'm reluctant about discovering IntelliJ. The smart people I know use IntelliJ. I want to know why. I've asked them in the past and none of them has ever been able to give me a better concrete answer than "It's just really good". And now I can understand why.

IntelliJ just seems to do all the small things right, or at least better than any other IDE I've used. But then I would have said the same thing about Eclipse the first time I used it as well. And all those small things are sometimes hard to capture and enumerate when someone queries you on why the IDE is better. It just is.

Now, maybe I can get an license in exchange for my endorsement? 8)

Tuesday, April 05, 2005

TDD Progress

I spent one hour last night doing some more TDD. It didn't feel productive and it wasn't exactly comfortable. But, I managed to cross off 3 more tasks, which was a bit of a surprise. Even though it didn't feel productive, it really was, because I have judged productivity in the past based solely on implementation. I've designed, implemented and refined 3 tasks, not just implemented.

I've got 3 task left, but a couple are big vague tasks that I've been shying away from, so I expect the list to grow out again after the next session (whenever that might be).

The uncomfortableness is because of the (bad?) habits I've developed over the numerous years developing software. This may be uncomfortable, but I'd have to say that I'm hooked! Now if only my current job actually required me to do some actually coding...

BTW, I'm starting to get the feel for IntelliJ. It's hard to put into words, but it's starting to grow on me. I fear that by the 29th I'll be in a position where I'll find living without it may be hard to do.

Sunday, April 03, 2005

Red Bar/Green Bar/REFACTOR, Red Bar/Green Bar/REFACTOR ...

Ok, now I'm really starting to get the TDD realization. I've been reading "Test-Driven Development: By Example" and thinking about how I have been approaching things. I had been refactoring a small project to get it to the point where I could then start writing unit tests for it.

After reading part I of the book for the third time and starting to consume part III, I decided that the best course of action would be to forget about the legacy code and just start from scratch. And to make things interesting, I'd change my IDE at the same time. 8)

Anyway, I wrote a list of 7 small chunks to start the implementation with using TDD. The first cab off the rank was to write a Button state object that would track a button's mined, flagged, exposed and questioned state. I wrote the tests first, I wrote the code to compile and then I fixed the tests. I took large steps, but not so large that I felt I was without a net.

In the end, I had a class with 4 boolean fields and 2 methods for each field. One to check the current state and one to set or toggle the state. 50 lines of code. At the time, I really couldn't see the duplication clearly in this, but I felt that the implementation had a bad smell. I hesitated briefly on the refactoring until I gained the courage to continue realizing that I could just role back to where I started from if things got worse.

After a few minutes of adding a few things and refactoring the tests to actually test the new refactored code, I ended up with a class with 40 lines of code. I wasn't too excited about the change in size, but I had focused on the size to begin with. Then I looked over the code and noticed no more smell. It all just happened so easily.

(In writing this I want back to look at the code, only to realize that I had left 4 of the original fields in the code, so in actual fact there are only 34 lines of code.)

What I now have is a class with 5 fields, one boolean[] with 4 elements and 4 static final ints for each property of the button. But instead of 8 methods, I now have 3 methods and one constructor. The code reads better and has a certain beauty to it. All is right in the universe of my implementation and I am happy. And once I had finished, it dawned on me what the duplication was. I think I've developed an intuitive sense of bad smells without having a good concrete grasp of why I sense the smell. It was easier for me to sense the smelliness of the code than to see the duplication. Once I'd removed the smell, the duplication was obvious.

Now I can see the wisdom in ditching the legacy code. Trying to remodel something that already exists was going to be more time consuming and lots of unrewarding efforts for very little value. Instead, I'm leveraging TDD to get what I really want quickly and easily. (I feel like I'm stating several obvious observations, but I don't think that there were so obvious to me only a week ago.)

So, I must not forget to refactor. In fact, I think it will be hard for me not to hit the refactor step. I've always tried to simplify my code over the years, long before I'd heard the term refactor. Now I have an excuse for the aesthetic that I seek.

IntelliJ, etc.

Ok, so I'm actually using IntelliJ to do some TDD. And compared to Eclipse, it is resource hungry. It is slow and not as responsive as Eclipse can be. The box I'm using at the moment is a bit low on memory, only 256Mb, but that's because I had a box die on me and had to use the current one as a back up and it only has one memory slot. (It's an HP e-Vectra I picked up at a computer auction for < $150 about a year ago.)

I think the power supply just died, but I haven't tried to isolate the problem. Now I'm starting to get motivated to do so. I really should just buy a new computer. The e-Vectra is the newest machine I own and it is 4-5 years old. I'm obviously not big on hardware. 8)

IntelliJ, take 2

Ok, it all works now. Just deleted the project I had and started fresh. It seems to work now. I think reading some of the documentation was a good idea as well. One bad point, I couldn't read the online documentation and follow through on the instructions because creating a new project popped up a modal dialog. This prevented me from scrolling the documentation page. Still not impressed yet...

Saturday, April 02, 2005

IntelliJ

I've heard a lot of smart people rave about IntelliJ. So I've downloaded a copy and have an evaluation license. 30 days is not long enough for me to evaluate something that is going to cost we several hundred dollars to "buy" when I am not using it full time.

That said, how do I create a new class in IntelliJ? I'm assuming my own stupidity is preventing me from doing the obvious...