Upgraded to Leopard

I installed it last Wednesday. My first upgrade attempt failed, so I paid a visit to the Tyson’s Corner Apple Store to get some help from the Genius Bar. Apparently the DVD wasn’t clean or something (since the guy cleaned it off), because when I tried archive+install as recommended, there were no problems.  The next day, I picked up a 1TB Western Digital MyBook Home Edition at MicroCenter for $220 + tax so the Time Machine feature would have plenty of room to operate.  It’s definitely as cool as advertised.  I was impressed that when you plug in an unformatted drive, Leopard asks if you want to use for Time Machine.  I was pretty lax about my backups before, so this will be a huge help.

Changing Primary Keys from “int” to “uniqueidentifier”

I’m in the process of doing this for a project that uses Microsoft SQL Server.  One of the “gotchas” I came across was that once you’ve switched from “int” to “uniqueidentifier”, @@IDENTITY and SCOPE_IDENTITY references won’t work.  The second response in this thread pointed me in the right direction.  You have to call NEWID() in the context where you need it (and save the value) in order to be able to refer to it later.

Back to the trenches

Instead of management and code, I’ll just be writing code (at least for now). Today, I started a new job at a small consulting firm in Virginia with a software lab that wants to start putting out products.

Today consisted of the environment configuration and filling out of forms typical of a first day.  Most of the last half of the day was taken up by a boot camp.  I found it to be a very enlightening how-to on consulting, as well as an intro to the company’s culture.

A More Perfect Union

Barack Obama spoke at length yesterday on the issue of race in general and his former pastor in particular.  If you haven’t already seen and heard the speech, or read the transcript, I encourage you to do so.  There is no soundbite that can do justice to the importance and brilliance of his message.  If there was ever a politician who could legitimately argue that he’s a uniter and not a divider, it is Barack Obama.  I only hope it helps him win in Pennsylvania.

Time to buy an iPhone?

I went to the barbershop on Friday.  During my haircut, I ask my barber how he likes the iPhone.  He doesn’t just like it, he loves it.  I got quite a sales pitch from him.  Then the guy getting his haircut next to me chimes in.  He just got an iPhone as well.  He actually said he’d been thinking about getting a laptop, but found the iPhone did what he needed.Of all the iPhone owners I’ve talked to since it came out (friends, fellow conference attendees, even a guy waiting for the bus in Seattle),  I have yet to hear any complaints.I haven’t caved in and bought one (yet), for a few reasons:

  • I’ve been kind of annoyed with AT&T Wireless lately over dropped calls
  • Don’t really like the idea of a $70/month cellphone bill
  • I’m kinda waiting for the next version of the iPhone (new hardware anyway)

Every day that goes by however, I find I dislike the Motorola Razr I’ve got just a bit more.  The gap between my current monthly cellphone bill and that $70/month is starting to get smaller too (probably too much text messaging).  I’m also not sure I want 3G badly enough to wait months and months for it.

Refactoring

Last night, I went to a presentation on refactoring by Jonathan Cogley.  My notes are below:

refactor – improve the design of existing code incrementally

Code must:

  • do the job
  • be maintainable/extensible
  • communicate its intent

Code that doesn’t accomplish all of the above is broken.

Refactorings

  • rename
  • extract method
  • inline method
  • introduce explaining variable
  • move method
  • inline temp

technical debt – anything that needs to be done to the code that gets put off until a later date

I found a much better definition for technical debt.  It makes a nice argument in favor of refactoring (though not as good as it would be with some way to quantify and measure it).

code smell – indication that something could be wrong with the code

Code Smells

  • duplicated code
  •  long methods
  • large classes
  • Too many private/protected methods
  • Empty catch clause (FxCop flags these by default)
  • Too many static methods
  • Variables with large scope
  • Poorly-named variables
  • Comments
  • Switch statements
  • Unnecessary complexity

Even though comments in code to tend to get out of date, I’m not sure I’d call them a code smell.  Wikipedia has another definition of code smell, along with a link to a taxonomy of code smells.

When to refactor:

  • before a change
  • after all current tests are green

Sometimes, refactoring is necessary to understand code.

reduce scope – bring variable closer to where it’s used

Be sure your unit tests don’t re implement what the tested code is doing.

Eliminate double assignments (a = b = 0) for clarity.

Each method should have only one operation/concept.

If you must use code comments, they should explain the “why”.  The code should be clear enough to explain the “what”.

Favor virtual instance methods where possible in your code.

Avoid using the debugger.  Write unit tests instead.

Performance improvements tend to make code harder to understand.  Don’t use refactoring to address application performance.

Recommended reading:

Refactoring to Patterns

Fixing Computer Science

I’ve been reading a lot of complaints about the current state of computer science education lately.  This post makes a reasonable attempt at summarizing the different ideas around what sort of graduates these programs should produce.  I’ve been in industry long enough that my CS program hadn’t switched to using Java as the initial language when I started.  I agree with Brian Hurt and Chris Cummer about the value of a computer science degree.

The right courses in a CS degree amount to a toolbox of concepts that you can use to solve whatever real-world problem you’re facing.  The most recent example of this happened on the job.  We had an issue where some text files being downloaded for storage in a database kept causing failures in a process.  Because of how the process was implemented, there was no way to pin the cause of a failure on a particular line of the file.  The files in question are regularly more than a gigabyte in size, so manual inspection wasn’t an option.  The minimal understanding I have of how compilers work enabled me to direct my staff to build a parser, so we could validate the input file before running the process against it.  Without a CS background, it’s highly likely that I don’t come up with a solution at all (or a really bad implementation of a parser).

If I had it to do over again, I would have spent more time in my CS program getting better depth in compilers, operating systems, and other areas.

Computer science isn’t perfect, but it’s relatively young as a field compared to disciplines like law or medicine.  There are probably things that should be changed, but I think the fundamentals are good.

Apple Stuff

iPod nano

The iPod I mentioned yesterday is the 4th (!) one I’ve owned. Each of the previous ones was sold to help fund the upgrade to the next one. I love this one even more than all the previous ones because it handles video.  The video is watchable, even at that size.  The nano makes great use of the screen when it isn’t playing video too.  The earbuds that came with this one are better than the previous ones, but I’m still going to buy a better set.

Thoughts on MacWorld

The most important product announced there isn’t MacBook Air–it’s Time Capsule.  I think far more people will find a use for wireless drive backup than they will for a really thin laptop.  Because Time Capsule also works as a router and can share a USB device (or devices if you plug in USB hub), you could conceivably share even more hard drive space and a printer to every machine on your wireless network.  As far as I can tell, Time Capsule provides more capabilities than Mirra Personal Server (a comparable backup/Internet access product) at a lower price ($300 for the 500GB version) in a much smaller form factor.  After a copy of Leopard, I think a Time Capsule will be my next purchase from Apple.

Birthday

I turned 34 today. I suppose I’m officially in my “mid-30s” instead of my early 30s now. Other than that, it doesn’t seem different at all from any of my other post-30 birthdays.

I did pick up a new toy for my birthday–an 8GB iPod nano.