title: Small lessons, loosely learned url: https://adactio.com/journal/10078 hash_url: 5ca3d2195e5b23f6dca45fcab9327040
When Charlotte published her end-of-year report, she outlined her plans for 2016, which included “Document my JavaScript learning journey.”
I want to get into the habit of writing one JavaScript post every week to make sure I keep up with learning it. Even if it’s just a few words about some relevant terminology; it can be as long or short as desired or time allows, as long as it happens.
An excellent plan! If you really want to make sure you’ve understood something, write down an explanation of it. There’s nothing quite like writing to really test your grasp of an idea. Even if nobody else ever reads it, it’s still an extremely valuable exercise for yourself.
Charlotte has already started. Here’s a short post on using JavaScript to pick a random an item at random from an array:
Math.round(Math.random() * (array.length - 1))
It might seem like a small thing, but look what you have to understand:
Math.round
works (pretty straightforward—it rounds a floating point number to the nearest whole number).Math.random
works (less straightforward—it gives a random number between zero and one, meaning you have to multiply it to do anything useful with the result).array.length
works (seems straightforward—it gives you the total number of items in an array, but then catches you out when you realise there can never be an index with that total value because the indices are counted from zero …which gives rise to an entire class of programming error).I really like this approach to learning: document each small thing as you go instead of waiting until all those individual pieces click together. That’s the approach Andy took when he was learning CSS and it led to him writing a book on the subject.
When it comes to problem-solving in general (and JavaScript in particular), I have a similar bias towards single-purpose solutions. Rather than creating a monolithic framework that attempts to solve all possible problems, I prefer a collection of smaller scripts that only do one thing, but do it really well; the UNIX philosophy.
Take, for example, Remy’s bind.js. It does two-way data-binding and nothing else. If you only need one-way data-binding, there’s Simulacra.js, which takes a similar minimalist, hands-off approach.
This approach of breaking large problems down into a collection of smaller problems also came up in a completely unrelated discussion at work recently. I floated the idea of starting a book club at Clearleft. Quite a few people are into the idea, but they’re not sure they could commit the time to reading a book on a deadline. Fair enough. Perhaps we could have the book club on a chapter-by-chapter basis? I don’t think that would work all that well for novels, but it did make me think of something related to Charlotte’s stated goal of learning more JavaScript…
Graham has been raving about the You Don’t Know JS book series by the supersmart Kyle Simpson. I suggested to Charlotte that we read through the books at the rate of one chapter a week. The first book is called Up and Going and our first chapter will be Into Programming, starting this week. Then at the end of the week we’ll get together to compare notes.
I’m hoping that by doing this together, there’s more chance that we’ll actually see it through to completion:
Why can I hit deadlines imposed by others, but not those imposed by myself?