Tuesday, December 26, 2006

The Little Drummer Boy

It struck me this Christmas that the author of "The Little Drummer Boy" wasn't a parent. Can you image this conversation two thousand years ago:
"Mary, doesn't Jesus look so peaceful sleeping?"
"He sure does Joseph."
"Hey, whose that at the stable door?"
"Hey cool, the boy going to do a drum solo for Jesus."

Friday, December 22, 2006

The Joy of ReSharper

After hearing friends rave about ReSharper, I finally took the plunge, and it's wonderful.
Use the IntelliJ key bindings.

Some of my favorite features:
  1. Cntl-n: find type. This takes you directly to the object of your desire. ReSharper (RS) does the google-suggest thing of giving you a dwindling list of all the objects possible based on your current key strokes.
  2. Cntl-Shift-N: Go to a file anywhere in the directory structure.
  3. RS gives advice on code. For example:
  4.  Ctl-Alt-v:  Add a variable to the left of an expression - if you don't have a ";". For example:
    new StringBuilder()
    var stringBuilder = new StringBuilder(); 
  5. RS said the "ToString()" was redundant and (this is the best part), offered to automatically correct it for me (OK, deleting a string is not all that helpful, but some of the other advice is a little tedious to implement. I especially like the offer to use the string.format option on long concatenated strings mixed in with variables. You can turn off specific suggestions like "the 'this' prefix is redundant".
  6. Real Refactoring. VS2005 comes with a few refactoring options, but typically not the ones I need. RS has a cornucopia of refactoring methods. Maybe the jetbrains developers actually read

    by Fowler, unlike some other IDE teams.
    One of my favorites is "Encapsulate Field..." which adds the getter and setters for a field.

Thursday, December 21, 2006

The Failure of Sanctions

I'm intrigued by the continuing use of sanctions in the modern world. Sanctions seem to be a popular way to impose some sort of punishment on evil states. But do sanctions actually work?
The US imposed sanctions on Japan to prevent oil and steel entering Japan in response to Japan's occupation of Manchuria in the 1940s. The sanctions failed to free Manchuria from occupation and dragged the US into WWII. The sanctions on Cuba have forced them to abandon their communist ideology - oh wait, after decades it hasn't. In 433BC Athenians imposed sanctions on Megara for farming sacred land. The sanctions eventually dragged Athens into the disastrous Pelopennisian War with Sparta, which it finally lost after decades of debilitating warfare. The historical record of using sanctions for political purposes is a dismal failure.

In addition to virus scans, will we have RIAA scans?

About 80% of the computing power of my computer goes to scanning for viruses (yes, I use Windows at work). Will it be too long before we are all required to have an RIAA scanner that constantly scans our hard drives and incoming email for copyrighted material? With those new quad-core machines we can devote one (or maybe two) to scan from viruses, one from RIAA infringement and we'll still have one left for doing our job.

Thursday, December 14, 2006

Seven Things You'll Love about Ruby

I don't know if you got the memo yet, but next year you'll be programming in Ruby. Here's just a few of the little things you will love about Ruby:

  1. Simple programs are simple
    If you are like me, I have a stable of code snippets and little utility classes. When I start a new java program I mentally think about which old program is similiar to the new one (e.g., ok I need a program that reads a file, takes input from the user, and writes out some proccessed data to an output file). I modify the old one to create a new program. I found I don't do that with Ruby.
    For example, just to do a hello world in C#,

    using System;
    public class HelloWorld
    public static void Main(string[] args) {
    Console.Write("Hello World!");

    In Ruby:

    puts "Hello World!"

  2. Open Classes:
    You can add methods to existing library classes. For example, in C# 2.0, Microsoft added the very helpful string function, IsNullOrEmpty() which replaces the unwieldly construct: if(mystring != null && mystring != ""). In Ruby you don't have to wait for the mavens in Redmond to decide you need a new string function, you can add it yourself.

    class String
    def NullOrEmpty?
    (self == nil || self == "")
    puts "test".NullOrEmpty?
    puts "".NullOrEmpty?

  3. Handy, time saving methods
    I'm amazed at how long I've done awkward constructs in Java and C# without even thinking a better way could be found. For example, in Java:

    if( x < 7 && x > 12 ) { ... }

    In Ruby:

    if x.between?(7,12) do ...

    Ruby is littered with helpful real world utilities for getting your job done.

  4. Methods can have variable number of arguments
    This can be quite time saving and reduce your lines of code.
    The following are all good calls to add():

    add 1
    add 1 3 5
    add 1 3 5 7

  5. Functions can return more than one value

    Yes, we could return a small array or structure with our multiply values, but why not just return multiple values:

    average,total = joke.getAverageRatingAndCount
    def getAverageRatingAndCount
    record = Rating.find_by_sql(["select count(*) as count,avg(rating) as average from ratings WHERE joke_id = ?",id]);
    return record[0].average.to_f , record[0].count.to_i

  6. Parallel Assignment
    You can swap the values in variables without the use of an temp variable. Remember your first programming class: Swap the values in "i" and "j"? You had to use a "t" variable to store one of the values first. Not needed in Ruby.

    i = 0
    j = 1
    puts "i = #{i}, j=#{j}"
    i,j = j,i
    puts "i = #{i}, j=#{j}"

    Which produces:

    i = 0, j=1
    i = 1, j=0

  7. Ranges
    Ranges are real objects

    puts (1..10).each{|i| p i}

    Prints the numbers 1 to 10 without the syntax for(i=0;i<10;i++)

    (1..10) === 2 # this returns true because 2 is in range

    The Range object just does the right thing in its context which can reduce your lines of code and make code more readable.

These are little things, some of the big things you'll love in Ruby are Blocks and generating methods on the fly from code. More on those later.

Tuesday, December 12, 2006

A Disappointing Austin Dot Net User's Group

The XBox racing game pumped up the 75 people attending yesterday's .Net meeting. The wireless controllers were passed around the room. (Afterwards someone asked "Where are the controllers?" to which the answer was "EBay!".)
The new Microsoft developer Evangelist, Caleb, presented on the new ASP.Net AJAX component (nee Atlas). Caleb went over the basics and then showed a demo of using VisualStudio 2005 for developing applications. What happened was a parable of development with Microsoft tools. He built the application and it failed because of a JavaScript error - a class was not properly scoped. So Caleb had to go under the covers of the code that VS generated and try to fix what was wrong. That sounded so familiar to me. Too often the cool WYSIWYG tools of Microsoft take you 90% of the way, and then leave you dangling. The tools demo so well, but in actual development, they leave many things lacking. So as developers we end up having to know all the plumbing underneath applications anyway. This is in addition to how to build applications with the graphical tools.
I really liked Caleb and he'll be good for our area - too bad he doesn't have better tools to demo.

Other tidbits from the night:
75% of the attendees programmed in C#, the rest VB.
ASP.NET AJAX has hooks to transfer data using JSON in addition to SOAP for speed.
Browsers (IE?) use only 2 connections to a domain. To speed downloads put images in diff sub domains.
Fiddlertool.com is some tool for doing HTTP debugging like Firefox's Tamper.
Devtoolbar is available for IE (like Firefox's Developer Toolbar) at Microsoft's site.

Wednesday, December 06, 2006

Connecting to a Remote SQLExpress

SQLExpress is both a blessing and a curse. It's nice to have a free alternative to SQLServer for development, but we all have to learn a new set of utilities to administer SQLExpress. When I first tried to connect to an instance of SQLExpress on a virtual machine with this:

C:\home\mfincher>osql -Usa -P"MyPassword" -S "MyServer\SqlExpress"

The result was:

[DBNETLIB]SQL Server does not exist or access denied.
[DBNETLIB]ConnectionOpen (Connect()).

The solution took three steps to remove the default locked-down settings:
1. Select "Start/Programs/Microsoft SQL Server 2005/Configuration Tools/SQL Server Configuration Manager"
Select "SQL Server 2005 Network Configuration/Protocols for SQLEXPRESS" in the left pane. In the right pane, enable "Named Pipes" and "TCP/IP".
2. Select "Start/Settings/Control Panel/Services" panel.
Right click on "SQL Server Browser". In the "General" tab set "Startup type:" to be "Automatic".
In the Services panel make sure the "SQL Server (SQLEXRESS)" service is running.
3. In "Microsoft SQL Server Management Studio Express" (see previous post on how to get), right click on the machine instance (the top item) and select "Connections". The check the box labeled "Allow remote connections to this server".

It's thrilling to see Microsoft take such pains to have a more secure system by default, but it would be nice to have a single, obvious checkbox to allow the system to talk with the rest of the world.

Austin Java User's Group Christmas Meeting

The Austin JUG met last night at the Sun offices here in Austin. Sun supplied the pizza and drinks for the 60 attenders. Gregg Sporar gave the technotiser showing three different integrated profilers - YouKit, Ecliplse tptp, and the built in profiler for NetBeans.

Angela Caicedo gave the main course about Sunspots - Sun's Small Programmable Object Technology (SPOT). She demoed small sensor devices the size of a deck of cards wirelessly talking with each other and exchanging data. The technology looked very interesting, but felt immature. These new devices are produced and ready for sale to the public, except for legal issues. I wonder if that's the future of technology here in the States - great products ready for release, but held up over some patent. Can you image Windows Vista ready to ship on January 31st, but being held up by some patent issue? It could happen, talk with our friends at Blackberry.

Something else struck me at the meeting - most of the attendees were middle-age, very few younger people. Are there not many people going into programming as a career here or are they just out partying and not interested in learning more, or are they all at the Ruby rallies? What do you think?

Tuesday, December 05, 2006

All the world's population could fit in a Texas County

I was talking this morning with a friend at work and he mentioned some of the shrill prophets of overpopulation. What most people don't know is that the entire 6 billion members of this race we call human, could all fit in an average sized Texas county.
The math: Shackelford county is roughly 20 miles by 30 miles square so the area in square feet is
(20 miles * 5280 feet/mile) * (30 miles * 5280 feet/mile) = 16,727,040,000 feet^2, or almost 17 billion square feet. With 6 billion people on our lovely planet that works out to about 2.7 square/feet per person just in this one county. It would be crowded, but Texas has 253 counties to go.

Friday, December 01, 2006

Regular Expressions to the Rescue of Testing

Recently I wrote about the problem of maintaining lots of xml test files. Here at IniTech we have 15 major test groups in my current project, each with a config file containing about ten descriptions of test components. This morning I needed to add three new attributes to each of the roughly 150 test components. Like most IDE since the 80s, Visual Studio 2005 has regular expression replacement. I needed to add jobNumber, localJobNumber, and nickName attributes with the value being a varient of the 'name' attribute.
<Survey name='USM1' groupName='US Malls' priority='4' status='1' cellLimiter='100'
surveyLimiter='100' dateStart='2004-01-07T09:30:00' dateEnd='2006-01-28T16:30:00'
exclusions='0' cluster='Cluster1' allSurveysExclusion='-1' surveyType='AdHoc'
excludeSurveyType='' excludeSurveyTypeDays='-1' >
<Survey name='USM1' groupName='US Malls' priority='4' status='1' cellLimiter='100'
surveyLimiter='100' dateStart='2004-01-07T09:30:00' dateEnd='2006-01-28T16:30:00'
exclusions='0' cluster='Cluster1' allSurveysExclusion='-1' surveyType='AdHoc'
excludeSurveyType='' excludeSurveyTypeDays='-1' jobNumber='JN-USM1'
localJobNumber='LJN-USM1' nickName='Nick-USM1' >
This handy little regex replaced them all with the highest level of quality assurance:
Find What:
 \<Survey name='{[a-zA-Z0-9]+}'{[^>]+}{\>}
Replace With:
 \<Survey name='\1'\2 jobNumber='JN-\1' localJobNumber='LJN-\1' nickName='Nick-\1' >

Note that the value of the "name" attribute is gathered into the '\1' variable because its description is surrounded with curly braces.