Friday, April 22, 2011

The value of a $

What really does happen when you type $ into your code?  I know it’s magic, but what really is going on?  I keep that in mind when doing anything with jQuery.  I always ask, is this the most efficient way to handle this task?  No matter how far I’ve progressed, looking at code I’ve written in the past always makes me shiver.  YOU SHOULD TOO!  Everyday is a learning experience; finding new techniques and trying them out will catapult you to new levels.
As I progress along finding the happy medium between jQuery and it’s parent: Javascript, I’m always looking for simple tweaks to optimize my code.  I’ve taken the time out to show a simple example of two different ways to populate a drop down.  Can you guess why the .append() method takes longer?

There’s a good reason why.  During the for loop, each option is being appended to the select.  That means I’m calling jQuery to work it’s magic EVERY time within this loop.  In this example, the code literally has to traverse the DOM 100 different times.  Even though each option is going to the same destination!  So, let’s look at it this way. 

If you had to walk across a fiery pit barefooted multiple times, would you carry as much as you possibly could each time or would you continually make that trip over and over again?  Personally, I’d run and not walk, but that’s just me…  Hopefully, that makes some sense.  Building an array full of the options and then traversing the DOM once, is infinitely more efficient.  I only make a call into jQuery once.  That’s an important distinction between these two techniques.  Traversing the DOM using jQuery is a slow task in some regards, especially in the example above.
Feel free to play around with the code sample provided and see if you can come up with some more techniques where this same logic can be applied.  It may just save you some time…

Sunday, April 3, 2011

Use Notepad++ instead of SharePoint Designer

I build and configure a lot of VM’s and I found a need to keep my IDE consistent across all of them.  Since I use Notepad++ for most, if not all, of my code; it’s absolutely necessary for me to have the same toolset no matter what VM I’m working in.  I’ve taken what I liked most about SPD and added it to Notepad++.  You’ll notice when you right click, you can select a tag, for example.  I’ve added a whole lot more capabilities also.  Check out the video to see what you can do with it. 

How to get it installed?

Unfortunately DropBox allows you to only share files.  For now, you can download the ProgramFiles/AppData from here.  You don’t need DropBox to make this work either.  All you have to do is install Notepad++ and then rename the Notepad++ folders.  Put a new Notepad++ folder in its place instead, then copy the files from above into those folders. 

The Sysinternals Suite helps by providing the junction.exe tool.  Without this, I’d have to manage my IDE in many different environments and I would never have the same experience across the board.  I highly recommend to have these tools on your box if you want to do anything remotely fun with your computer.

What can I do with it?

Lots!  This is just a glimpse into what you can do with it.  I didn’t even have enough time to go over the code snippets.  I hope you enjoy your new Notepad++ capabilities.  Definitely click on the Plugins menu and explore.  There’s a whole lot of interesting things you can do with it.

Update: I almost forgot to mention where I learned the junction.exe technique from.  My buddy Ravikanth Chaganti first introduced me to the technique with this post.  Excellent work Ravi!


Technorati Tags: ,,