Timestamping played a big part in our programming this week. One of my responses was to do one of the things I often do: write a "crib sheet" on the subject, in this case something along the lines of:
command.com: echo %DATE %TIME Thus 01/21/2010 13:52.55.95 Perl 5.8.8: print scalar localtime(time), "\n"; # Thu Jan 21 13:52:55 2010 Python 2.4.4: print datetime.datetime.now().ctime() # Thu Jan 21 13:52:55 2010 Tcl 8.5: puts [clock format [clock seconds]] # Thu Jan 21 13:52:55 CST 2010 SQL (Oracle, MySQL, PostgreSQL): select CURRENT_TIMESTAMP [from DUAL] 21-JAN-10 184.108.40.2066733 PM +00:00 ...
That's as far as I got before I had my, "It's no longer 1990! Maybe it is quicker to use what someone else has written" moment, and realized that Rosetta Code has already done the work.
You need to know Rosetta Code -- or, if like me, you sometimes don't think of it in the first two minutes of tackling a programming problem, you need to know it better. Rosetta Code styles itself as a programming chrestomathy, a refinement of my crib sheets. There are several such chrestomathies; Rosetta Code is the essential one for working programmers, though, as far as I'm concerned. It's the one that is useful for daily work.
Varieties of values
Timestamping makes a good example of one kind of benefit Rosetta Code provides. I'm big on measurement; while I trust my colleagues, I get "itchy" when one of us says, "slow", or "a few", or other such vernacular quantifiers. I relax better, particularly when we're making design decisions, after quickly coding a pertinent measurement.
Like most professionals, we work in a variety of different languages during any particular day. It's easy to grow a bit rusty on subtleties of rarely-used syntax ("in Texan, do you say, 'access road', 'frontage road', or ...?"), so I've long written personal chrestomathies to keep me on track.
It's rarely necessary, now, though! Although it has a few blemishes, Rosetta Code is generally more complete and correct than my own memory; the page that applies most immediately to timestamping, for example, improves on my Perl, and has the C, Java, Lua, and Erlang that I had in mind to write next, as well as dozens of others that we won't soon need. I was mildly surprised to see no entries for SQL,
/bin/sh--I'll need to log in later and add those.
In any case, this is the first great value of Rosetta Code: it supplies working code that serves as a useful model for a developer's daily needs.
I also recommend it in four other aspects:
- It's simply good reading. Contributors to Rosetta Code are generally knowledgeable and literate, and Rosetta Code is interesting much as Wikipedia is, despite its far narrower ambition;
- The high quality of the contributions as code, or at least as code-in-the-small, means that Rosetta Code is educational. Read through all the examples of a language you think you already know well: you're likely to pick up at least a few valuable idioms or techniques;
- Comparison is important. When a particular concept--"pointers", say, or functions whose domain is other functions--in a particular language gives you problems, read about how other languages handle the same challenge. You're likely to gain insight into the idea behind the particular implementation before you, and its advantages and disadvantages;
- Rosetta Code is a challenge and inspiration. If you're ever in the "I want to learn X, but don't know what to write" mode that afflicts some acquaintances, pick a corner of Rosetta Code, and see if you can fill it in or improve it.
Two ongoing themes of "Smart Development" are the pedagogic value of good reading, and how smart programmers take advantage of the resources available to them. Rosetta Code fits in both categories.