Tuesday, August 28, 2007

"Ruby off the Rails?" quid pro quo

I came across Ruby off the Rails? by Paul Turner and he issued a challenge at the end of his post, and I bit :)

Read it here (including the comments) then come back for my some-what larger response.

Begin communique:

I agree with you that Microsoft adding more and more languages to the framework is a bad idea. J# anyone? . Their ploy is to lower barrier to entry, so what you end up with is some developers using anything but C#, because, well why bother learning it if you don't have to. Have you tried proposing C#.NET to a VB developer when they can use VB.NET? I have, it's not fun. It might just be me but I question the maintainability of an application written in 7 different languages.

To answer your question:

Read the following with the caveat of using the "right tool for the right job". Obviously if you are targetting a windows desktop app, it is hard to trump WinForms. However i think .NET is licked in every other category.

  1. Portability (Mono still doesn't implement the full .NET 2.0 API)

  2. Expressiveness of language:

  3. 1    for (int i = 0; i < 5; i++) {
    2      Console.Out.Write("c# loop ");
    3    }

    vs.

    1 5.times { print "ruby loop " }

  4. Cost $$$$$$$$$$$$$$$

  5. MSDN documentation is, well crap, contrast:

  6. http://msdn2.microsoft.com/en-us/library/system.io.file(vs.85).aspx
    and
    http://java.sun.com/javase/6/docs/api/java/io/File.html

  7. Closed source / Open standard


I can safely say that you are the first Microsoft proponent that I have come across that knows the difference between open-source and open-standard :). Some people claim that .NET is open-source. No; it's a huge difference. Java is open-source: http://www.sun.com/2006-1113/feature/. Ruby is open-source: http://www.ruby-lang.org/en/LICENSE.txt. But you hit the nail on the head C# is an open standard: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf.

This might not be a kicker for a lot of people, but it is to me. I like being able to delve into source and see what's going on and change it to suit me. This is how i found a bug in the Sun implementation of the CachedRowSet, i thought i was going insane but i was able to get in there and figure why it wasn't working and then report it. Kudos for the open-standard, but one up it and go the whole hog.

I was also working as a government employee when I discovered that bug. If the source hadn't been open I would not have been able to temporarily patch it and get on with what I was doing.

I also have to disagree about the 'purity' of keeping SQL code in SQL Server. It's fine if you have resigned yourself to paying for SQL Server subscriptions the rest of your life. But i'd like to bet on a bit of flexibility and write ANSI compliant SQL that i could quite easily drop into Postgres or any other db for that matter. Ofcourse there are extenuating circumstances (performance reasons and the like) to dabble in sql server extensions, but it is a rarity. I wish i also had the energy to go the age old 'dynamic sql vs stored procedures' argument with you too :)

Rather than bemoan the fact that is IronRuby, maybe have a look at it, who knows you might give up your C# day job :)

Friday, August 17, 2007

Automating SVN stuff with Ruby

Ahoy hoy.

The other day at work I was looking at upgrading an SVN installation at an off-site and came across a good 70 odd repositories dumped to backup. Rather than take the typical windows muppet route and unzip each one, create an svn directory and import them manually, I scripted the whole thing.

Ruby lends itself to this sort of work. I've used it in the past to automate daily and weekly backups of another repository so I knew it would be pretty easy to sort this out. The best part is it didn't take more than 15 minutes from go to whoah. Here it is in it's entirety, it's not a shining example of best practice, nor does it profess to be, but it does what it's supposed to do.



 1 ################################################################################
 2 #
 3 # SVN importer
 4 #
 5 # rubyzip must be installed: gem install rubyzip
 6 #
 7 ################################################################################
 8
 9 require 'zip/zipfilesystem'
