Sunday, November 19, 2006

One argument script pimps use frequently is that it doesn’t matter what tools a contractor uses to build a house as long as the finished product is the same.

The problem with this argument is that the premise and the analogy are flawed.  Comparing the language to the tools is not quite accurate.  The language is more aptly compared to the building materials used instead of the tools.  The tools would instead include things like the IDE.  With the analogy corrected we now see that the choice of building material is very important.  Using 2x4's instead 2x6's will have a big impact on insulation properties (thicker wall cavities) and cost. 

Is this important?  Absolutely!  

Unfortunately, too many scripting language fans (script pimps) make the same flawed analogy in order to justify the use of their pet language instead of a higher performance language like C++ (or C#, Java, etc).  Scripting languages like Ruby are slower then compiled languages.  Also their nature precludes them from having good IDE support.  This is because much of the meaning (context) can’t be derived until runtime so things like IntelliSense become difficult if not impossible to implement. 

Following the scripter’s analysis we are supposed to assume that scripting languages allow faster construction which I would say is another falsehood.  Yes, some contractors might be able to cut wood just as fast with a handsaw but most want to use as much automation as possible.  Hence, table saws, compound miter saws with laser guides, etc.  These automation tools are closer to Visual Studio than VIM. 

In my experience with Ruby (among other languages) I found that the resulting programs were usually slower, which a scripting language will be by its nature.  I also found that the emperor wears no clothes!  Shockingly, developing in a scripting language is slower because of the lack of automation tools.  Example, try to find all references to variable in a Ruby on Rails project.  Now try the same thing in a C# project using Visual Studio.  In Visual Studio it’s a right click and “Find All References”.  In VIM you could search for the references but you don’t have any support for context.  You don’t know that is the only reference to that variable.  You are using a handsaw instead of the best tools available.

I'm sorry but reality demands that 1 = 1 and slower is slower and speed is important.

Sunday, November 19, 2006 9:53:49 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Sunday, September 17, 2006

Dear C#,

It's taken many months to get the courage up to write this letter.  I have been unfaithful.  I have cheated on you several times.  I won't go into all the details now because I know you will be too fragile to read all of the sordid details but I must confess my first indiscretion.  Her name was Ruby on Rails.  She promised me so many things like an automagical data access layer and super fast site creation.  Only now I realize that she was a cheap whore, pimped by a slick smooth-talking metrosexual Dane with a knack for finding the weaknesses of enterprise developers and exploiting them.

I feel so dirty but I have to say this.  The cheating was only part of it.  I was also using pretty heavily.  I was using VIM several times a day.  That's when I suspected I had a problem.  I think I knew I hit rock bottom when I stooped to hitting the Exuberant Ctags for a fix.  It was Ruby that got me hooked on that crap.  I was so sold on her elegance and simplicity I ignored the hoops I was jumping through to get a decent editor.  The whole time this was happing Visual Studio 2003 just waited patiently for my return with a knowing look.  VS2003 knew she was better but she let me find out for myself.  Like a parent who knows the only way to teach a child a lesson is to let them learn it on his own, you knowingly looked on as I struggled in vain with a succession of seedier solutions for text editing.  There was the aforementioned VIM, SciTE, jEdit, and the abomination to end abominations radrails.  When you are reduced to an orgy of J2EE acronyms to stay agile you know you have a problem.  The Pimp himself has so shamelessly denigrated Java, yet many of his clientèle must turn to Java to make sleeping with Ruby a tolerable experience. 

I now know what it must be like to be a fan of Anna Nicole Smith and then to meet her in person and then to realize what a waste of chemical compounds she has turned into.  She's apparently beautiful but once you here her talk you realize there's nothing going on in there.  So I liken the experience I had meeting Ruby on Rails.  Seemingly beautiful on the outside but utterly deranged once you get passed the magical ActiveRecord song and dance show. 

I'm physically drained.  That's all I can stand to write for now.  I have more to confess like using Daedalus to keep Ruby up on running once she would go on her nightly benders and the inevitable crash afterwords (I guess she was really Like Ms. Smith!) but I will leave that for later. 

Sunday, September 17, 2006 4:02:16 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, September 15, 2006

I think when Microsoft introduced .NET and the declared that you where free to write in any language most people focused on bringing old crusty languages like COBOL to the modern .NET framework.  I'm not sure how successful this has been.  I'm not being critical, I simply do not know because I use C#, arguably the most mainstream of the .NET language families.  For the past few years I have flirted with languages like Ruby and Lisp and found some of the features of these languages to be intriguing.  C# is fairly powerful and is still being extended by Hejlsberg and company and is even starting to stretch into some Lispy areas with features like LINQ.  What I miss most in almost every language is the Lisp style macro.  These things are powerful, if you don't know what I'm talking about you need to check out Peter Seibel's Practical Common Lisp book.  Once you implement the MP3 database in Chapter 3 you should have a good idea what macros can do for you and your coding, especially if you write a lot of repetitive code (hint: database access, DAL, etc). 

The problem is that even thought I enjoy Ruby and Lisp the implementations for these languages are hit and miss.  The open-source implementations all feel like second class citizens on Windows XP.  Using Emacs as a text editor for Lisp when you are used to Visual Studio 2005 is a little disappointing.  Using GVIM to edit Ruby on Rails files leaves me with a similar sense of dissatisfaction.  These are great languages without great tools and with hit and miss implementation issues.  I have to say however that I am fairly comfortable with some of the commercial Lisp Implementations with LispWorks being the best all around when you consider licensing. 

Back to my point, I did not set out to author a diatribe on Lisp and Ruby, and I will leave that to the Flamer and the Flaming Flamed.  My intent is to write about two rather new languages that give me a lot of hope for the direction and potential of CLR languages: Boo and Nermerle.  Both of these languages support cool syntactic macros and add their own little twist to CLR programming.  Boo is about agility and keeping the code lean and clean and uses macros to support this concept.  Nemerle is a hybrid functional language very similar to C# but with the cool functional stuff like Pattern Matching and also C# 3.0 features.  What is interesting is the C# 3.0 features are implemented in the C# compiler and does not require support from the CLR.   CAUTION GENERALIZATION AHEAD!  Lisp macros are simply code that runs at compile time instead of run time.  So we are doing things in C# that sounds like an area where macros could make a huge impact.  In fact this is how Boo and Nemerle implement many of their advanced features, they are simply using macros.  So Greenspun's 10th Rule plays out again this time inside the CLR.  In fact if we design a language with Lispy-ness in mind we know that we need very few constructs to develop a very powerful language and I think Nemerle especially takes advantage of this fact.

These languages are not designed by Microsoft.  They are independent languages targeting the CLR.  So yes even though we are coming back around to Lisp, I for one am not disappointed but rather quite pleased.  If I can get the power of Lisp on a framework like .NET then I will be a happy camper.  I'm waiting for the tools around these languages to mature a bit and at this point I'm leading more towards Nemerle because it seems to be farther along and very well documented.  Once a plug-in for Visual Studio 2005 becomes mature I will definitely spend more time playing with this Nautilus machine for the mind. 

So all I want is a great language and great tools and I will be happy.  Is that really so bad?

Friday, September 15, 2006 8:44:52 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, October 25, 2005
Funny thing is all the new language features of C# are very old LISP features and Ruby already has them...
 
"Anonymous methods allow code blocks to be written “in-line” where delegate values are expected. Anonymous methods are similar to lambda functions in the Lisp programming language. C# 2.0 supports the creation of “closures” where anonymous methods access surrounding local variables and parameters. " - MSDN
 
I just mean that I've been reading about LISP lately and how Ruby is a very closely related language and even thought LISP has been around for something like 4 decades it's features are still being picked up by Java, C# and other languages.  In fact one of the co-creators of Java said somethong about Java bringing C++ developers half way to LISP. 
 
LISP is a very ugly language but Scheme, a variant, is not so bad.  I'm not sure I would have picked up Ruby if I hadn't migrated to C# from VB6 and then had to learn Java and Progress.  The thing is I like learning this stuff and if knowing Ruby helps me understand C# so much better which I can say it does because I can see the intent of the abstract constructs in C# so much clearer through the lense of Ruby then I could through the broken glasses of VB6.   
 |  | 
Tuesday, October 25, 2005 8:47:54 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, September 23, 2005


If you're familiar with vi then gvim should be no problem.  If you're not you can still use gvim in a windows compatible mode.  Either way gvim can be used as a pretty good (not to mention free) IDE. 

First go get gvim at http://www.vim.org/.

Then go get the project "script" at http://www.vim.org/scripts/script.php?script_id=69  If you can't find it try searching for "project"

Now you need to install a nice little ruby gem named "vim-ruby" 

   You can go this with the following steps:

  •    gem install vim-ruby --remote
  •    vim-ruby-install.rb

   from your command line of choice.

Now one last bit, to make sure you can enable folding which helps a lot with large files remember to do the following step:

To enable folding, download the patched ruby.vim file shown atop this page. Then put the following lines into .vimrc (or ~/.vim/plugin/ruby.vim):

 set foldmethod=syntax
 set foldtext=getline(v:foldstart)
 " you may try out this: set foldcolumn=3
 set fillchars=fold:\ " note the whitespace after  
 " not neccessary but useful (so you can use the TAB key to fold/unfold):
 map <TAB> za

-- originally found at http://www.rubygarden.org/ruby?VimExtensions

You should be on productive dude after this!

Friday, September 23, 2005 5:15:52 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, August 09, 2005

This is a great tip as rsync is super fast and can work both ways.  But rsync is too good just to be a *nix only utility.  There is also a Windows version available from ITeF!x that installs cygwin, ssh and all the other goodies to get you going on the Windows side.  

Follow the installation instructions and you shouldn't have any problems.  

To make life easy I added the default install directory (C:\Program Files\cwRsync\bin) to my path.  I also added a couple of system variables for cygwin: CYGWIN = nontsec and HOME = c:\path\to\home\directory.  

Once you have rsync downloaded an installed you can alter the code above slightly to work on a Windows system.

desc "Deploy basic application directories"
task :deploy => :environment do
  dirs = %w{ app lib test public/images public/stylesheets public/javascripts db}
  dirs.each do | dir|
   onserver = "username@yourdomain.com:/home/username/web/"
   local = "/cygdrive/c/rails_app/" + dir
   cmd = "rsync -arvz -e ssh #{local} #{onserver} --exclude \"*.svn*\" --exclude \"*~\" "
    
   puts cmd
   rsync = IO.popen(cmd, "r")
   while line = rsync.gets
   end
   rsync.close     
  end
end


Notice that in the local assignment I'm not using "#{RAILS_ROOT}/".  This is because of the way cygwin has to access the NT (or FAT I suppose) file system.   "/cygdrive/c/rails_app/" evaluates to "c:\rails_app".  Notice also that I added another exclude for files ending with ~.  This is because I use VIM and it leaves these files all over and I haven't gotten around to another solution but this should serve as an example of how to exclude other file types.

Once last piece of goodness.  If you're using Textdrive (and why wouldn't you?) then you can set up certificates to authenticate with rsync instead of a password.  

