Wednesday, January 26, 2005

Query Your Code

Lately, I've been doing a handful of code reviews for clients. I have access to all sorts of sophisticated tools (like OptimizeIt and TogetherJ), but I find that one of the tools I use the most is the *nix "find" utility combined with regular expressions. Sometimes, simplest is best.

If you had to analyze some data that lived in a relational database, would you look at all the records one at a time? Of course not -- you would execute a query that looks for troublesome records. I've been using the same technique against a body of source code. Curious about who is firing constructors on your boundary classes?

find -name "*.java" -exec grep -V "new .*Boundary.*(" {} \;

[Find all files named "*.java" from the current directory down and send each of these files into the grep command, which looks for the regular expression for constructor calls to any class with "Boundary" in the name.]

Or what about this:

find -name "*.java" -not -regex ".*Db\.java" -exec grep -H -n "new .*Db" {} \;

[Find all non-Db Java files that fire constructors on DB classes. In other words, determine the coupling between the boundary classes and all other classes.]

This technique depends on consistent naming patterns for your files. If you can rely on this, you can query your code base for analysis.

One of my common themes is to avoid drowning in impressive but unsuitable tools. If you go rabbit hunting, you can use a shotgun, a bazooka, or an atomic bomb. One of these tools is better than the others. Similarly, using a simple but effective command line tool beats the expensive ones for some tasks.

Treat your code as data and apply the same techniques you use on data analysis on your code base.

Sunday, January 23, 2005

Friends Don't Let Friends Use VSS

Andy (of the Pragramatic Programmers) writes in his blog today that he has heard that Microsoft's VSS is "Unsafe at Any Speed", based on other developer's experiences. Let me add some first person experience that validates this.

We used VSS for quite a while at DSW (for no good reasons). And, we have many clients who use it because it seems to be free (you get it with the big Microsoft box with an MSDN subscription). Thus, we have lots of experience with it. And it is absymal. The archives reliably spontaneously corrupt themselves when they reach about 2 Gb. When this happens, you always lose some data (of varying amounts). That's part of the entertainment of using VSS: "Gee, the repository is corrupt again -- I wonder what has entropied into the universe at large this time?"

My advice if you are using VSS or thinking about using it is
  1. don't use it
  2. really don't use it
  3. keep your repositories below 2 Gb
  4. didn't I tell you not to use it?
In our experience, if you want a really elaborate version control package that allows you to define rules, set up workflows, do bug tracking, and generally have a pretty extensive process around version control, use StarTeam.

If you want a straigthforward, easy to use (once you understand its metaphors), solid, stable, genuinely free version control system, use Subversion. We have been using it for most projects for several months now and couldn't be happier. In fact, I recently set up a repository at home, tunneled through my router, so I can get to my personal repository anywhere. I couldn't be happier with it. The Pragmatic Programmer's series is coming out with a best practices book on Subversion which should be the last piece of the puzzle for everyone to start using it. It Just Works.

Wednesday, January 19, 2005

The High Price of High Coupling

I read an interesting quote today in the latest Newsweek (January 14th issue, page 14). In the article "A Fox in Bill's Henhouse", Bill Gates is quoted as saying to the author last October: "Explorer is going to be the primary browser used on Windows, and for anyone to suggest otherwise is just irresponsible".

Irresponsible. What an interesting choice of words, given that Internet Explorer is such an abysmal piece of software. I generally try to avoid militancy on software and tools, because, after all, they are just tools. However, at some point, I think that geeks must start weaning their friends off this particular tool. Would you let your friends and family use a bank that has a security record as stellar as IE on Windows? Most of my non-technical friends and family don't understand what a browser is -- they just think that the way to get to the Internet is click on the blue "e". I've started taking the time to explain to them that they have a choice and that they should stop using the dangerous choice.

What really galls me is the clear choice of high-coupling as a business decision by Microsoft. Software developers know that high coupling is a bad idea for lots of reasons. The developers at Microsoft are smart guys, so the only conclusion I can make is that the decision to snake IE code throughout the operating system was a business decision. Thus, you cannot actually uninstall IE even if you try. If you type a URI in the address bar in Explorer, it will launch (in place) an IE window to view the site. How often have you crashed IE and therefore the entire shell? Even if IE were as secure as Fort Knox, the high coupling to the underlying OS would still be bad. Given its myriad security problems, it compromises the integrity of the entire operating system, and there is nothing you can do to fix it except wait for the steady stream of service packs and new vulnerabilities.

Of course, other software has security problems, including other browsers and operating systems. It is the deadly embrace between Windows and IE that makes it such a dangerous combination. This is the high price of allowing a business decision (i.e., IE cannot be removed from Windows to allow a competing browser) to create a compromised architecture for the whole operating system.