10
11 SVN_REPOS_URL = "http://paleale:8090/svn-repos/"
12 SVN_REPOS_PATH = "C:/svn-repos"
13 BACKUP_DIR = "//sparkling/SVNbackups/"
14 UNZIP_DIR = "C:/Documents and Settings/dan/My Documents/"
15
16 # unzip all the dump files into the UNZIP_DIR
17 # we make the assumption that the dump file inside the zip shares the same name
18 # i.e. web_indicator.dump.zip has web.indicator.dump inside it
19 Dir["#{BACKUP_DIR}*/*.zip"].each do |zipFile|
20   dumpFile = zipFile.gsub(/^.*\//,'').gsub(/\.zip/,'')
21   Zip::ZipFile.open(zipFile) do |unZip|  
22     unZip.extract(dumpFile, UNZIP_DIR + dumpFile)
23   end 
24 end  
25
26 # create svn directories for each dumpFile, load into SVN then delete the file
27 Dir.glob("#{UNZIP_DIR}*.dump").each do |dumpFile|
28   projName = dumpFile.gsub(/^.*\//,'').gsub(/\.dump/,'')
29   cmd = %{svn mkdir -m "automated: creating project structure from import" } 
30   cmd << SVN_REPOS_URL << projName
31   %x"#{cmd}"
32   cmd = "svnadmin load --parent-dir #{projName} #{SVN_REPOS_PATH}"
33   cmd << %{ < "#{dumpFile}"}
34   %x"#{cmd}"  
35   File.delete(dumpFile)
36 end

Monday, August 13, 2007

Linux eye for the VMS guy

Recently I traded my comfy life with Fedora and Solaris for Windows and VMS. Yes, I'm crazy, but I wanted to see how the other half live, plus it's what they use at my new job.

What I propose to do is make my VMS life as cruisy as possible. Therefore I'm trying to map as many *nix commands as i can to DCL. If you don't know what a LOGIN.COM file is, it's analogous to your .bashrc if you use the BASH shell. It also funnily enough gets executed when you login. My first triumph was getting VIM installed, thanks to this guy for building the binary, absolute champion.

Here is my login.com, no doubt it will grow and i'll try and update it as i add stuff.



 1 $!      LOGIN.COM
 2 $!
 3 $!
 4 $ set noon
 5 $ IF F$MODE().NES. "INTERACTIVE" THEN GOTO BATCH_LOGIN
 6 $ vt200
 7 $ set term/inq
 8 $ set term/color
 9 $ set control = "Y"
10 $ set prompt="Dan$ "
11 $! VIM
12 $ define /nolog VIM dev_users:[dan.VIM]VIM.EXE
13 $ define /nolog VIMRUNTIME dev_users:[dan.VIM.VIM71]
14 $ define /nolog TMP SYS$SCRATCH
15 $ vim :== $dev_users:[dan.VIM]VIM.EXE
16 $! Other UNIX stuff
17 $ who == show users
18 $ date == show time
19 $ ls == "dir/size/prot/date=create/width=(filename=28,size=5)"
20 $ pwd == "show default"
21 $ clear =="type/page nl:"
22 $ more == "type/page"
23 $ cat == "type/nopage"
24 $ cd == "set default"
25 $ top == "monitor process/topcpu/interval=10"
26 $!
27 $ set protection = (s:rwed,o:rwed,g:e,w)/default
28 $ EXIT

Wednesday, August 1, 2007

Pander to familiarity

The first step of getting out of the familiarity trap is to feel confident in sizing up what else is on offer.

A simple set of criteria as defined by Sebesta in 'Concepts of Programming Languages' includes:

  1. Readability

  2. Writability

  3. Reliability

The invisible 4th criteria I belive is Familiarity. Unfortunately, in reality I believe that familiarity takes precedence for the majority. You might argue that familiarity is a construct of readability and writability but I disagree. It may be a fuzzy line; but to me something isn't purely readable and writable just because you've twisted your mind to think that way.

For example:

1 for (int i = 0; i < 5; i++) {
2   Console.Out.Write("hi ");
3 }


That looping construct makes sense to a veritable legion of programmers (pick your printf or println statement). Is it readable and writable because you've done it a gazillion times or is it inherently simple?

Contrast that with:

1 5.times do
2   print 'hi '
3 end


If you pulled a layman off the street and showed them both I could take a guess at which one would be considered more readable.

In Steve Yegge's (in)famous next big language post his number #1 rule for the next triumphant language is 'C like syntax'. I can tell he feels oh so dirty saying that, but 'you gotta give the programmers what they want'.

Things like orthogonality, control structures and data types don't seem to rank as highly. Whatever happened to the best tool for the job? If I know there is something out there that works I don't care whether it's functional, applicative, imperative, logical, whatever. It's just a side-effect. If you have a brain in your head, you can work it out.