Here's how it works.  Open a command prompt.  If you've added C:\Program Files\cwRsync\bin to the path then the ssh command should be available from the command line.  

Type this:

ssh-keygen -d

You will be prompted to save the key to a file.  Choose a location otherwise it will default to the value in your $HOME + \id_dsa.  When prompted for a passphrase you can leave it blank.

Now upload the *.pub file you just created to Textdrive into your  /home/username/.ssh directory and rename it to authorized_keys if this file doesn't exist otherwise copy the contents of your file into  the end of the authorized_keys file.  

Once this is done you know have a way to authenticate yourself via certificate from your machine to the Textdrive server.  This means that when you run the "rake deploy" command you won't be prompted for a password each time because you are authenticating via public/private keys.


Tuesday, August 09, 2005 10:25:37 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Saturday, August 06, 2005
Open your config/environment.rb and place this line someplace after the # Include your app's configuration here: comment.

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:tmpdir] = "#{RAILS_ROOT}/sessions/"

In this example if my application (on Windows) looks like this:
   
root/
    app
    config
    ...
    sessions

Then when you restart webrick or whatever web server you should see session data populate in the root/sessions folder.  This is an easy folder to access for session clean up if need be.

In production you could set up a task in cron or task schedule to delete these files periodically.
 | 
Saturday, August 06, 2005 3:54:02 PM (Central Standard Time, UTC-06:00)  #    Comments [0]

