Iris Classon
Iris Classon - In Love with Code

Stupid Question 139: What is a shim?

[To celebrate my first year of programming I will ask a ‘stupid’ questions daily on my blog for a year, to make sure I learn at least 365 new things during my second year as a developer]

What is a shim?

Putting the final touches on the exam project me and PA have been doing I had my colleague James look over our jade markup. “What do you think, pretty?” He had been using the serenade.js template language also inspired by HAML (and Jade), last summer I was in on that project and I had a hard time wrap my head around it but I really like it now. “Have you added any shims?” He asked. “What is a shim?” I asked back.

Let’s find out!

The dictionary explanation of a shim is:

A thin, often tapered piece of material, such as wood, stone, or metal, used to fill gaps, make something level, or adjust something to fit properly.

And what does this have to do with programming? Well, shims are application workarounds that help fit when there are compatibility issues. It’small library makes an older part of an application (that has to be kept and can’t be redone) work with the new additions/changes. Think of it as a compatibility layer. The shim James was referring to was one for HTML5, more specific the HTML5Shiv, which enables styling of HTML5 elements in IE explorer versions sub 9.

Adding HTML5Shiv
[sourcecode language=“html”]
//

[/sourcecode]
In Jade
[sourcecode language=“html”]
//[if lt IE 9]>
script(src=‘http://html5shiv.googlecode.com/svn/trunk/html5.js')
//<![end if]
[/sourcecode]
So the shim was added to the project, and I learned something new. They really do have a name for everything, and a library for everything, a fix for everything. Except the iPhone viewport scale bug. But that is a whole other story.

Comments

Leave a comment below, or by email.
Sop Killen
2/1/2013 12:21:52 PM
Thanks for the article! I've just encountered shims myself in javascript. Great stuff!
Btw, I've never used jade, but judging from html example, shouldn't it read lt (less than) instead of gt (greater than) in the jade example? 
Iris Classon
2/2/2013 7:41:25 AM
Reply to: Sop Killen
LOL you are absolutely right! I corrected that :D 


Last modified on 2013-01-30

comments powered by Disqus