The software engineering reading group, hosted out of Gangplank Phoenix, has finished Clean Code and is moving on to another book: Working Effectively with Legacy Code by Michael Feathers.

This book was my personal choice, kindly agreed to by the other members of the group. Everyone seems to enjoy the book thus far, even when I presented chapters four and five this week!

If you’re in the Phoenix area, come join us! Drop by Gangplank at 8:00pm on any Wednesday.

 

A recent attempt at creating a unique identifier at work was shot down in flames by Findbugs. My naïve attempt wasn’t very thoughtful but seemed to work.

Integer.toString(Math.abs(random.nextInt()))

Findbugs indicated there was a possibility that I might end up with a negative value even though I “cleverly” used Math.abs().

RV: Bad attempt to compute absolute value of signed random integer (RV_ABSOLUTE_VALUE_OF_RANDOM_INT)

If the number returned by the random number generator is Integer.MIN_VALUE, then the result will be negative as well

Even though I didn’t need this random id to be perfect — the unintended side-effect wasn’t a technical problem since I used it as a String — I still wanted to fix it. Stackoverflow to the rescue.

A question-and-answer from Stackoverflow pointed the way to the solution: java.util.UUID. Somehow, I missed that Sun had added Java’s own universally unique identifier (UUID) generator in Java 1.5.

In the end, I happily replaced my homemade id generator with Java’s.

UUID.randomUUID().toString()

The output of which is something like 1c312843-8903-411f-88b2-ff1b92ca80ba.

Cross-posted at http://java.dzone.com/articles/global-unique-identifiers-java.

 

Check out Julien Ponge’s article on Fork and Join in Java 7.

 

Perhaps most people using Cygwin don’t realize this, but they actually have two home directories. One is their Windows home directory (%USERPROFILE%) and the other is their Cygwin home directory (~).

Several months ago I became frustrated with repeated navigation from one to the other, so I began using a symbolic link. In ~ I created a link to %USERPROFILE% with ln -s "$USERPROFILE" home. Thus, any time I wanted to change to my Windows home directory I would simply cd ~/home.

It worked, but that dichotomy remained… Then, it occurred to me: why couldn’t ~ and %USERPROFILE% be the same?

Luckily, they can!  In fact, the Cygwin documentation on alternate home roots shows exactly how. Using mkpasswd, one or all home directories may be set to any arbitrary path; to change all home directories to the Windows home directory:

mkpasswd -l -p "$(cygpath -H)" > /etc/passwd

Pretty neat. See the Cygwin documentation on alternate home roots for more information.

 

I joined a software engineering reading group, last week, hosted out of Gangplank.  The group is reading Clean Code by Bob C. Martin.  If you’re in the Phoenix metro area and interested in joining, check for details on the Gangplank blog.

© 2011 And now here's something… Suffusion theme by Sayontan Sinha