Jan 29 2008

Get Launching with Launchy

Category: ProgrammingPhil @ 11:18 pm

I’m a bit of a keyboard freak. I’ll openly admit to people that I’d rather hit the win + r + calc key combination to get to the calculator. I’ve been known to challenge people to try and beat me to open an application with their mouse versus me and my run dialog. I love the run dialog in windows and in fact I’d say it’s another one of the things I’ll have to add to my Geek Related OCD list… randomly hitting win key + r…

However, despite my love for the Run dialog, it’s been superseded by a new kid on the block. Thanks to Launchy the run dialog is now obsolete.

I have to admit, I wasn’t convinced that Launchy would be able to live up to the lofty standards set by the run dialog, but after five minutes of configuration, move over windows + r and say hello to Alt + Space.

Launchy is the Run Dialog on steroids. To launch launchy, you simply press Alt + Space (default) and start launching.

It automatically indexes the contents of your start menu, but you can also tell it to index and .exe and directory locations. If Launchy wasn’t cool enough, it’s also got some pretty sweet plugins like Webby which lets you launch common websites and Runner which allows you to configure custom commands to launch applications.

Runner is especially cool because I can map individual letters to certain applications like mapping O to Outlook so now all I have to do to get to my email is alt + space + O and I’m elbow deep in emails.

And launching calc from the run dialog is now a thing of the past because Launchy comes with a built in plugin called Calcy which allows you to type in simple mathematics equations and Launchy will tell you the answer straight away.

If you’re into skinning, then Launchy also caters for you, but the skins it comes with by default are already pretty slick.

All in all it’s a very slick app and is one of those apps that does the job it’s supposed to do with minimum fuss and maximum results and will have you falling in love with your keyboard all over again.


Jan 16 2008

Top tips and tricks for code generation

Category: .NetTiers, Programminglomaxx @ 11:07 am

If you’re like me, a lot of your development work will involve generated code. I love code generation and use CodeSmith and Iron Speed regularly so I’ve put together my list of top tips and tricks for code generation.

  1. Databases are the cornerstone of code generation so it is crucial that you keep your database in pristine condition at all times. Your database should never be taken lightly and some of these suggestions might seem obvious, but they are doubly important for databases that are used for code generation. If you’re creating a table with foreign key references, always ensure that you add them in when you’re building your table. It will save you much heartache and probably a re-generation or two in the long run.

    Use a naming convention for tables and fields and make sure you stick to it. By doing this, you can design your templates to behave consistently.

    Try not to use keywords from SQL or the programming language you are using for table or column names as it will mean you either have to cater for these in your templates, or spend time debugging the problems when the code is generated.

    Ensure that you have primary keys on all your tables.

  2. Active Generation + Passive Generation = Total Control.
    Active generation is the concept that your files are blown away and overwritten on each code generation. Passive generation refers to generating code once and never touching it again. There are people that will argue that one method is better than the other, but I’m a big fan of using both to ensure that you have complete control over your application. In a perfect generation scenario, you will actively generate base classes for each file that are constantly being overwritten each time your code is regenerated, but then you will also have passive classes that inherit from the base classes. These passive classes are generated once and never generated again and will then contain your custom code that can’t be generated.

    The advantage is that you are able to add custom code without fear of it being blown away yet still have confidence to know that a regeneration will completely refresh your code files.

    Passive generation is even easier in .net 2.0 with the introduction of partial classes meaning that you don’t even have to inherit the passively generated class from the base class, you just need to name them differently.

  3. Allowing your functions to be overridable is an extra way to ensure that your generated code is completely flexible. So often I see people generating a method like SaveData() and then in their custom code they’ll have another method that is named something like SaveCustomData(). This then creates confusion because someone wanting to use that object in the future isn’t sure which Save method to use and if it’s even safe to use the SaveData() method. If you had allowed your SaveData() method to be overridable in the first place, you could have simply written your custom code in the overridden method and there would be no confusion as to which method to use.

    It also means that if you change the save logic, you don’t have to go and find every instance where the original method was used and change it to the SaveCustomData() method.

  4. Not everything can be generated and nor should it be. It is very important to realise that whilst code generation is useful for cutting down the mundane tasks such as building objects or writing stored procedures, there are times when you’re just going to have to roll up your sleeves and write some custom code. Don’t fall into the trap of thinking that code generation means you won’t have to write code ever again.

  5. Generate often. Once you have your templates, you should re-generate and re-compile your code often to ensure that you pick up any problems with your templates or the generated code quickly. I’ve found that the quicker you find a bug with your templates or the code generated from your templates, the less time it takes to track down the cause of the problem and the easiest way to do this is to re-generate your code.

  6. Continually add to your codebase via your templates. People are often adding really useful bits of custom code to their generated classes which is great, but you shouldn’t be afraid to add that custom code to your templates if you can find a way to apply it in a generic fashion. Don’t be afraid to let your codebase grow, having extra methods on your classes is only going to make those classes more useful and the framework you’ve created around your templates more powerful.

