Database stored procedures, functions and triggers are source code of your application. Please treat them as such.

As a consultant for the past two years, when I come into a batch of code that has many stored procedures or triggers in the database, the first thing I ask is whether those stored procedures and triggers are under some kind of revision or source code control. If the developers/DBAs look at me like I’ve got two heads, then I know I’m in for a doozy of a gig because those devs are probably not doing the best job they could be doing.

And that makes sense right? You don’t call in a consultant if everything is unicorns and rainbows with your system.

Stored procedures, functions, and triggers in your database are part of your codebase. They could even be the most important and most delicate piece of your codebase.

I’ll repeat this again for total clarity… Stored procedures, functions, and triggers in your database are part of your codebase.

But not managing your codebase with a tool is a huge mistake. And yet, I see this time and time again on my gigs. And if I had a nickel for every time I saw a stored proc named with “_new” or “_new2” or “_use_this_one” in the name, I could invite Warren Buffet over to play cards and he would consider it.

For managing the source code of your stored procedures on SQL server, there’s even some commercial tools available that take your database objects and chucks them into your source code repo. Or you can always just create a “sql” directory in your source code repository and store the objects there.

There are a lot of ways to manage this problem. Ignoring it, is not managing the problem, it’s making it worse.

Continue reading

Review of Siri voice app for iphone 4s

I’ve been playing with Siri on the new iphone 4s for about 12 hours now and I can honestly say I’m quite impressed with the features. The small help section within Siri gets you going quickly with example commands. When Siri doesn’t understand a command, she prompts you to do a web search for that phrase. Of course saying things like “google barack obama” or “search for barack obama” also command her to do a google search for those terms.

A lot of the examples show how you can text, email, or call using Siri by just referring to a person’s first name.

  • “Text Vinny”
  • “Email Vinny”

If you have multiple Vinnies in your contacts, Siri will show you a list and prompt you to choose one. This makes perfect sense. However, the voice commands don’t appear to work very well for choosing which Vinny. Siri doesn’t seem to understand names very well ( which from a programmers point of view makes perfect sense ). I was hoping that it would work like most phone systems work however, where I could say “one” and Siri would select the first Vinny in the list or “two” for selecting the second Vinny and so on. It doesn’t work like that. So you either have to click the “Vinny” that you want or try to say their whole name in the original request like: “Email Vinny Boombotz.” And you have to really pronounce names phonetically ( not necessarily how they’re pronounced ) to get the right name to show up.

The same issue comes up with email addresses. When you command:

“Email Vinny Boombotz”

If Vinny Boombotz has multiple email addresses, Siri will show you a list of Vinny’s email addresses and prompt you to choose one.

I’ve found that text commands work better than email commands and that’s usually because most of my contacts only have one mobile phone number and therefore one texting address. Saying “Text Vinny Boombotz” will have Siri prompt you for the body of the message. Saying “Text Vinny Boombotz I’ll be right over” will have Siri put “I’ll be right over” in the body of the message. Pretty handy.

Creating meetings and reminders works very well. When you say “Remind me to call Vinny Boombotz at 8:30pm” Siri will set up a reminder for 8:30pm with Vinny’s number attached. So the reminder winds up with a “call” button on it for easy dialing.

Commands like “what’s the weather today” and “show me today’s meetings” are pretty handy as well.

Commands like “Find me an italian restaurant” have Siri locate italian restaurants local to you. Clicking on one shows a map and then clicking on the map label will show you the phone number and address of the restaurant.

There’s a whole slew of mapping functions that I haven’t even tried yet.

The Wolfram Alpha piece of Siri is kind of like the ultimate bar bet tool. You can ask questions like:

  • “Who won best actor in 1982?”
  • “Who won the SuperBowl in 1986?”
  • “What’s the population of China?”
  • “How many calories in an Egg McMuffin?”

And the Wolfram Alpha piece kicks in and gives you a handful of information on your topic. Again, if its not in Wolfram Alpha, then it falls back to a web search. But I found this much quicker then typing in a search. I’m probably going to use this piece of it quite a lot.

There’s also a bunch of fun questions you can ask Siri that I mentioned here.

There’s big things missing from Siri right now that I hope get improved. There’s really no concept of “latest news” or “latest baseball scores.” Siri will prompt you to do web search for these terms. Ideally, they should open up the API to/from Siri so that if you ask for “latest baseball scores” it can query ESPN or another sports outlet for that request. It would be really killer if when you created iphone apps that you could register some Siri answers in your app so certain questions would go to your app instead of just a default web search from Siri.

So in the baseball case, the ESPN app could register answers with Siri to questions like “Latest baseball scores” or “Next Texas Rangers game.” So if Siri couldn’t find the answers to those questions, it could question the ESPN app on your phone for those questions, before doing a default web search.

In conclusion, I think Siri is a nice addition to the iphone. It’s not quite a killer app but its definitely useful and something I’ll probably be using a few times a week.

Continue reading

How to find all the distinct PHP session variables that your applications uses.

The short answer is a one line Linux shell command:

This command:

  • looks through all the files in your application recursively for the PHP $_SESSION reference
  • finds any variables named with capital letters, or lowercase letters, or underscores, or numbers
  • sorts the list alphabetically
  • removes the duplicate items in the list