One thing that I love about Ruby on Rails is the fact that I can concentrate on adding functionality without the hassles I used to have with ASP.NET.  I just downloaded the search generator (gem install search_generator) which allows me to add a simple search feature to my site and even integrate some of the features from OpenSearch (http://opensearch.a9.com/). 

Once again the generators usually provide simple code generation which generates models, views, helpers or controller classes etc which you can then extend to your heart’s desire.  Usually the generators integrate or weave some feature into your application that just makes your life much easier. 

The beauty of rails is that you KNOW where things are at.  Where’s the business logic?  Controllers or Models.  Where’s the display logic?  Helpers or Views.  And it’s the same with each app. No need to scrounge around an inconsistent application looking for bits and pieces of some functionality. 

Rails is a shining example of some best practices and some pragmatic ideas combined with patterns and OOP to make one heck of a productive application. 

Saturday, August 06, 2005 3:45:20 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, August 05, 2005
I uploaded my latest project to http://Textdrive.com the other night and at first I was disappointed with the response speed.  Then I remembered I was using cgi instead of fcgi.  I made the config change and the speed blew me away.  I’m used to ASP.NET application speed and the usual compile and load time each page normally takes.  Also with WEBrick I was used to a slower response time.  All I can say is that the UI was nice and zippy and just felt good. 

It’s one of those times when something surpasses your expectations.  Textdrive is a pretty good host and I recommend them.  I’ve had quite a few hosts to this point and I have to say their tech support has been great.  They also support the Ruby on Rails project which is great also. 

So far I’m enjoying life on the rails.

Friday, August 05, 2005 7:22:33 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, June 17, 2005
I've decided on the following format:

Tabs for indenting, spaces for alignment.

In gvim I have set tabstop=2 and in Crimson I have set View > Tab Size = 2 also.

This way I have tabs in the files but I can set the actual tab display to be anything I want.

This should provide a consistant look to the source code.  2 spaces is about right, 8 is way too much as your code quickly gets too far to the right.
Friday, June 17, 2005 5:11:07 PM (Central Standard Time, UTC-06:00)  #    Comments [3]