Before you fans of JavaScript libraries (e.g. jQuery, MooTools, Prototype/scriptaculous, etc.) form a mob and beat me to death with your coffee mugs, let me quickly state that I am a BIG fan of JS libraries. They make life much easier in most programming scenarios, BUT…
Sometimes using them for smaller JavaScript tasks and effects is simply overkill. It does not justify the loading of a whole library of 30/40/or 60kB just to use a small portion of it, especially for client-side effects.
Case in point: I wanted to add the text resizer tools to my blog posts as you see on the right hand side and I started to determine the best solution to achieve this.
I like using jQuery for its elegance and simplicity but I find myself using MooTools a lot because it accommodates the use of classic JavaScript without complaining. It also keeps things simple for me since I also code in ActionScript, so the differences are not that varied.
I started coding the text resizer code in MooTools speak as following:
window.addEvent('domready', function(){ var currentSize = 12; $('increase').addEvent('click', function(){ sizeUp(); }); $('decrease').addEvent('click', function(){ sizeDown(); }); $('txtreset').addEvent('click', function(){ resetCurrentsize(); }); }); function getCurrentsize() { return currentSize; } function setCurrentsize(newsize) { currentSize = newsize; if (document.getElementById) { $("resizeableText").setStyle('font-size', currentSize+'px'); } } function resetCurrentsize(){ currentSize = 12; if (document.getElementById) { $("resizeableText").setStyle('font-size', currentSize+'px'); } } function sizeUp(){ if (document.getElementById) { if (currentSize != 14){ currentSize++; $("resizeableText").setStyle('font-size', currentSize+'px'); } } } function sizeDown(){ if (document.getElementById) { if (currentSize != 11){ currentSize = currentSize - 1; $("resizeableText").setStyle('font-size', currentSize+'px'); } } }
On top of that I needed to load the MooTools library and I wasn’t happy with the additional footprint this implies, so I set about refactoring my code to being plain old JavaScript with no additional library to load.
Here’s how it turned out:
/* ************************************************************** * Text-resizing script * Plain JS. No Mootools, jQuery, Prototype, or any of that bulk * * Copyright (c) 2008-2009 Figo Mago. All rights reserved. * * Released under the GPL license * http://www.opensource.org/licenses/gpl-license.php * Use this script as you wish, but please leave the notice intact * * Author: Sifiso Khumalo a.k.a figomago * Author URI: http://figo.tandolin.co.za/ * **************************************************************/ var currentSize = 12; el = document.getElementById("resizeableText"); function getCurrentsize(){ return currentSize; } function setCurrentsize(newsize){ currentSize = newsize; if (document.getElementById) { el.style.cssText = "font-size:"+currentSize+"px"; } } function resetCurrentsize(){ currentSize = 12; if (typeof(preDefaultSize) != "undefined") { currentSize = preDefaultSize; } if (document.getElementById) { el.style.cssText = "font-size:"+currentSize+"px"; } } function sizeUp(){ if (document.getElementById) { if (currentSize != 14){ currentSize++; el.style.cssText = "font-size:"+currentSize+"px"; } } } function sizeDown(){ if (document.getElementById) { if (currentSize != 11){ currentSize = currentSize - 1; el.style.cssText = "font-size:"+currentSize+"px"; } } }
(For some strange reason using “currentSize–;” in the code display messes up the front page display on this blog. Substituting the longer version “currentSize = currentSize – 1;” fixes that. Either version should work fine in your code)
The only downside is the addition of adding “onClick()=appropriateFunction();” to your tags, which I can happily live with.
I’m no financial guru, so please take what you are about to read with a pinch of salt. This is not meant to be taken as expert advice. Just an honest opinion of what I would do in these turbulent economic times if I could still afford to keep my house.
I would not sell it. Why?
First of all I’d be selling in a depressed market, that means I would be selling it at a fraction of its real value. Secondly, because of this saying:
Bad money drives out good money
Bad money in this case would be the declining value of cash because governments all over the place are printing money (and in the process creating humongous deficits) in order to:
When that starts to happen increasingly, investment funds stop flowing into paper assets/ exotic financial instruments and run to the safety of tangible assets like gold, other precious metals, oil, and -yes – real estate, all collectively known as commodities (good money).
Because demand will have returned to commodities, their prices will shoot up as further pandemonium ensues.
It seems that in the panic we have all forgotten about past horror stories of hyperinflation. What I’m seeing now with rescue packages worries me because those are the very actions that can lead to hyperinflation. Yet we all seem to be merrily oblivious of the monster that might befall us.
Most of us alive today have never experienced hyperinflation (except Zimbabweans) and that painful experience may be just around the corner.
I don’t buy the story about inflation going down “because the economy is slowing down”. That’s talk of inflation from a completely different dimension. These are the reasons I think your house may pick up value sooner than you think.
If you had spare cash, now would be a good time to pump it into real estate. Property is cheaper and it will always be a good store of value.
If this does not happen you can rightly dismiss me as a bumbling quack who should stick to computer code. but I have the gut feeling that we are headed in that direction. Don’t get me wrong, the good times will be back, infallible human ingenuity will again find new ways to create great sums of money out of thin air. This will not happen before the crucifixion passes through.
One day it might be written in history books that the biggest economic blunder made in the 21st century was to not let financial institutions fail and let the markets correct themselves.
Without meaning to toot my own horn, I correctly predicted over a year ago that the overheated Chinese stock market would collapse and cause mayhem. This was largely overshadowed by the crisis that began in the US.
All the while, others were saying such a thing was impossible. Perhaps that’s because they honestly did not see it coming. So let’s not be too hard on our gurus. It’s important to be careful about whom to take advice from. This blog post by Dave Duarte backs me up on that front.
Let’s remember that it’s not nice to fool with mother nature.
A while back I stumbled upon this article by the team at radiiate.co.za. It speaks about the benefits and potential pitfalls of using agile development methods in general.
I was preoccupied with a lot of things at the time so the message did not really sink through that a lot of time and effort could be swallowed up by this approach, and that it is probably best left to internal or personal projects only.
The article mentions also Agile can be employed on client work if there is a clear understanding of the time and costs involved in journeying from point A to a hazy point B.
I could not agree more, especially after spending the past week on designing this blog (WordPress) and getting new ideas as I went along. I shuddered at the thought of having a client behave the way I did and yet being on a fixed budget.
Someone would have definitely got burned and I wonder, since Agile is the buzzword right now (especially in the Rails community), how this wildcard of a project scope is accounted for.
I don’t know too many clients who would be willing to hand you a blank development cheque, not least in these times of economic turmoil. What do you think?