Back

Lazy Programmers User Code Snippets

Full property snippet

The best programmers are lazy

The great Larry Wall (author of Perl) claimed that laziness is one of the greatest virtues a programmer could develop. The best programmers are lazy in the sense that they do not write duplicate code or take pleasure in writing boilerplate code. They are efficient in writing code that follows the DRY, KISS and YAGNI principles.

Efficient IDE usage

Next to writing as few lines of code as possible (without compromising on readability ofcourse), being a lazy programmer also means using the IDE efficiently.

This means:

  1. Knowing when and how to use the various project and project item templates.
  2. Using keyboard shortcuts instead of navigating through long menus.
  3. Using code snippets instead of writing boilerplate code.

Code Snippets

Ever since the 2005 edition, Visual Studio allows inserting blocks of reusable code, called code snippets, through shortcut keys (or the context menu, but truly lazy programmers don't take away their hands off the keyboard).

I'm still amazed by the fact that so many .Net developers are still not aware of these code snippets. Using these can really speed up writing commonly used bits of code like properties with backing fields, try/catch blocks, foreach loops etc.

So if you want to be a lazy programmer learn these snippet shortcuts by heart!

  1. ctor - constructor
  2. prop - auto implemented property
  3. propg - auto implemented property with private setter
  4. propfull - property with backing field
  5. if - if block
  6. else - else block
  7. try - try/catch block
  8. tryf - try/finally block (oddly enough there is no trycf!)
  9. for - for loop
  10. forr - reverse for loop
  11. foreach - foreach loop
  12. switch - switch block

Simply invoke the snippet by typing the shortcut followed by [TAB]. Here's a list with more built-in shortcuts if you're eager for more.

Get lazier: write your own snippets!

If you want to be as lazy as me you can easily write your own snippets as I've done for extension methods, unit tests and more. The Snippet Designer plugin can be useful if you don't like editing the raw XML.

Enjoy lazy coding!