Derek Sivers writes about switching back to PHP from Ruby on Rails after attempting to rewrite cdbaby. Raganwald references an intersting series from Chad Fowler on "Rewrites" and why they are so difficult.
Although it seems to be a little disagreement over the existence of beautiful code, a refactor I did today was pleasant to my eye.
result = RunArglessCommand(user, commandName);
string commandArg = RetrievePairCommandArg(commandData);
result = RunArgCommand(user, commandName, commandArg);
RunArglessCommand(user, commandName) :
I'll take it. ()?: is your friend!
I've always wanted to work for Microsoft. My first chance was right out of college when a professor of mine passed my resume to his friend up there. I had some embarrasing crap about how I'd always wanted to work for "the company." It was all true but I can imagine the HR person directing anything that sappy to the trash. Instantly.
But it's just as well - Steve McConnell has an interesting comment about how much time at Microsoft may be spent in meetings - for developers:
When I was at Microsoft in 1990-91 I probably spent less than 5 hours a week in meetings. In contrast, I had a former Microsoft employee tell me earlier this year that on the team he was on he was booked in meetings from 10:00-4:00 5 days a week. Lots of managers at other companies have told me that they're in meetings all day every day and get most of their "real work" done during evenings and weekends, so obviously there's a big difference between Microsoft 1990 and Microsoft 2007, and among different companies.
As I hit "publish" from my previous post on pivot tables, a thought struck me on another most excellent use for them. No, really - for the next job interview:
WHEN I % 5 = 0 AND I % 3 = 0 THEN 'FizzBuzz'
WHEN I % 3 = 0 THEN 'Fizz'
WHEN I % 5 = 0 THEN 'Buzz'
ELSE CONVERT(VARCHAR(2), I)
I taught a T-SQL Programming class this week and in the process looked over some old books on the subject. One in particular I've enjoyed was the Transact-SQL Cookbook from O'Reilly - I have yet to find as novel an approach to SQL, coming from the ideas of set theory rather than tutorials on querying. I'm biased too, my best friend in highschool was Slovenian and one of the authors, Aleš Špetič, hails from that fine country.
A cool idea from the very first chapter is the pivot table, a numeric range that can come in handy for many different types of operations. The book, which is probably circa Microsoft SQL Server 7, demonstrates the building of a pivot table using some hardcoded insert statements followed with a cartesian join that generates the range.
It occured to me in SQL 2000 and higher one can use a User Defined Function and get all the benefits with a little bit more flexibility. Here is a simple approach to the same concept:
CREATE FUNCTION fnPivot(@BOUND INT)
RETURNS @Pivot TABLE(I INT)
DECLARE @I INT
SET @I = 1
WHILE @I <= @BOUND BEGIN
INSERT INTO @Pivot VALUES(@I)
SET @I = @I + 1
The approach is different but the benefits are similar. A simple one from the first chapter is building a calendar of a given range of days. I've adapted it to use the function above:
CONVERT(CHAR(10), DATEADD(d, i, CURRENT_TIMESTAMP), 121) [date],
DATENAME(dw, DATEADD(d, i, CURRENT_TIMESTAMP)) [day]
Kaizen is all about small improvements that never stop coming. With respect to Nregex, I plan to keep it moving as a project by spending small amounts of time on new features that will hopefully make it more useful.
Tonight's new feature, though it was really something I did on Saturday morning, is a bookmarklet that should make it a little easier to get into the site from elsewhere (like your favorite IDE).
A few weeks ago my boss noticed some latency issues, especially with larger documents. I've added a "manual" mode that will let you press a button or just hit your enter key to evaluate a regex, rather than it being processed as you type. Animated gifs give a little feedback on wait time.
If you have a request for a feature, please submit it here. If you have a handy regex you solved some problems with, please submit it too. I'm currently at work on a "library" that I hope to cover some basic regular expressions (phone, zip, ssn, and so on) with.