Monthly Archives: February 2008

5 Books to make you stupider

Well, after a week of investigation, I’ve settled on a social network for books: Shelfari. It’s attractive, easy-to-use, easy to manipulate many books at once, they have a mobile version, and I have one friend on it (who invited me).

 Goodreads.com also looked nice, and it almost won. bookwormr.com, the one I originally found was just too immature at this point. I’m also wondering what features are going to set it apart from the pack, especially when there are so many well-established sites that do the same thing.

Meanwhile, if you want to read some books that will definitely NOT make you smarter, check out 5 Books that can actually make you stupider.

Visit my Shelfari page.

 

Technorati Tags: ,

Unit testing benefits programmers who are already good

In order to kick my unit testing skills up a notch, I’ve been reading a lot about it lately. Today I had the thought: “Unit testing only helps already-good programmers.”

My reasoning is that bad programmers are going to write bad tests, or not enough test cases, or bad test cases, or won’t take the effort to refactor their code when necessary, or won’t realize their code reeks, and so on and so forth.

The message from unit testing, and the XP camp in general, is that well-factored, object-oriented, testable code is key. But don’t those criteria presuppose some fairly intense skills on the part of the programmers? Merely introducing unit-testing into your processes won’t automatically improve the quality of code if someone has no clue.

This is a depressing line of thought. It’s not entirely true, however.

It IS possible that enforcing a rule on unit tests will “inspire” inexperienced developers to improve their code. Once they see the beauty of automated unit testing, hopefully some will realize that their code was NOT testable, NOT pretty, NOT well-factored, and start taking steps to change that. The knowledge to do that (why and how), however, will have to come from somewhere else. And since they’re not a good programmer, will they do this?

For these people, then, unit testing is of little benefit–chances are the code is of such low quality that the tests will just conform instead of try to break it.

You can’t teach someone the vision of unit testing without teaching the vision of a lot of other things as well. It doesn’t make sense otherwise.

A programmer who already understands how to build well-factored code is going to use unit tests in an entirely different way than someone who doesn’t understand them. To these people, it’s a way of verifying that it works to spec, and that it’s safe to change the implementation details without destroying the system.

I got into unit testing because I’m a good developer. It didn’t make me a good developer–it made me a better developer. (I said good developer, not great. I’m good because I realize that I always need to improve, and I take steps to do so, not because I’m a genius.)

That last paragraph and parentheses deserves more attention. How do you define a good programmer? Are they innately good, or are they good because they do certain things? Do you unit test because you’re a good programmer, or does the act of unit testing make you a good programmer? Is there a paradox here? Are both true? Neither?

Obviously, there aren’t just two kinds of programmers: 1) good and 2) bad. There is a spectrum. Obviously, again, just doing something doesn’t mean you’re automatically good or better, either. So I think you have to unit test because you’re a good programmer (or someone is forcing you, which is a different topic altogether) already and not the other way around.

I believe being a good programmer must come from within you. Becoming a better programmer can be done with the help of education, tools, and processes.

(Unit testing is just the topic I’m thinking about lately–you could replace it with any practice and the ideas are still the same.)

Technorati Tags: ,,

Tip: Easily Automating use of WaitCursor

This is really simple and probably common, but it’s a useful tip anyway.

Say you need to set a form’s cursor to the wait cursor while you accomplish something.

You would do something like this:

this.Cursor = Cursors.WaitCursor;
 
//do something
 
this.Cursor = Cursors.Default;

Of course, what if “do something” throws an exception? Then your cursor won’t be set back to the default.

So let’s wrap it in try-finally.

try
{
    this.Cursor = Cursors.WaitCursor;
    //do something
}
finally
{
    this.Cursor = Cursors.Default;
}

Better, but that’s a lot of wrapping around a simple operation. Notice, that the try-finally is exactly the pattern that using is. Why not wrap this functionality into a simple to use class that handles the cursor reset automatically?

internal class WaitCursor : IDisposable
{
    private Control _control = null;
    public WaitCursor(Control control)
    {
        _control = control;
        _control.Cursor = Cursors.WaitCursor;
    }
    public void Dispose()
    {
        _control.Cursor = Cursors.Default;
    }
}

And to use it in a form is simple:

using (new WaitCursor(this))
{
    //do work
}

