Tommy’s Blog

Photography, technology, and a little bit more from Tommy Williams

Archive for the 'Programming' Category


ADO.NET vNext CTP is live

15th August 2006

Happy day today: the ADO.NET vNext CTP is available. We have worked hard to get this out the door and we’re anxious to know what you think. You can discuss it at the ADO.NET Technology Preview forum on MSDN.

Alex has been bugging me to write about the experience of pulling this Community Technology Preview together to provide an in-the-trenches view of things. I’m still too excited about the release to know what I would write but I’m sure there will be something in the next few days.

In the meantime, enjoy!

Update: Sanjay Nagamangalam has made a screencast showing some of the Visual Studio tools in action.

Tags: , , , , ,

Posted in Microsoft, Programming, Work | No Comments »

Translating from cmd.exe to PowerShell: dir

30th July 2006

After a long hiatus from Monad, err, PowerShell, I have started working with it again now that Release Candidate 1 is available.

One thing that frustrated me when I last used the shell was figuring out how to do all the things I was used to doing with dir in cmd.exe. Things like dir /o:d to order by date, or dir /a:r to show me all the read-only files seemed to take a huge amount of typing in Monad.

It can still take a bit of typing in PowerShell but last night I decided to make a little table that translated common actions in cmd.exe’s dir to PowerShell’s get-childitem. There are two lines for each entry in the table. One is the “full” version without use of parameter shortening or use of built-in aliases, and the second is the shortest I could make the command using the aliases that ship with PowerShell. My one concession: even in the full version I never use get-childitem. I always use “dir.”

cmd.exe PowerShell
dir dir
dir /s dir -recurse
  dir -r
dir /s *.txt dir -recurse -include *.txt
  dir -r -i *.txt
dir /s %temp%\*.txt   dir -recurse -include *.txt $env:temp
  dir -r -i *.txt $env:temp
dir /o:-d dir | sort-object -descending {$_.LastWriteTime}
  dir | sort -des LastWriteTime
dir /a:d dir | where-object {$_.PSIsContainer}
  dir | ? {$_.PSIsContainer}
dir /a:-d dir | where-object {$_.PSIsContainer}
  dir | ? {!$_.PSIsContainer}
dir /a:d /o:-d dir | where-object {$_.PSIsContainer} | sort -descending {$_.LastWriteTime}
  dir | ? {$_.PSIsContainer} | sort -des LastWriteTime
dir /a:hd dir -force | where-object {$_.Attributes -like ‘*Hidden*’ -and $_.PSIsContainer}
  dir -fo | ? {$_.Attributes -like ‘*H*’ -and $_.PSIsContainer}
dir /b dir | format-table Name -hideTableHeaders
  dir | ft Name -h

 

One nice thing about functions in PowerShell: / and - are legal in function names. So, in my profile, I’ve defined functions with names like dir/o-d and dir/s to get back to the short commands I’m used to.

Coming soon: a list of things you can do with get-childitem in PowerShell that aren’t possible with dir in cmd.exe.

Tags: , , ,

Posted in PowerShell, Programming | 7 Comments »

Strong typing epiphany

1st March 2006

It has nothing to do with skills at the keyboard, but with programming languages and environments. For the first time ever, while working on a small, self-contained script, I missed having static typing and a compiler to help verify what I was doing. I almost fell off my chair when I realized it.

Let’s back up and I’ll try to explain what this is about. As usual, I’ll ignore all kinds of details to try to get the idea across.

There are lots of different ways of classifying programming languages. One distinction that has always been relevant to me is that between scripting and compiled languages. Scripting languages (and here I’m including things like Perl, VBScript, and PHP) lack two features that, in my simple classification scheme, belong to compiled languages: strongly typed variables and, of course, compilation.

But that lack of features is, to me, a good thing. When trying to write a quick program, strong typing and compilation get in the way. Strong typing requires you to be careful about the way you use data and variables in your program — the way you handle things like numbers or text. Spending time to get that right can slow you down. Compilation is an extra step in the process. With a scripting language, you just write the code and then run it. But with a compiled language, you have to write the code, then compile it, then run it. That compilation step may only take a few seconds, but when you’re doing it dozens of times while building the program, it adds up. Edit-compile-run is a noticeable difference between Edit-run.

