When I was a kid eager to jump to our XT computer with a massive 20MB harddrive to play text based RPGs (where @ was the lead character and # was a wall) my mother devised a cunning way to curb the habit. I could play when I wanted, but before I could play I had to do 10 minutes of Typing Tutor.

Fair, but I hated it.

But in hindsight, not a bad thing - I can type faster than I need to and I still had a childhood rich with many hours of hacking around in DOS, playing text games and levelling up my RPG characters.

 Screenshot of an old NetHack style RPG for nostalgic purposes (courtesy of the Wikimedia Commons)

I’m of the opinion now that being able to type fast, just like being able to talk fast, can at times be detrimental. For stuff to come out right the first time without tumbling over itself it needs thought through and structured. Rushing to express something and simultaneously create structure for optimal delivery often muddies and flusters thoughts. Like when you’re pairing and the keyboard operator subconsciously pauses mid sentence or releases a long “Ummmmm…” while they’re fixing brackets and white space.

I was watching a Scott Allen video the other day and was once again impressed by his clear, concise communication and almost effortless live coding skills. He worked the keyboard like a magician, shortcutting ReSharper, using prop and ctor snippets frequently. Code spilled onto his screen with just a few keystrokes and was elegantly refactored with even less.

It suddenly dawned on me that that is what I was missing, I had an epiphany :

Snippets aren’t just for slow folks!

My fast typing had held me back: I had dismissed snippets as useless and more effort than they’re worth, but here was evidence that they clearly were worth it.

I rushed to Tools > Code Snippets Manager and started exploring which ones were out there that I could use. Inspired I made a few more for JavaScript stuff I commonly do and I have a feeling I’ll be making loads more while I build up my efficiency.

Handy JavaScript Code Snippets

There are a few of the snippets I’ve put together for common JavaScript stuff, like Immediately-Invoking functions, Revealing Module Pattern and jQuery Document Ready wrapper function here.

But creating them is so easy and they can be so easily personalised to fit into how you as an individual dev think, that I’m kicking myself I haven’t used them more extensively before :)

Useful to know

  • In Studio 2012 Your custom code snippets are stored in %USERPROFILE%\Documents\Visual Studio 2012\Code Snippets\JavaScript\My Code Snippets

  • To represent a $ in a code snippet you have to escape it using a double $$ (because $ is used to delimit variables)

Blog Logo

Stephen James

JavaScript and Front-End Developer


Proudly published with Hexo

Stephen James' Code Blog

Back to Overview