Monday, February 26, 2007

Where are all the fancy schmancy graphics?

And where are the real links? We mention a lot of stuff here and we never seem to link up the stuff.

No graphics. No links.

I would love to add a bunch of sweet looking eye candy to this blog but the reality is that I suck at graphics. I could spend hours putting graphics together but I'd much rather spend it doing something else. Like writing here. Or playing guitar. Or playing a board game. Or watching the Osca...er...wait. I'd rather make graphics than watch the Oscars. But not American Idol! I'm a sucker for that show.

As for the links? I'm still not sure I want to litter my blog with tons of links. They're distracting in a paragraph and usually take something away from the meaning of it. They focus the reader on the links rather than other parts you may want to emphasize. I'll try to make them more subtle with the CSS and if that doesn't work I may put the links at the end of the text in each blog entry.

Friday, February 23, 2007

FYI, I've opened the comments to anonymous users. If this becomes a problem I will have to change it back to registered users only. Let's hope for the best!

Decaffeinated

A couple weeks ago I had a life changing event. I was home alone with the kids and completely out of Pepsi. I don't drink tea or coffee so I tried to go without the caffeine. I was doing alright until about 1 o'clock when I started getting the dreaded lack-of-caffeine-headache. At that point I should have packed the kids up, gone to the store, and gotten some caffeine. But no, I decided to stay the course and wait for my wife to come back with some Pepsi.

Bad plan.

The headache kept getting worse. By the time I finally decided to take some ibuprofen for it I realized we didn't have any of that either. Shortly after that my wife arrived with some Pepsi which I quickly opened up and gulped down. Then I went to lay down for a while and wait for the headache to go away.

Wrong.

It kept getting worse. And I had to go to the bank. I grabbed another Pepsi and went up to the store to buy some Ibuprofen. My headache was so bad at that point my vision was starting to deteriorate. Fortunately the grocery store is only a few block away. I got the pain killers, went back out to my car, took 3 or 4 and slammed down some more Pepsi. Then I proceeded to the bank -- painfully. When I got there I felt like throwing up but they didn't have a public restroom (small town bank). So I finished my business there and went back home. When I got home I lied down for a short time and the nausea went away.

After a while I was finally able to sleep. A couple hours later I awoke to a very minor headache and an incredibly valuable lesson learned.

There's really no punchline to go in here. It was the most miserable day in recent memory. I don't get migraines but I suspect what I got was much like one. I don't think I have ever felt pain that bad in my life. The lesson?

Caffeine wreaks havoc on your body.

On that day I vowed to myself that I would never have that kind of reaction again to the lack of caffeine and the only way to do that was to break my addiction. Was it a combination of factors? Possibly. But it certainly wasn't worth taking that risk.

So I quit. It took a long time to do it and it wasn't without moments of minor headaches. I had to slowly wean myself off of it. Every day I'd drink less caffeine and wait longer between feeding it to my body. Eventually my body adjusted, grudgingly.

It's Friday and I had a Coke this morning. Before that I had one Wednesday afternoon. Before that it was Tuesday morning. I didn't drink one this morning because I was getting a headache. or because I'd get one if I didn't . I drank it because I like the taste. But I realize that if I have another one today I could fall into bad habits. This isn't going to be easy. When this 12-pack is gone (only 2 left) I'm going to get decaffeinated cola drinks. That'll be good.

The caffeine is still pulling at me. I'm craving one right now. But I'm not going to risk getting that kind of headache again. Not ever.

Monday, February 12, 2007

Memory Management: C vs. Java

Like many other companies, the company I work for decided to move from C to Java. There were a lot of good reasons for the switch. One of the biggest reasons was that we could ditch manual memory management (malloc(), free(), etc.) for automatic memory management (garbage collection).

Garbage collection is usually marketed as having the following advantages:

  • No memory leaks
  • Less development time spent on memory management

Let's examine these claims in more detail.

No memory leaks?

It's not really entirely true that garbage collected languages have no memory leaks, depending on your exact definition for "memory leak". Here are a few ways you can still leak memory in garbage collected languages like Java:

  • Accidentally keeping object references in collections.

    Garbage collected languages induce a false sense of security in many developers. I've seen code that leaks memory by the megabyte because of developers forgetting to remove object references from collections when they're done with those objects.

  • Forgetting to release non-memory resources which themselves have allocated memory "under the covers".

    Many APIs, such as AWT, Swing, and JDBC are partially implemented in native code. That native code often allocates memory from the operating system. If the application fails to release one of these kinds of resources, memory is leaked more often than not.

It's worth pointing out that I'm not suggesting garbage collected languages are just as likely as non-garbage collected languages to leak memory. I'm just trying to show that garbage collected languages can also leak memory.

Less development time spent on memory management?

There's no doubt that it takes more time to write software that does manual memory management. After all, those developers have to take the time to think about when memory resources can be safely disposed.

There's also no doubt that developers will likely spend less time fixing memory leaks in garbage collected programs. That's because there should be less memory leaks to track down and fix in the first place.

However, there's another issue that's often swept under the rug...

Before switching to Java, the company I work for used to sell products written mostly in C. Not surprisingly, these products had the occasional memory leak. It usually caused quite a stir around the office. One or more developers would spend anywhere from a few hours to several days hunting down and fixing the leak. Manual memory management was wasting our time! Garbage collection would free us from this onerous task!

Fast forward to the present. Hardly a day goes by that I don't hear about our JVMs running out of memory, or our products not scaling well because they consume such a massive amount of memory. It seems like developers are constantly trying to determine where the memory is going and how to use it more efficiently.

All of a sudden, the occasional memory leak doesn't sound so bad. Personally, I'm quite convinced we have more memory problems now than we did before.

Conclusion

To be fair, I can't say with any certainty that massive memory consumption is a common issue in garbage collected languages in general, though it does seem to be a problem with Java in particular. The company I work for has a lot of really smart architects: too smart, if you know what I mean. They're ready and eager to deploy complicated patterns and over-engineered solutions for every problem, which most of us mere mortal developers find really hard and time consuming to maintain.

Apparently, someone forgot to tell them that more time is spent on maintenance than on new development. Writing easily maintainable code should always be priority #1. Using every pattern imaginable isn't nearly as important.

But I can say with certainty that we seem to be spending inordinate amounts of time worrying about the shocking memory requirements of our applications these days. It seems garbage collection isn't quite the panacea that we were sold.