Monday, February 22, 2010

Eschew Obfuscation

I'm going to go out on a limb and say that all types programming and software development, including web development and design, have the common need to eschew obfuscation.  There are more commonalities beyond this, of course. But, I'd really like to stress this one: Eschew Obfuscation!

This policy, if you will, is something that all Computer Science majors learn in the classroom—or were at least taught.  It's something that all web developers and designers are undoubtedly taught. And yet, the number of slow, cluttered, obfuscated, and even broken websites astounds me! The message behind the humorously obfuscated phrase has gone unheeded by many developers—most notably web developers. (Their work is generally the most visible.)

Unfortunately, there are too many platforms, languages, and pitfalls and not enough global obfuscation eschewing techniques to compile a "universally" comprehensive list. However, I'll touch on a few important things off the top of my head that I've been taught and/or discovered. So, here we go:
  • Normalize your data.
    Whether you think database schema, object model, or "what set of arrays do I need?" when you see this point, the policy applies. Make your data represent reality minus the overlap. Remember that any data that is duplicated anywhere needs to be updated in each location when that data changes. (unless each copy is purposefully meant to be different) This applies to objects, arrays, and database tables. Each is capable of "pointing" to a row or instance of another. Use this capability.
  • Use recursion when it fits the problem well.
    Some problems have a recursive solution. If that solution happens to be the easiest solution to think about and understand, use it. It will also be the easiest for future developers to understand when they're digging through your code.
  • Avoid recursion when it doesn't fit the problem well.
    Don't use recursion because you can make it work or when a similarly simply iterative solution is available. A recursive solution is generally a good deal slower than the iterative counterpart. So, if you're using recursion because it's 1337 or clever, stop! Despite what you may have heard, making your code more difficult, slow, and resource hungry is not very 1337 at all.
  • Use the best tool for the job.
    Don't use Perl because it makes you look smart. Don't even use Perl because you have an aptitude with Perl. Use Perl only when you're taking full advantage of it's ridiculously fast regular expression engine on very large blocks of text. Use CSS for styling. Use JavaScript or Flash for user-interaction. Et cetera.
  • Do not reinvent the wheel if a good one already exists.
    If there's an existing framework or application that does what you need, use it. If your application relies heavily on user-provided data to select DOM nodes, restyle them, move them around the page, and so forth, use something like JQuery. These types of libraries are usually written and optimized by a lot of intelligent people. It would be silly to forgo using a well-crafted tool that does what you need.
  • Don't use a wheel for its bolts.
    Including a library for one, two, or even a small handful of its features is often a horrendous waste of bandwidth and efficiency hit. Don NOT use JQuery solely—or even mostly—for the ability to select nodes by ID using the $ function. Use the methods that the DOM already provides or write your own $ function that does precisely and only what it needs to do.
  • Give "things" to your future programming staff and your end-users in small, hierarchical chunks.
    Your navigation, content, and code should be hierarchical, each chunk containing only a "handful" of information, which may reference and/or be part of other chunks. Each chunk should be a complete thought or process, able to be understood, proofread, optimized, or debugged on its own. This will help ensure maintainability, efficiency, and good end-user experience.
  • Write and design so that 5-year ago you could understand what you've done.
    This may be hyperbole. But, as you become a "better" developer, your coding style will naturally become more complex. You will find neat ways of doing things you hadn't thought of before. You will find new ways of combining lines of code. You will more effortlessly throw complex chunks of code together in complex ways, and so forth. However, if your previous self would not be able to readily understand your current code, there is high probability that your code is both inefficient and difficult to maintain. Remember, while you grow more sophisticated, the compiler (or parser) is still a relatively stupid thing, designed and optimized for simplicity. The same is probably true of your successors. :-)