Monday, January 17, 2005

Suspicious Training Locations

How do you know that you've ended up at a bad training location?



The classroom was on the 3rd floor. Riding the elevator twice a day made me very cognizant of who was breathing on me!

Thursday, January 13, 2005

Perfect Numbers

One of the topics I must teach from time to time is how to use JBuilder to build EJB's. This isn't a class on EJB, but rather how JBuilder helps you build them. The problem that arises is how to create an exercise for the students that doesn't rely on specific infrastructure (like a particular database server, network details, etc.). Recently, I found a fun topic.

According to ancient Greek numerology, every number may be clasified as deficient, abundant, or perfect. These classifications are based on the sum of the factors (excluding the number itself). Thus, 9 is deficient (1+3 = 4 < 9), 12 is abundant (1+2+3+4+6 = 16 > 12), and 6 is perfect (1+2+3 = 6 = 6). The perfect numbers are the interesting ones. The exercise is to write an application where the user provides a seed number, and the application finds the next perfect number. Here is a list of the first 8 perfect numbers:

  1. 6
  2. 28
  3. 496
  4. 8,128
  5. 33,550,336
  6. 8,589,869,056
  7. 137,438,691,328
  8. 2,305,843,008,139,952,128

What's nice about this exercise is that it is a nice distraction from the boring plumbing-type coding required to get the application working. This happens several days into the class, so it provides a great outlet. Inevitably, students start doing research and get caught up in this topic. There is a great entry that describes the origins of perfect numbers on the Wikipedia site.

As much as I'd like to take credit for this, it came from an exercise in my first Pascal programming class. Dr. Head had us create lists of numbers that were perfect. On the Apple ][e, finding 496 took about 5 minutes. A simple, non-optimzed Java console application finds the first 4 almost instantly, and takes about 20 minutes to find the 5th. This is always a fun topic.

Wednesday, January 12, 2005

Software Development Time Warp

I teach a lot of enterprise Java classes, and it has continued to shock, amaze, and depress me how many people still haven't heard of Design Patterns and the GoF book. It's getting a little better now (typically more than 1/2 the class has heard of it now), but come on -- the book turned 10 last year!

I'm teaching a class this week of really intelligent Java developers (most of which have heard of GoF and at least the names of some of the patterns). However, I'm reaching the same dead-end with unit testing. I have become a True Believer, and I preach it in every class I teach. But it definitely hasn't trickled down to most developers. Still the most common question I get is "How can I convince my manager that I'm not wasting time?"

Is it me, or is software development in a time warp? I'm not talking about the cutting edge guys (like the attendees at your run-of-the-mill NFJS symposium) -- I'm talking about smart people who make their living writing enterprise applications. It seems that everyone in the world seems to think that advances in software development stopped in the early 90's. Just after the advent OOP and Java, innovation stopped. Developers are still writing applications the hard way, just like they did 10 years ago. The gap between the cutting edge and the masses seems to be widening. And from my experience, it's better in the Java world than in the .NET world, which seems to drink the Microsoft kool-aid on all topics.

It's frustrating and depressing because I keep seeing projects that are going to fail for all the same old stupid reasons that have caused them to fail for the last 10 years. It could be argued that I'm seeing a special set of developers, those whose management acquiesced to train. I don't think this is the case -- most of the classes I teach now are advanced enterprise stuff, not Java language foundations.

I have long suspected that part of the problem is that pointy-haired management views software development (and developers) as overhead, sort of like the HVAC system. Everyone seems cool enough -- why should we upgrade the HVAC system? What managers don't realize (and what developers have been unsuccessful convincing them of) is the software is a strategic investment in a lot (if not most) businesses. Because developers are not treated like rainmakers (and sales people are), they don't express themselves and eventually settle into that attitude themselves. Why bother beating your head against the wall if it never helps?

The consequence? A continuation of the staggering number of software projects that fail, within stones throw of techniques that can help them succeed (like Agile methodologies). Continuing frustration and tension between managers and developers. Do you think that management would allow their sales staff to fail as often as they allow software projects to fail without intervening and trying to figure out what's wrong?

Tuesday, January 11, 2005

Simplicity is spreading

It seems that most developers are coming to understand that simplicity is the answer to many of the problems software development faces, not more complexity. We've been talking about this for a while. Now, it seems that the rest of the world is starting to see the same thing. An editorial in eWeek magazine touts simplicity as preferable to complexity. They are talking about it in non-developer and simplistic terms (i.e., making the point that UI consistency is a form of simplicity), but the message is starting to spread amongst the non-developers. Could it be that these guys have been listening to developers talk, and have osmosed the idea?

