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]
 Monday, January 02, 2006

I was under the weather this weekend so I spent some time looking for a new text editor.  I had a few requirements:

  • File explorer
  • ability to view differences between 2 files
  • syntax support for Ruby
  • pretty print features

I tried out CPad and it was very promising.  However there is a little bug with CPad where the program will not close without killing it in taskmgr.  I posted the bug on the CPad form and we will see if it gets fixed.

So I tried quite a few others but none had the features I listed above.

Then I came upon PSPad.  It has the features I need plus the kitchen sink.  This thing has everything from a color picker to an ASCII table to the ability to handle ruby embedded in HTML.  Something only sophisticated IDE's are usually able to handle. 

I'm still playing with the PSPad but I think it may replace my current favorite Crimson Editor and earn a place in the Pragmatic SDK.

Update:

Yes it does do Ruby fairly well.  I must admit however that since ASP.NET 2.0 came out I haven't used Ruby or Ruby on Rails much.  I'm exploring the new features of ASP.NET and C# and enjoying the new IDE.

See the comment below for enabling Ruby syntax support.

Monday, January 02, 2006 8:08:24 PM (Central Standard Time, UTC-06:00)  #    Comments [2]
 Thursday, December 15, 2005

You may be annoyed if you are used to a convenient trim function on your strings that eliminates leading and trailing whitespace and you've found that it doesn't exist in javascript.

Here's a quick fix:

//start code
// add the missing trim functions
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

//end code

Add this in any javascript file or in between some <script> tags and your javascript strings will magically have the trim function.

This is because javascript classes are mutable.  There is a more accurate and technical explanation but I will spare you the pain. 

We are simply adding the trim function to the string class at runtime.  The trim function uses regular expressions to trim the string of leading and trailing whitespace. 

Thursday, December 15, 2005 11:47:55 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, October 18, 2005
How to detect JavaScript in a browswer - Version 1 - Poorman's special.

This is a simple hack to detect whether JavaScript is enabled in a browser.  This trick should work for ASP.NET or Ruby on Rails or any other framework.  The trick is to use the noscript tag.  Here is a snippet of code:

 <noscript>
  <INPUT TYPE='hidden' NAME='jsdisabled' VALUE='true'>
  <span class='warning'>JavaScript must be enabled to use this site!</span>
 </noscript>

Make sure you place this code inside the form that is to be posted.

The noscript tag is only active when script is either not supported or disabled.  This chunk of code gives a warning to the user and also sets a hidden form value.  When the form is posted you can then check to see if the jsdisabled parameter is included with the post.  If it is you know that JavaScript is enabled.

Notice I call this a poor man's method as it needs more testing.  If you can see any problems with this please add a comment so I can change it
Tuesday, October 18, 2005 10:34:11 AM (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]
 Friday, September 16, 2005

When it comes to login or authentication schemes for web pages you have a few choices.  

  1. Authenticate with email address and a password.
  2. Authenticate with a user name (either system or user generated) and password.
  3. Authenticate with an account number (or some relevant identifier) and password.
  4. Authenticate with an account number (or some relevant identifier) and pin or other unique identifier (SSN, address, etc).
Each of these schemes has its own unique merits.  The most popular is probably number one above.  The email address is usually one of the easiest logins to remember.  However a potential stumbling block is the situation where multiple unique users share an email address.  It’s hard to believe that this seems logical to a person when email addresses are a free commodity.  

Number two is probably the second most popular as it eliminates the problem from number one, however it introduces the problem that a user must remember some kind of random user name because they probably won’t get the one they want as it will already have been taken.  This increases the possibility of support calls and user frustration.

Number four is becoming more common especially for financial services and other highly regulated or secure environments.  All information is meaningful and unique.

My preference is usually number one.  It’s common and easy to understand and the draw backs are easily remedied by the forcing of a unique email address.

I choose number four as my second choice.  It’s more complex to implement but it provides a higher level of security while using relevant customer/user information.  This would prove especially effective if the required login information changed randomly like many financial institutions authentication schemes.

Friday, September 16, 2005 10:36:15 AM (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

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]