Both in PHP and ColdFusion I recently discovered that you don’t need to close certain script elements to have them run correctly, which is highly annoying coming from someone who has spent a considerable amount of time learning and abiding by XHTML rules. Internet Exploder was (and still is) famous for being flexible on letting users not close their tags properly.
This was acceptable at the turn of the century when website creation was more fashionable and less well-known. But for server side languages this just seems lazy. In PHP, you don’t need to put in the closing ?> and in CF I’ve witnessed a missing </cfquery>. I hope that this is a legacy element that has only survived because of older websites, but I doubt it since these could have been eliminated with PHP 5 and ColdFusion MX were released.
In general, I don’t care about the differences between server languages that so many have a personal beef with. The vitriol against CF is extremely virulent in some areas, but whatever, it serves its purpose well. It was also my first real markup language after HTML back when I was in college (1998, CF 3.0).
Having been exposed to CF for about almost 10 years now, and PHP for 5 years (my other major development platform) I’ve been able to really notice certain perks or shortcomings with CF when compared.
- Meh: CFWRITE doesn’t allow you to overwrite a file’s content; you can either append or destroy/create the file again, with the latter being very inefficient. This is most troublesome.
- Yay: CFIMAGE, from version 8 on, has built-in CAPTCHA which, if you’ve ever tried to encode it in PHP, is worlds easier. More can be found here.
I love JavaScript frameworks. Coming from a time when you had to code uniquely for IE (document.all) and Netscape (document.layers) most (including me) just did it for IE. Also, many of us were just learning about JS via the highly recommended Peachpit books, so we copied but didn’t understand. This was the late 1990s when Netscape still held onto a respectable portion of the browser market, but was waning fast due to IE 3. It was a brutal, semi-cryptic world of copy/pasta from websites that allowed you to perform amazing feats like rollover image swaps. Form validation was also the cat’s pajamas but very rickety since most people would only check for an actual length of string instead of whether the contents were valid.
Then, along came document.getElementById(nameOfId) and suddenly, scripting became easier. A LOT easier. Now, whether you were using IE or Firefox you could target the same element in the exact same way provided that element had id="nameOfElement" in it. This simplified using conditionals to determine the browser. Changing the style, font, background image, etc. was easy peasy. However, it was still messy with doing AJAX as IE (again) had a unique function call for initiating the necessary action, but it was still necessary.
NOW, we have the very efficient and very easy-to-learn (if you have some actual coding ability) JavaScript application frameworks. jQuery, Prototype, MooTools to name a few. I stick with jQuery primarily because it’s the one I was first exposed to. I dabbled with MooTools prior but found it very cumbersome at the time; this also was due to my lack of overall understanding. Each framework has its proponents, but 90% of them share the same basic utility and features. Their extensibility is where they really shine, allowing you to add AJAX on the fly, quick and painless form validation for a dozen types of data, animation and interactivity that would take hundreds of lines of code otherwise, and best of all, graceful degradation if someone doesn’t wish to use JS in their browser (nowadays, that’s quite rare).
I could tout on forever about all the sweet benefits it offers to those of us who are tired of reinventing the wheel of JS methods and objects for the same things, or wish to have nice and tidy code for simple features like mouseover opacity (IE6 required ugly hacks for this) and making sure an email entered is in a valid format.
Why must people insist on not following code protocol? Coding in general, and PHP in particular, uses lower case for variables (except constants), functions and whatnot. For coding languages that are case-insenitive we’ll use lower case on sheer principle. However, I found one coder who created this site that I’m constantly patching with e-duct tape managed to use Header("Location:blahblah");. It worked, which surprised me but the dev box I work on is very lax with error messaging. This is definitely a no-no in general, and something I would not let pass muster.
One habit I have when visiting websites is to look at their codebase, both for curiosity and for new/interesting code snippets. Today, I was going through Facebook’s code while playing Mafia Wars and, aside from the sheer volume of code, a few things that sort of surprised me:
- Liberal use of
onClick="" for basically all links that weren’t form buttons. This is DHTML 4.0 event functionality.
- Hundreds of lines of internal stylesheet classes, prefix-named according to a specific user id or session. For Mafia Wars, they preload all the possible classes used for any of the (currently) 3 locations you can explore. It’s never easy to have nice, clean, always external css, especially with a site this massive.
- About two dozen calls to external javascript and css files, all from the same server. They must have serious bandwidth
Granted, these aren’t by any means a knock against their coders. I’ve been fascinated by the sheer amount of data that goes between user and server for the Zynga games. It’s a feat in itself to command that much dataflow and event triggers and have a (mostly) stable environment for the user.
Plus, considering how long the site’s been around, there’s a lot of legacy code that’s most likely too difficult to extract to make the site work more efficiently. They would benefit greatly from using a JavaScript framework like jQuery, Prototype or MooTools, but trying to retrofit this into their current framework would be a bear, and quite frankly, is it worth it?
First post! I’m not sure exactly how this site is going to progress in terms of my daily experience with coding or the type of people that I know work with it, but it’s mostly for ranting about programming that my other outlets just won’t work as well on.
This is also my first Wordpress website. I’ve given up making my own cms on the grounds that I do enough wheel reinventing during regular hours so I should save time where I can. And sanity.
/begin