In the same issue (in fact, on the facing page), a guest editorial editorializes in the same vein. He talks about the complexity of monsters like ERP systems and single-vendor lock-in. Could it be that the masses (albeit the informed masses -- we are talking about eWeek here) are finally starting to understand that Windows represents a huge business-model-trumps -technology mess of highly coupled cruft? Hopefully, someday this will lead to the death of software written to enforce monopolies and towards some really useful stuff. Not anytime soon, though...

Pair Programming

Can someone who is clinically schitzophrenic successfully pair program with themselves?

Friday, January 07, 2005

Programming for Life

I'm convinced that if anyone wants to develop software for the rest of their lives, you have to do it carefully. The activities associated with writing software (typing, sitting, staring) aren't natural. This also applies to other computer-intensive activities, like gaming. You must be proactive in mitigating the negative effects of this pursuit or they will eventually bite you. I know of so many young developers who have terrible ergonomic setups. They are just asking for carpal tunnel and other nasty surprises in 10 years. I myself have mild carpal tunnel in my right wrist, initally brought on by my irrational love for the original Tetris.

To this end, I have developed some defensive tactics for interacting with a computer. First and foremost, the Natural Keyboard. In fact, I was very attached to the orignial Natural Keyboard from Microsoft, then they changed it on me, ruining the placement of the meta-keys. After some chagrin, I switched to the Natural Elite (which has a different but less obnoxious arrangement of meta-keys). Because I want to type on the same keyboard, I bought 3 of them (1 for office, 1 for home, and 1 for the road). I hate typing on laptop keyboards!

For mousing, I generally use my left hand when I use a regular mouse. When I must, I use my right (although it causes discomfort if I do it several days in a row). I recommend that everyone learn to mouse with both hands and switch out periodically (like once a week). I know it's annoying to learn, but it doesn't take long and it becomes second nature. I've tried several mouse alternatives, the latest being an iGesture pad from Fingerworks. I had tried one of their keyboards a while back but it was too much. The iGesture pad is brilliant. It looks like a mouse pad, but it's fingertip sensitive -- different combinations of fingertips give you different functions. So, it not only replaces the normal mouse functions, but allows cut, copy, paste, zoom, and a whole bunch of other functions. Best of all, because the movement isn't restricted to a single plane, I can use it with my right or left hand with no discomfort. It's pricy, but well worth it. Most of my mousing now is done on the iGesture pad and I love it.

Wednesday, January 05, 2005

Meme receptors

I've been thinking about memes a bit lately (that is, after all, what lead to the name of this blog). Over Christmas, I talked to a lot of people who are regular church-goers. Some of their discussions lead me to the idea of meme receptors. I haven't read about this (although I'm sure that someone has written about it), but in my version, our brains have wiring in them that allow them to be receptive to certain types of memes. For example, I think it makes perfect sense that we evolved to follow a charismatic leader -- the ones following the leader are grouped together, and therefore less likely to become lunch for a saber toothed tiger. Most of the world's religions feature a spiritual leader of some kind. And most cults have one, too. This observation shouldn't come as a surprise to anyone who has thought much about this.

Here's the interesting part. What if some people have meme receptors that others don't? This could be either a nature or nurture thing, I don't think it matters. Could this explain the kind of feeling a software developer gets when they see a particularly elegant solution to a problem? What about detective meme receptors? Maybe Sherlock Holmes wasn't that brilliant, he just had good receptors. This could in fact help to answer Robert Pirsig's Quality question in Zen and the Art of Motorcycle Maintenance -- maybe the recognition of quality (his definition, anyway) fit like a hand in glove with a particular meme receptor.

Tuesday, January 04, 2005

Welcome to the Meme Agora

Meme
Pronunciation: 'mEm
Function: noun
Etymology: alteration of mimeme, from mim- (as in mimesis) + -eme
: an idea, behavior, style, or usage that spreads from person to person within a culture

Agora
Pronunciation: 'a-g&-r&
Function: noun
Etymology: Greek, from ageirein to gather
: a gathering place

Yes, I know that this is a profoundly pretentious name, but all the good ones that I wanted were already taken (like The Sound and the Fury or A Sip from the Firehose). So, this is as good as it gets.

This blog is intended to serve as an outlet for whatever happens to spill out of my head on a semi-daily basis -- a scary thought indeed. It will primarily focus on software development topics (like Java, .NET, Ruby, etc), but there's no telling what may come bubbling out at any time.

Fasten your seat belts -- it's going to be a bumpy ride.