Curly’s Law

I’ve been writing SQL Scripts in Oracle over the past few days, and since it’s not my native SQL land (I much prefer SQL Server), I sent an email to one of our native PL/SQL guys and asked him to look over the script I wrote.  One of the things he mentioned for me to fix was that the script should be in all lowercase because the server is a Unix server. Ok.

So I did the complete non-programmer thing and I started going through and changing the SQL Keywords to lowercase, as well as all the table names.  About a 1/3 of the way through it I realized thatt I could just as easily create a small application that would do this for me.  My instinct was to use Perl, but given that I haven’t used it in years, I opted instead to create a C# application to do it for me. Over the weekend I’m going to pull out my Camel Book and see what I can remember.

The C# code is trivial, but it’s fairly representative as to how I write code. I follow Curly’s Law:

Curly: Do you know what the secret of life is?

Curly: This. [holds up one finger]

Mitch: Your finger?

Curly: One thing. Just one thing. You stick to that and the rest don’t mean shit.

Mitch: But what is the “one thing?”

Curly: [smiles] That’s what you have to find out.

An algorithm, function, method, or whatever you call it in your favorite language should only do one thing. That’s it. One. It feels a lot like speaking in three word sentences, but once you get the hang of it, it makes it much easier to test your code. And who wouldn’t want to test their code? (grin)

 

namespace LCConverter
{
    class LCConverter
    {
        static void Main(string[] args)
        {
            string oldfilename = CreateStringFromFile(args[0]);
            string newfilename = args[1];
            string lcFile = oldfilename.ToLowerInvariant();
            GenerateNewFile(newfilename, lcFile);
        }
        private static string CreateStringFromFile(string filename)
        {
            return System.IO.File.ReadAllText(filename);
        }

       
        private static void GenerateNewFile(string newfilename, string lcFile)
        {
            System.IO.File.WriteAllText(newfilename, lcFile);
        }
    }
}

 

Spending 10 minutes creating this tiny little application could have been spent manually checking the SQL scripts, but that’s no fun, and now I have a way to do it for all of the SQL Scripts I write. I can simply write them in ways that are readable to me, and convert them to the ‘required’ way with no fuss.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s