Thursday, May 28, 2009

Lunchbreak: jQuery Habits

Recently, jQuery has become by far my most favorite JavaScript framework. It's so freeing to be able to use statements like $(".restricted-admin").hide(); to hide elements en-mass, based on CSS class, or to be able to fade things with a similar statement, load page content via AJAX in two lines... yes, jQuery has become the new object of my amazement. It has made JavaScript website enhancement easy for the first time, ever.
My only concern is that it's too easy to encourage healthy programming practices. JavaScript is a funny little scripting language, in which you can create functions/objects mid-statement. So, you can make a statement like this:
$(".button1").click(function(){alert("we're inside a function!"); alert("hooray!");});
...with absolutely no grief. This is absolutely amazing, considering how much it streamlines the coding process. If I need a callback function, I can write it where and when I need it. Recently, though, I've noticed myself slipping on some of the more fundamental aspects of SE...
Particularly, the finer grains of encapsulation/"granulation" - having the ability to write functions inline has given me the nasty habit of re-writing code in a bunch of places, where I need it. It's good that I've caught myself early enough to force myself into good practices.

Wednesday, May 27, 2009

CSS Fundamentalists

During the last week of the spring semester, I was roped into several heated conversations regarding web development. In all of these conversations, people somehow managed to get me to argue on the side of tables versus divs & css.
To me, having a good deal of practical web development experience, these "CSS fundamentalists" are scary. Now, you might call me pretentious, but web developers are not necessarily going to be good programmers, and likewise, good programmers may not always make the best web developers. However, there is one paradigm that I believe web developers and programmers alike can agree with: less work + stable result is always going to be a goal to strive for. In every one of these arguments, I had to bring up the issue of visual consistency. I've worked cross browser, cross platform, to try and get things to look the same on every browser I test on. In every case, a table will produce a more consistent result than a Div/CSS approach. I brought this point up, and the CSS fundamentalist would bring up two or three possible solutions using divs, and more CSS. Of course, the more points I brought up, the more css they suggested, and the less likely it was to work on a variety of platforms.

The bottom line is, CSS is more work, for a less stable result. The only reason these people insisted on using it was because tables were "obsolete" ... which is a fairly arbitrary and unsubstantiated thing to claim, seeing as how they are still supported under W3C standards, HTML 5, and XHTML 1.0 Strict...

There are two valid arguments that I heard against using tables in design:

Tables were not meant for GUI design - Tables were meant to hold tabular data. This is a valid point, but then again, there isn't a whole lot designated in HTML or XHTML standards specifically intended to cater to GUI design. Every tag is meant to hold a specific, well-formed piece of data in the document. HTML as a whole was nothing more than a document formatting language to begin with, and it's only through hacking and adaptation that it has become so adept at GUIs.
Tables are not well supported by mobile browsers - Alright, you've got me there. Tables force a lot of scrolling in mobile browsers, whereas an extremely well thought out Div/CSS layout will automatically be collapsed to a simple, vertically scrollable format. However, if enough of your viewer base is going to be using mobile browsers, you've probably already got a mobile version of your site, specifically designed with minimal extraneous data. There's no need to sacrifice consistency on desktop browsers for the sake of a mobile browser.

Also, speaking from a perspective of practicality, W3C standards are largely useless. Half of them aren't even properly implemented by the browsers used by the majority of the world. It doesn't matter if you've done something right, if it doesn't work on the client's browser. Yes, there will eventually be a day when all browsers can pass the acid test on standards, and when standards evolve to support all platforms and content types in a way that doesn't fail so hardcore. In the meantime, I'll be keepin' it real with my tables.