I have never doubted the value of strong typing, or static typing and type safety, anyway, in large programs with multiple people collaborating on it. There’s tremendous value in the structure those systems impose.

But until today I had never wanted those features/burdens when working on scripts. The script I’m working with is about 500 lines and was written several months ago. Now that we’re working on the next version of our product, the assumptions that were made when the script was first written are no longer valid — it needs to handle more possibilities.

So I’m reworking the script to handle these possibilities. And the logic of what I’m doing — the actual purpose of the script — is very simple. But there are enough variables and subroutines, and they’re used enough places, that there are plenty of opportunities to make mistakes, often just with a typo. Maybe the variable is abcVariable and the first five times I type it correctly, but the sixth time I type abVariable. With a compiled language, the error would be flagged before the program could run. But in a scripting language, I can’t know that the error exists until I run the program. You may have heard the terms compile time and run time. This is the distinction.

In this case, the script takes a few minutes to complete its work and restoring the system to its previous state (so that I could try the script again) takes a few more minutes. To make things even more dangerous, the script copies and deletes files. If I make a mistake in some of that code, I could erase a whole lot more than I intended. And it’s no fun restoring from backup.

So, working in the scripting language, I have had to pull bits and pieces out as I make changes and put them into another script, write a bit of code to run those bits and pieces, and test things piecemeal as I go.

This is the first time that I’ve been handling a scripting task where I would have been faster with a compiled language. It’s pretty darned surprising to me.

And, please, all you fans of Ruby or Python, don’t tell me I’m an idiot because your language could solve these problems. If I had the luxury of using Ruby or Python — or even taking the time to rewrite the script in a compiled language — I would. But we have a budget and I can’t spend enough of it on this to rewrite it.

Tags: , , ,
del.icio.us tags: , , ,

Posted in Programming | 5 Comments »

Refactor Pro now supports Visual Studio 2005

28th February 2006

Refactor Pro now supports Visual Studio 2005, and there’s a trial version available. It expires on the 20th of March. I’m almost afraid to try it out — I may grow so attached that I’ll just have to spend the US$99 and buy it when the demo expires.

Tags: , , ,
del.icio.us tags: , , ,

Posted in Programming | No Comments »

A little structure goes a long way

22nd February 2006

Natural language processing is one of the holy grails of computer science. Why should people have to learn special, strange languages for interacting with the computer? Very few people can construct a workable query using SQL, for example. Why can’t we just ask the computer questions the same way we would ask another person using natural language?

We’ve found out in the decades since Arthur C. Clarke wrote about HAL that it’s very hard to write software that can understand natural language. And humans, bless our hearts, are remarkably skilled at adapting. So even as difficult as structured languages may be, it’s still easier for people to learn to speak “computer.”

Omar Shahine shows how to create a little “Magic Word” for SlickRun to search for flights using Mobissimo. He got the idea from Aditya Bansod who points out that natural language — something better than formal, structured languages — doesn’t have to be strictly natural.

So the Web — specifically, search engines — are showing us another possibility. They’ve trained us to put phrases in quotation marks and use + to note words that are important and - to indicate those we don’t want to see. They’ve even taught us that we don’t need to write complete sentences: just enter some terms that make sense. Map sites like Windows Live Local and Google Maps, the structured input format for addresses (one field for street address, one for city, one for state, one for zip — you know the stuff you fill out every time you buy something online) has been banished in favor of a single field. Enter an address like 100 Main St, Some City, Washington and the system can parse it. It’s amazing how much nicer the experience is.

Maybe we don’t need true natural language processing. Maybe we don’t even want it. What I’ve seen so far of semi-natural language queries seems very good indeed.

P.S. I’ve got thoughts about how this relates to tagging vs. formal hierarchies, and how tagging – especially collaborative tagging – complements these semi-structured language approaches.