Of course, you could easily add functionality like restoring the previous cursor instead of always the default, handling exceptions, make it thread-aware so it uses Invoke if necessary, better error-handling, etc.

Technorati Tags: ,,,

Online reading list – bookwormr

I found a great site I wanted to share with everybody: bookwormr.

To explain:

I’ve got 3 large books on my nightstand at the moment:

  • Scotland: The Story of a Nation – Magnus Magnusson – Much of my heritage is Scottish, and I got intensely interested in Scottish history during our trip to Edinburgh last year.
  • Code Complete – Steve McConnell – I’ve read this before, but it’s a good book to review every year or so and pick up new tips.
  • The Complete Grimm’s Fairy Tales – there are many variations on this book. I have a very old, out-of-print edition. I read a few of these a week–they’re mostly quite short.

Those are all fairly large books and I’ve been working on them simultaneously. Meanwhile, I keep getting book recommendations from various places (blogs, podcasts, family). It’s to the point where if I don’t write them down, I’ll forget. I’ve sort-of kept track of books I want to read on my shelf, in an Outlook note, in e-mails to myself, but I was in need of a central repository for this.

So I stumbled upon bookwormr, which is (almost) exactly what I want.

It’s still in its infancy stages, but I think it shows great promise. And it is usable now, despite some rough edges. The owner seems very amenable to suggestions via the blog.

How it works:

  • Search for books (it uses Amazon as its database)
  • Add them to one of your three lists (already read, reading, want to read)
  • You can tag, review, and rate the books.
  • See what others are reading.

The author also has a wordpress plug-in and a Facebook app to go along with it. I’m going to try out both.

Features I’d like to see:

  • Easier way to add multiple books at a time
  • Ability to sort lists according to a ranking system of my own (the author is planning on adding the ability to sort on author, title, book rating overall)

Update: here’s my bookwormr profile.

Technorati Tags: ,,

Dear Spammers…

Thank you for your increasing interest in my blog, which is apparently slowly gaining in popularity with legitimate readers too!

Unfortunately, my dear spammers, you are idiots. 100% of comments on this blog are moderated–99.9% are filtered before I ever see them. The rest are fairly obvious scams. None of your stupid spammy comments will ever be allowed. You’re just annoying me. And you get nothing out of it. I hate you.

Sincerely,

Ben

Technorati Tags: ,

Amazon Kindle + Audible = Killer-app?

My wife sent me a link to the Amazon Kindle the other day, and asked, “Have you heard of this? what do you think?” I think she wants one.

I have to admit that the thought of such a device is appealing. I have tried reading e-books on my PDA and BlackBerry occasionally, but other than a quick read now and then, it’s too painful–the screen was too small.

But the Kindle…this might work out. I’m seriously considering getting one.

With the news that Amazon is buying Audible, the story gets more interesting. Personally, I haven’t gotten much into audio books, but I know people who do and love them.

I have no idea if or how Amazon will integrate Audible into the Kindle’s experience, but I have a feature request. For a killer feature:

Sell the audio version of a book at a discount (or free, or + $1)when someone buys the e-book format (or vice-versa). Then, synchronize the bookmarks between the two formats. That way, I can plug the Kindle into my car’s stereo on the way home to listen to my current selection, and at night I can pull it out and continue reading from where the audio left off.

That’s my prediction for a killer app. My wife and I do a LOT of reading (we JUST ordered our first TV, and it’s only for NetFlix, and we will not be hooking it up for any broadcast or cable). I think someday soon we’ll both have our own Kindle–it would save a lot of bookshelf space.

Technorati Tags: ,,,

.Net Reflector

Lutz Roeder’s .Net Reflector has been discussed on many blogs before, but I want to give it an additional plug. I recently had to emulate some C# serial-port code in our C++ app. The .Net SerialPort class is great, easy-to-use, and works well. Unfortunately, we’re using a C++ serial port library that does not support all the possible features. Fortunately, we have the source code and can easily extend it. Unfortunately, I’m not too familiar with serial port programming, and the .Net functionality does not all obviously map to the Win32 API in every respect.

Enter Reflector. It was trivial to poke into the .Net assemblies and see what the SerialPort class was doing under the covers and then use the correct Win32 functionality in our app.

