• A Helpful Guide to Moving Away From jQuery (Via the Lonely Coder)

    moving truck

    Recently, I wrote a post about how jQuery’s prevalence on the web was causing web developers to learn less JavaScript and more jQuery due to how it conceals many of the more complicated inner workings of JavaScript in wrapper methods like bind and ready.

    Michael Enger over at The Lonely Coder seems to agree with me and he put together a really cool guide on how to replace some of the more common jQuery methods with their native JavaScript counterparts. In addition to going over how to replace ready and how to do event delegation, he does an excellent job of covering CSS selectors. From the guide:

    One of the greatest benefits of jQuery is to be able to drill down into the DOM by using CSS-style selector strings to specify which element you’re looking for. Something as complicated as “#app ul .title a:hover > span.left” can be used to choose one specific element, or a set of elements that are situated in various places around the document. Unfortunately there isn’t a direct replacement in native JavaScript, but a combination of getElementById, getElementsByTagName and getElementsByClassName, as well as iterating through the results, can be used to select the element(s) you need and not being able to rely on CSS pseudo-classes or some of the more esoteric selectors may result in structuring the HTML in a less convoluted way, avoiding unnecessary strain on the browser who has to deal with all your crazy shenanigans.

    // Get the data-foo attribute of all links inside a .button list
    var buttons = document.getElementsByClassName('buttons'),
        foo = '';
    for (var i = 0; i < buttons.length; i++) {
        var links = buttons[i].getElementsByTagName('a');
        for (var j = 0; j < links.length; j++) {
            var link = links[j];
            foo += link.attributes['data-foo'];
        }
    }
    

    Edit: My good friend Torjus Bjåen made me aware of the querySelectorAll function, which provides the same CSS-style selector capabilities that jQuery does, albeit without some of the more “magical” selectors. It works like you’d expect and can be used to easily fetch elements that may be spread about the DOM.

    var links = document.querySelectorAll('.buttons a.special');
    for (var i = 0; i < links.length; i++) {
        links[i].style.backgroundColor = '#f09';
    }
    

    I highly suggest you check out his guide, it’s an excellent starting place for those looking to move away from jQuery and to a more native approach.

  • Recommended Reading: How to Think Like a Programmer

    think like a programmer

    Recently, I began working on improving my problem solving skills as a programmer. Usually, this is done by trying to solve a series of increasing difficult puzzles. No, I’m not talking about the rumored Microsoft and Google questions of “How do you move Mount Fuji?” and “How many golf balls can fit in a school bus?” True programming puzzles (at least ones worth solving) are designed to exercise and evaluate your critical thinking skills. One great book for helping increase these skills is Think Like a Programmer: An Introduction to Creative Problem Solving by V. Anton Paul.

    Read more

  • Why Array.Splice Belongs With Push, Pop, Shift, and Unshift

    If you take a look at tutorials about JavaScript adding and removing items from an array, you’ll see four methods mentioned: Push, Pop, Shift, and Unshift. If you’re new to JavaScript or need a refresher, here’s a quick breakdown of each of those methods.

    Push

    Definition: Mutates an array by appending the given elements and returning the new length of the array. This method changes the length of the array.

    Read more

  • How to “Detect” If Your CDN is Down And Load a Script Locally As Backup

    system down

    I’m sure this has been around for a while now, but I just stumbled upon it and found it interesting:

    ...
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
    window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
    ...
    

    Basically, this does a check to see if jQuery has loaded properly from the CDN and, if it hasn’t, it tries to load it locally.

  • Semicolon Insertion: Or Why You Should Keep Braces on the Same Line

    When it comes to code formatting, developers can be pretty opinionated. Some believe in tabs while others like to use spaces. Some people believe the else statement should go on the same line as the closing brace of the if and some people think the else should go on the same line.

    Read more

  • Helpful Tools for Web Developers: TryRuby.org

    why's guide

    If you’re looking for an interactive way to mess around with Ruby without installing anything, I’d checkout TryRuby.org. It’s a really cool interactive terminal that let’s you execute ruby commands from the comfort of your browser. You can even step through a quick 15 minute tutorial inspired by Why’s Guide to Ruby.

  • Helpful Tools for Web Developers: Ruby Fiddle

    ruby fiddle

    Recently, I talked about my desire to learn more Ruby to help round out my skill set. Well, if you’ve ever taken up the task of learning a new language, you know that the most difficult part can be getting the proper development environment up and running, especially if you’re trying to run an open source language on a Windows platform. If you’re looking to start messing around with Ruby with out having to install anything, I recommend you check out Ruby Fiddle. It’s basically JsFiddle for Ruby developers and it’s a great way to both tinker with Ruby code and execute some of the examples in the Ruby Koans project I mentioned in an earlier post.

    As I’ve messed around with it, I have found a couple of weird issues. First, it appears that the “gistify” button doesn’t work as expected. Second, there’s no way for me to login and save the “fiddles” I make (JsFiddle allows you to do this). Hopefully these issues get fixed soon.

  • Learning Ruby Through Ruby Koans Online

    ruby

    As you’ve probably noticed, I talk a lot about front-end development on here. Recently, I’ve come to the conclusion that it’s about time I round out my skill set with a robust back-end language to balance things out. Originally, I thought about going back to PHP since I’ve already spent 4+ years developing in it. But PHP jobs are getting harder to find around here and I figured that I could challenge myself by attempting to master a new language that I don’t have much experience in: Ruby.

    To help my along my journey, I’ll be walking through Ruby Koans Online. Ruby Koans is a series of TDD-driven code katas designed to help you learn Ruby. Each week, I hope to go through a new koan and t hen write about it here. I highly encourage you to check out the Ruby Koans Online site and follow along with me.

  • Blue Collar Development Vs White Collar: An Important Decision

    5930363628_0191dfea84

    Recently, I’ve talked to several people about “white collar” vs “blue collar” development jobs. It’s an important distinction that I don’t think many people know about. But first, let’s establish what these two terms mean.

    Blue Collar Development: Development that is done on a system, application, or platform that is not the primary product being sold (e.g., an internal website used by an insurance agency for use by its agents).

    Read more

  • Are We Becoming jQuery Developers Instead Of JavaScript Developers?

    Recently, a fellow web developer asked me an interesting question: how strong are your JavaScript skills without frameworks like jQuery, YUI, etc.? While I am fairly confident in my JavaScript skills as a whole, it did make me step back and think: because of it’s prevalence, am I becoming less of a JavaScript developer and more of a jQuery developer? Are jQuery’s abstractions causing us (as developers) to forget how to work some of the more low-level areas of the language? For example, to stop even propagation in jQuery, you only need to do something like this:

    Read more