Tags: , , , , ,
del.icio.us tags: , , , , ,

Posted in Programming | 1 Comment »

Why does PHP have to be professional-grade?

20th February 2006

Tim Bray complains that all the PHP code he has seen has been “messy, unmaintainable crap.” The responses he has posted mostly confirm his opinion, saying things like, “it really needs to clean its act up to appeal to people coming from other programming languages, instead of just people coming from dreamweaver.” Or “it hasn’t been proven that users *can’t* write clean, comprehensible, maintainable PHP - but it also hasn’t been proven that anyone can.”

One response, perhaps unintentionally, points out the absolute beauty of PHP: “people with little or no education in the realm of programming are programming.” Hallelujah! Too bad that he introduces that beautiful statement with this lead-in: “Herein lies the main problem.”

Fine. So PHP isn’t “professional grade.” But it can be used to do some pretty amazing things. The software that powers this blog, and thousands of others, is written in PHP. I wasn’t surprised to see it called out as an example of poor code.

Does it matter? No. The easy entry to programming that PHP offers is letting people with ideas — people with passion for things that are not software — to produce some magnificent work.

So it’s hard to refactor. So it doesn’t scale. So it’s impossible for someone else to come along and maintain it. That’s OK. We have dozens of languages and programming environments that scale up to big teams and big demands and that promote good software practices.

Why not have a language that doesn’t value the enterprise first? Isn’t there room for the hobbyist?

This argument against PHP feels a lot like the one the professional journalists have been throwing at amateur bloggers. There’s certainly room for both journalists and bloggers; if anything, we’re hearing that it’s the professionals that are at risk in the imaginary journalists vs. bloggers showdown.

I’m not trying to discount the value of well-written software: over the past decades, we’ve learned a lot about the value of disciplined, well-designed code. Just don’t forget the value of the folks with the ideas and the passion to implement them. We need software that supports them. And if they make a mess along the way? It’s fine with me.

Update (2006-Feb-27): Shelley Powers, writing about all the languages she has learned over the years, also points out the value of PHP’s ease-of-entry and its ubiquity. It’s an entertaining article in its own right, even if you don’t care about PHP.

Tags: , , ,
del.icio.us tags: , , ,

Posted in Programming | 6 Comments »

Productive weekend

19th February 2006

It’s been quite a weekend. I finally got fed up with dasBlog hanging the worker threads on my old blog site* so I decided to move all the content to Wordpress and start up a new blog. No single part of the process was hard, but there were a lot of moving pieces. Among other things, I:

  • Wrote a C# app to convert all my dasBlog content into an RSS file for importing into Wordpress.
  • Set up two Wordpress blogs (one to hold the archived content and one — this one — for future posts).
  • Designed a set of Apache RewriteRules to handle the various permalinks that dasBlog uses.
  • Wrote a C# app to generate the RewriteRules to map the old permalinks to the Wordpress permalinks.
  • Set up 404 handlers and other redirection for old pages at tommyblogs.com.
  • Wrote a Windows Forms apps to easily let me add Technorati and del.icio.us tags to my posts

What remains in the blog migration?

  • Handle categories redirection
  • Remap various Feedburner category feeds
  • Monitor logs and see what I’ve missed
  • Transfer the domain name from the current host to 1and1.com and save myself about $15 a month.

* Old blog site: tommyblogs.com. The problem (I think) was actually happening due to — what else? — spammers. They were hitting my site with some generic comment post code. They weren’t even bothering to see what fields were there, they were just POSTing to the forms. Somehow, though, this was corrupting the ViewState on the pages and dasBlog didn’t have the exception handling in place to deal with it. In fact, it was apparently throwing up dialog boxes. When enough of these things hit, I consumed all the threads available to me (since there was no one on the server to click “OK” on the dialog), and the site was hung until I emailed the hosting provider and asked them to cycle my site.

Tags: , , , ,
del.icio.us tags: , , , ,

Posted in Programming | 11 Comments »