The long answer is that I found myself with an interesting dilemma recently. How to find all the PHP session variables set in my application. Some pieces of the application were new code, some were older legacy code. I needed to get the full list of session variables because I needed to delete most, but not all of them for a certain usage case ( ie, the user is still logged in and has some properties, but the other session data could be safely destroyed ).

So I began with some command line greps on linux. First I tried:

This was a decent list, but about 1000 rows long. Too unwieldy to deal with. Let’s get rid of the filenames, I don’t really care where the session values are set for my case.

This is a little better, but I don’t need the whole line, just the session variable itself. Let’s see if we can start to grab the session var using a regex pattern.

Now we are cooking. This is a nice list of the session variables ( albeit only one array level deep which is all I needed ). Now how to remove the duplicates? Maybe we should “sort” them first?

That is really close. Is there a way to remove duplicates with the “sort” command? Yes, there is. Hot dog.

There it is. That’s the final command I used which located around 50 variables in the old legacy code and new modular code that were used in the sessions. The only really drawback to this code is it will not find multiple nested array values on the session itself, but you could add that as a separate regex if you need.

Continue reading

Write helpful code comments or none at all.

Stumbled onto the following comment in some code I’m working on:

//Code updated by Crappy Developer – 06/22/2011. Fix for Prod problem.

This is a terrible code comment. I would rather you not even put this comment into the code.

First off, I’ve replaced the name of the developer with “Crappy Developer” to protect their public persona and since that’s how they are now known to me.

The comment “Fix for Prod problem” tells me nothing. Aren’t all problems Production problems? Otherwise, they’re not problems. What was the actual bug? Under which circumstances was it reproducible? How did you fix it? Any tricky business logic involved here?

And then there’s the “//Code updated by..” You might think that giving the date of the fix and the developer’s name is at least a little bit helpful, but all of that can be discovered with “git blame.” This dev probably doesn’t know “git blame” exists. I’ll have to send him the man page on that.

So the next time you leave a comment in the code, make sure its worth the time of the next developer that might see it. And make sure they aren’t just going to blog about how terrible your comment was. You’re wasting time with lame code comments, so please stop it.

Continue reading

Eclipse update conflict “Do you want to overwrite the changes made on the file system”

Earlier today I kept running into a problem using Eclipse (really Zend Studio built on Eclipse) with a project running on the network that I accessed via a mapped drive on my Linux machine. The problem occurred during file saving and looked like this:

Eclipse update conflict “do you want to overwrite the changes made on the file system?”

The only way I was really able to fix this problem was to make sure that both my machine and the networked machine in question had the same exact time. So I busted out ntpdate and made sure both machines were updating their time at least once a day using a command something like this:

Continue reading

linkedin.com needs to sync up company names when the company name changes

My invites to present and former colleagues via linkedin.com have started to tumble in as opposed to the normal trickle. I think that’s a fairly accurate sign of our flagging economy as anything I can personally put a number on. Of course it could also be that I’m a loser who has never really used linkedin a lot and so have practically no contacts there. 😉

What’s annoying however is the way linkedin keeps track of company names and what happens when a company name changes. For instance, let’s say I work at a company called “Davisons.” I put that in my linkedin profile. “Davisons” gets bought by “Johnson, Inc” and they change the name of the company to “Johnson Davisons.” So any new people coming into the company know it as “Johnson Davisons,” not just “Davisons.” When they look for current employees on linkedin, they won’t find all of them because some have the old company named listed while some will have the new company name listed. Not to mention how bad this problem gets when one of your previous employers changes names after you have left.

This problem is what I would call an issue with name history. This kind of name history problem is starting to creep into other areas of the web as well. I’ve already had the misfortune of trying to email someone I haven’t emailed in a few years and reached a completely different person (ie, one person’s email acct was shut down and another started with the same address). Pretty embarassing — makes me think twice about starting emails with “Hey dirtbag! Long time no see!”

The solution for linkedin’s name history problem is pretty simple. They should ask you if the company has gone by any other names and let you choose from possible alternates (or even free type them). It won’t take long for their system to build up the necessary relationships between past and current company names. It could even be pretty slick and auto-update old companies in your profile to their present name if the name is now different from what you specified.

A search for employees of “Davisons” in this case would give you both Davisons and Johnson Davisons and whatever other company names are “linked in” to this company.

Continue reading

Open source twitter clone anyone?

Does anyone know of an open source twitter clone?  Preferably in PHP or Python.  Not a client mind you, but the server guts of receiving IMs and doing something with them, enabling followers, public viewing, etc.  I want to implement this on an intranet inside a corp network and obviously not display our tweets for public consumption, but only internal consumption.  If this doesn’t exist, what do you all think is the easiest way to create this?  An instance of jabber or something else?

Continue reading

Yes you, Mr. ASP.NET developer can use a hosted open source Subversion source control for your projects also

For some reason, most .NET devs that I run into insist on using closed source applications for everything they do. I have no idea why. I guess it’s a culture thing. That’s why I love it when a mostly ASP.NET fellow starts using something open source, like Subversion source code control. All the tools are in place to do what you need, the TortoiseSVN windows explorer plug-inthe Ankh Visual Studio plug-in. It’s all there.
Plus, I’ve really fallen in love with the concept of a hosted subversion solution. For me, I host my own at my provider. But for my side projects, its great to be able to access them from multiple computers. If I can get to the internet, I can get to my project code.

Continue reading