In summary, I feel code generation is a great asset to any developer’s toolkit and hopefully these tips and tricks can help you get even more out of these already powerful tools.


Jan 09 2008

Geek Related OCD

Category: ProgrammingPhil @ 12:30 pm

If you’re one of these people that has Geek Related OCD you’ll understand why I had to install XNeat.

You know who you are.

You’re the type of person that has to keep your desktop clear of all Icons other than My Documents, or conversely you can’t save anything anywhere other than the desktop. Perhaps it’s your programs menu in your start bar that you religiously sort, organise and cull after every application install. The sight of an unauthorised icon just makes your eye start to twitch.

Maybe the desktop isn’t your thing, maybe your MP3’s need to be sorted by Artist, Year and Album and if you can’t find album art for your album you either scan it in yourself or simply delete the album because you can’t bear the thought of an album in your collection without a pretty picture telling you what the album is. You video collection is organised alphabetically into separate folders with a subfolder for each series, and again, album art is compulsory.

Ha! You say, I don’t have OCD, but have you found yourself opening your web browser without and instinctively typing in a forum address to check for latest posts or replies to your previous posts? Does every forum you’re a member of need to have your avatar, your sig and your funny little quip so people can recognise you no matter which forum you’re on?

I don’t go on forums you say, I can’t have OCD. But you’re wrong, because maybe your OCD is embedded deep in your subconscious. You’re OCD is showing without you even knowing. In fact you’re probably doing it now. You’re highlighting paragraph text while reading articles, scrolling the scroll wheel up and down while waiting for a page to load or pressing the arrow keys on the keyboard in a predefined pattern for no explainable reason.

OCD… pfft… I’m in control of my actions you say, but perhaps your vice is e-mail. When was the last time you hit send and receive even tho you have outlook set to send and receive ever 2 minutes? Why do you need to hit it if it does it for you? You can’t work it out can you?

Email not your thing? What about RSS… c’mon, everyone has RSS, including you, and even tho you’ve subscribed to the feeds in your reader, you can’t help but check manually in case there’s a super important feed you need to read.

Geek Related OCD isn’t just about things that you have to do. It’s also about things you can’t do. Like how you can’t use the numeric keypad, how you can’t use the keyboard for copy and paste and how you are chained like a slave to your desk until you press the WINDOWS + L key combination to safely lock your computer. Even when you have locked it, you’ll be in the middle of a meeting and suddenly catch yourself trying to remember if you’ve locked your terminal.

It’s possible that you Geek Related OCD is quite advanced. In fact, it’s serious. You find yourself ghosting your machine after every new piece of software is installed. You backup your outlook file at the end of every day. You have a spreadsheet of all the serial numbers for every piece of software you have ever purchased which you simultaneously backup to 7 different locations after every new key is added.

Geek OCD can be costly too. How did you feel when the latest Nvidia gaming card came out? Were you able to just read about those benchmarks that ran the latest game at a silky smooth 60FPS with everything turned up, or did run down to your local computer store and smack $800 worth of pixel shader glory onto the credit card?

Anyway this has turned into somewhat of a rant, but the point is that you might be suffering from Geek Related OCD you’re not alone because it’s the reason why I had to install XNeat.


Jan 05 2008

The argument for Singular Database Table Names

Category: ProgrammingPhil @ 10:00 am