Take all of these thoughts with a grain of salt, of course. Sometimes a more complex seeming solution will yield significantly better results in some area. But, you ought to show significantly increased benefits before choosing a solution over a simpler solution.
    Simple is easy to create, easy to maintain, and easy to look at. But, don't stress out if you can't simplify a solution. Remember, sometimes the simple solution is merely the simplest of several complex solutions. Do your best!

    Now, go forth and Eschew Obfuscation!

    Monday, December 7, 2009

    (IE8) Cookies have been reassembled!

    Well, I said I would post back when I determined in what way IE8 was breaking my cookies, and I think I have.  The issue seemed to be a combination of a difference in behavior in which IE8 handles session cookies (cookies that are deleted when the browser closes) for linked resources (such as my opensearch xml specification) and an authentication policy I previously had on Svidgen.  That is, until recently, any un-authenticated HTTP request acted as an explicit sign-out.  I think this would still be a nice security precaution to implement, but IE8's cookie handling won't allow it.

    My initial quick-fix for this issue was to give my opensearch specification some caching rules that would encourage browser to avoid requesting the spec on each page load (they really shouldn't be anyway).  However, because these caching directives are not necessarily adhered to, I have now also changed my session behavior to some extent.  Unauthenticated HTTP no longer act as an explicit sign-out on Svidgen.  If this behavior doesn't seem to match your experience with the site, please let me know as soon as possible!

    I also found some forum posts floating around which suggested that IE8 requires the domain attribute to be set in cookie headers.  I updated all of my cookie-setting code to reflect this alleged requirement, because it's good to be explicit.  However, I am very skeptical that IE8 ignores cookies without an explicitly set domain.  In fact I think the requirement was probably "deduced" by a shoddy developer at whits end ... Point me in the direction of some documentation if I'm wrong.

    Wednesday, November 25, 2009

    Internet Explorer 8 broke my cookies!

    Fairly recently, I discovered that svidgen.com does not properly manage sessions with IE8.  Is seems as though the general session cookie (svession) is being set and maintained correctly in all browsers, including IE8.  However, my "subsession" authentication token (atoken) headers are not being respected by IE8 in all cases, causing signin to last for only a single page view.

    After spending some time Googling around, it seems as though some other folks are having similar issues.  And, from what I can tell, this may have something to do with "enhanced" security on cookie handling in IE, which requires cookies to have the domain explicitly named--though I have yet to find any Microsoft-published documentation to confirm this.  In fact, I have yet to see any Microsoft-published documentation on cookie-handling in IE8 at all.

    Can anyone point me in the direction of this documentation?  I can't find any cookie information on the IE8 Readiness Toolkit for Developers.  But the information regarding changes in cookie handling must certainly exist somewhere ... mustn't it?

    In any case, I'm working to resolve the signin issue as soon as possible.  If you have any information that might help me resolve the issue more quickly, it would be greatly appreciated.  And of course, once the issue is resolved, I will post again with any information that may help other developers who are experiencing IE8 cookie issues.

    Thursday, October 22, 2009

    Search Engine Optimization (SEO) woes

    Search Engine Optimization (SEO) is a curious thing. Search engines are designed and continually optimized to provide better results, based on what searchers want to see. These engines take advantage of Artificial intelligence (AI) algorithms to index pages in a meaningful way, with respect to quality content.

    Why then, should anyone even be seeking SEO services? Is a page with quality content not already optimized for good, intelligent search engines? Is SEO not necessary a hit to the quality of your content?

    ... SEO is a screaming confession of low quality content! If you feel the need to optimize for search engines, either they're not doing their job, or you're not. (most likely you) And with search engines taking a harder approach on SEO, incorporating more and more anti-SEO intelligence, investments in SEO are likely to quickly lose their value anyway. Why lose out on quality content and money? Just produce quality content from the get-go, and if you don't make it onto the first page, at least you'll still have quality content.

    Seriously folks, stop posting in forums about SEO best practices. Just produce some damn quality content! If folks like your page, they'll write about it in their blogs, and your site will flourish on its own.

    That being said, be a friend and write about one of my sites in your blog :)

    Friday, October 9, 2009

    JavaScript: Script-ably Rewriting a Function

    I've seen numerous posts in forums in regards to the ability to access, and sometimes modify, the contents of a JavaScript function dynamically (using JavaScript itself of course). To respond "globally" to these questions, I've created a quick little demo, hosted on Svidgen: JavaScript: Script-ably Rewriting a Function.

    I considered posting the code for a brief moment; but, the demo provides a relatively simple look at script-ably playing around with JavaScript functions. Accessing the "contents" of a JavaScript function is simple; but the entire function definition is returned. So, editing the function on the fly and "recompiling" it isn't perfectly straightforward, and it's best to just see the demo if you're interested.