There are also a ton of plugins available.

Technorati Tags: ,,,

Fighting Brain Rot

Alex Shalman has a great post at zenhabits about how to avoid letting your brain decay into apathy and atrophy. It’s a great call to action, to find ways of self-improvement. I think the behaviors listed here dovetail very nicely with the attributes of highly effective programmers.

By continuing to do as we always have, the quality of results will be the same as always. Only when we step out of our comfort zones, and push ourselves to improve, will we gain useful new experiences, knowledge, and ideas.

I think the methods of expanding the mind are highly applicable to software developers. I just have a little bit of commentary on each one.

11. Reading – I think I would have put this at #1. It’s the easiest way of cramming information into your skull. It’s the most efficient method of information transfer, and that’s our bread-and-butter as programmers, so we should become expert at it.

10. Writing – We write code for a living, not necessarily prose, but communication is key to so many areas in life, that learning how to write effectively is critical to most careers. For myself, I definitely find it easier to express myself in writing than in-person. Doing this well becomes a critical ability.

9. Puzzles – Developing a large software project is in many ways like an enormous software project. It’s so large, though, that we can’t comprehend it all at the same time. But practicing other types of puzzles can train our brains to look for patterns and to develop new, creative ways of thinking. My favorite offline puzzle is the New York Times Crossword, but I enjoy the occasional sudoku.

8. Mathematics – a good understanding of boolean logic, prepositional calculus, discrete mathematics, asymptotic notation, etc. are great things for developers to have. A general understanding of algebra, calculus, trigonometry, and statistics also comes in handy more-than-occasionally. Another valuable idea that comes out of mathematical understanding is the idea of precision in thought and rigorousness in testing or understanding your software–think loop invariants.

7. Painting – I am definitely not an artist by any means, but the underlying principle of some kind of artistic self-expression is important. The creative side of your brain must be regularly exercised. For me, this is in the form of building Legos.

6. Cooking – I initially found this to be a peculiar choice, but it makes more sense when I ponder it. Cooking is at once creative and precise. Not only does it use all the senses, but it requires you to think on your feet and be very, very organized and detail oriented, especially when you start cooking for more people. Planning and execution both become huge issues.

5. Music – I wholeheartedly agree, and I’ll even go out on a limb and say that you need to listen to lots of genres of music, especially classical. Why classical? Because it exhibits more musical complexity than all others. It doesn’t minimize various musical aspects (variation, melody, harmony, tempo, timbre, i.e.) for the sake of a single one (i.e., rhythm).

4.Poetry – I used to write fiction and poetry in high school and earlier, but it’s been quite a while. I do remember it being quite the exercise to compose sonnets–it forces you to be extremely creative with grammar, syntax, meaning, vocabulary, and more.

3. Meditate – This is an art I need to learn more about. I find I do this automatically in some situations where I’m not otherwise preoccupied (the shower), and I can solve a question I’ve had. I find that NOT doing something is as important as doing something in many cases. When I’m faced with an especially thorny problem at work, it really helps to just write down my thoughts about it and let it sit for a few days while I think about it in my off moments. Most of the time, I can come back and have a better solution than if I had started right away.

2. Learn a language

A language that doesn’t affect the way you think about programming is not worth knowing. – Alan Perlis

The original article obviously means foreign spoken languages, which I definitely agree with. I speak Italian, and the insights it’s given into my own native English are quite valuable. If you’re a careful student, knowing two languages definitely forces you to think about the meaning of words and constructs. It’s much harder to take things for granted.

I think the same is true of programming languages–knowing more than one helps your mind think about a problem in different ways. Once you understand functional programming, for example, you will never look at programming the same way again.

1. Question Everything – This is analogous to love of learning in my Effective Programmers essay. It’s not being a jerk and denigrating everybody else’s ideas. It’s asking yourself continual “Why” questions in order to understand the issue.

Technorati Tags: ,,,,

6 Programming problems you don’t want in the interview

1. Write out all floating point values between 0 and 1.

2. Write tic-tac-toe in Brainf*&$

3. What is 2128 in decimal?

4. Solve traveling salesman in constant  time (O(1))

5. How many grains of sand are there in the Sahara (at a given instant, assuming constant, well-defined boundaries)?

6. Implement quicksort on a spherically linked list.