I was having a conversation with a colleague the other day about whether database table names should be singular or pluralised. I personally have always believed in singular table names in my databases for a few reasons:

  1. Pluralisation doesn’t play nice with code generation.
    If you’re like me, you probably use a number of code gen tools like Codesmith or perhaps Iron Speed. The code is more often than not generated off the database schema and objects are generated of the table names. When you’re generating your objects off table names it becomes difficult to take the pluralised version of the table name back to the singular version. For example, a People table needs to become a Person object and an Addresses table needs to become an Address object. Unless you implement a special case in your templates for each of these table types, your objects are going to become awkward in your code.
  2. What do your objects represent?
    When I start talking about table naming and pluralisation, one of the most common arguments for pluralisation is that a Customers, table for example, is a collection of Customer rows, therefore it should be pluralised. This is fine in theory, but if this is your argument then to me it would seem that the logical thing would be to structure your objects in code so that the Customers object is a collection of CustomerRow objects. If you’re going to implement this structure, then fine, but very few people do, yet they still pluralise their database table names.
  3. It helps make things consistent
    It’s obvious that if you call your table name Customer it’s easier to then keep it consistent throughout your application by then being able to name your objects Customer, however it also means that you will be able to name your columns consistently, in particular your primary key. For example if you have a Customers table, your primary key will be CustomerId. That’s not so bad, but what about the Addresses table, it will have an AddressId. It’s not a huge issue, but in terms of database style, I like the consistent look and feel much better.
  4. The tables and objects are grammatically easier to work with
    Again this one is a personal preference, but when you pluralise the tables, your SQL queries will begin to look like SELECT Customer.CustomerId FROM Customers or worse still, SELECT Addresses.AddressId. This then translates to your objects in code which will then look like Customers.CustomerId or Addresses.AddressId. If you want to avoid that situation, you’ll have to do the translations manually which takes away from the consistency and obviously, you’re adding an extra step to manually convert the pluralised table to a singular object.
  5. It doesn’t fit the model
    When you’re modelling the application in UML or any other design tool, your actors are always represented in the singular. Translating this to a plural database table is just another case of inconsistent style.
  6. It makes many to many relationship tables look stupid
    When you have a situation where you need to create a many to many relationship like users to groups, you have the situation where you’ll have a Users table, a Roles table and then the many to many table should by rights be called UsersRoles, but more often than not it gets called UserRoles. If you had singular table names in the first place, you’d simply have User, Role and UserRole.

I guess at the end of the day, it doesn’t really matter if you have singular or plural table names in your database but my personal preference is for singular.


Jan 02 2008

Protecting your Quick-Saves

Category: ProgrammingPhil @ 2:23 pm

I’ve been playing BioShock recently and whilst it’s an impressive game, it has an implementation of quicksave that is similar to a lot of games and it’s an implementation that I don’t like. The problem that I have with BioShock’s implementation of quicksave is that it continually overwrites your previous quicksave. Some people might think this is a good thing, but I recently found out why it wasn’t so good.

I had played my way through about 30% of the game and after killing one of the Big Daddy’s I quickly hit F8 for a quicksave but for some reason the save failed and the application crashed. To my great dismay, when I fired the game back up, my quicksave file was corrupted and I was unable to re-load my game. Needless to say I was more than a little annoyed. Luckily you get an autosave at the beginning of each level, which took a little of the sting out, but still, I’d have to take down that big daddy again.

The more I thought about it what annoyed me even more was how ridiculous this quicksave mechanism is.

I wasn’t annoyed that the game had crashed really, it’s a little inconvenient, but no big deal to fire it up again and pick up where the last save had occurred but if that quicksave doesn’t work… that’s unforgiveable. It’s also annoying if you hit quicksave in a spot where you don’t really want to quicksave, for example when you know you’re going to die so want to skip the death scenes and reload. If you accidentally overwrite your previously useful quicksave with a now useless quicksave, you either have to go back to the start of the level and work your way back up again, or you have to try and salvage the accidental quicksave.

In future, I’d like to see game developers implement a quicksave that would create a pool of say five recent quicksaves which it cycles through and overwrites the oldest previous quicksave so you’ve got a few previous quicksaves to choose from. This way you have a bit of protection from corrupted quicksaves and you also have the ability to go back to a few different parts of the game if you miss something or just want to kill a big daddy again J

Without the implementation of some sort of quicksave protection, quicksave is just too risky for me to use in future.