Monthly Archives: June 2015

Notes on JavaScript Allongé by raganwald, Part 1

Yoat.

Here are some unstructured notes on what I’ve learned reading raganwald’s excellent and free JavaScript Allongé, which you can read here: https://leanpub.com/javascriptallongesix/read. This is the “Six” edition, which reflects major updates to JavaScript currently being rolled out, usually called ES6.

Reg Braithwaite is an excellent writer. I’ve been putting off learning ES6 for a while, so I’m pretty stoked to find he’s written a fairly comprehensive piece on it. Anyways, notes:

  • I never knew about the “arguments” keyword in JS. That’s not even a new ES6 thing. Well.
  • All values are expressions. i.e., “a café Cubano is an expression (you can use it to place an order) and a value (you get it back from the barista).” You give the computer expressions, and it returns values. Okay. Cool.
  • “Value” and “primitive type” are fairly interchangeable in JS. They are numbers, strings, or bools.
  • In some languages like Lisp, expressions are values. Not so in JS.
  • “A literal is a notation for representing a fixed value in source code.”
  • 042 === 34; // starting literals with 0 turns it into an octal.
  • Node’s –harmony mode is pretty useful while reading this book.
  • If you want to return undefined, return “void 0”.
  • Statements, like return, exist only within blocks.
  • JS evaluates expressions to values before passing them as arguments.
  • “A free variable is one that is not bound within the function.”, e.g. those produced by closures.
  • Invocation is much more expensive than expression evaluation.
  • “[const statements] shadow values bound within environments created by blocks”
  • ES6 allows for incredible self-indulgence:
    ((diameter_fn) =>
    ((PI) =>
    diameter_fn(2)
    )(3)
    )(
    ((PI) =>
    (diameter) => diameter * PI
    )(3.14159265)
    )
  • WordPress didn’t format that last thing very nicely and neither will I.
  • An anonymous function can be bound to a named reference. Functions can also be named. These are two independent things. A function’s name is a property of the function and has no effect on the environment, but the name of its reference is the environment’s concern, not the function’s.
  • A named function is available to be invoked within that function, like for recursion if ya wanna.
  • Function declaration refers to the following syntax:
    function someName () {
    // ...
    }
  • Function expressions look like this (among other ways):
    const a = function () {
    // ...
    }
  • It’s relevant to note that the above is an anonymous function. Naming it would look like this:
    const a = function someName () {
    // ...
    }
  • Only declared functions are hoisted to the top of their scope.
  • Function declaration is not supposed to occur inside a block. It might work, but it’s a bad and un-guaranteed thing. Only use it at the top scope.
  • If a function is declared inside an expression, that function is an expression. Not a declaration.  Because.
  • The last few code examples weren’t ES6-specific, just JS things I had never bothered to really learn. You can get pretty far with only a shallow knowledge of JavaScript.
  • Here’s a simple combinator function:
    const compose = (a, b) =>
    (c) => a(b(c))

    “Combinators are useful when you want to emphasize what you’re doing”.
  • Decorator functions accept a function and return a modification of that function.

Okay that’s as far as I got today. Adios!

Leave a comment

Filed under Uncategorized

Things that might help beginner learners

I was a TA at Dev Bootcamp in San Francisco for two months, and now I write Ruby professionally (though at a junior level). Here are some things I know about learning Ruby and web dev in general that come into play for learners. I doubt this format will be terribly useful for actual beginners, but it’ll be a handy reference for me as I write more in depth and useful articles on these things. If it’s targeted at any particular group, it’s to people beginning to learn Ruby with the intention of entering the web development industry, like for example code school students.

– The | key is right above “enter” on your keyboard. It’s called a bar.

– Microsoft Word is used to edit text, but it’s not what developers mean to when they say “text editor”. They mean programs like Sublime Text, Atom, or vim.

– Don’t use vim as your first text editor; it has a very steep learning curve. I recommend Sublime Text 2 or Atom to start. Experiment with vim later.

– Most developers aren’t particularly smart or motivated. Don’t worry if you think you don’t measure up. Most of them are very unsurprising.

– Don’t name things after their type. It might might seem nice and explicit to name your Hash hash, but try and evaluate hash in irb without having declared anything with that name. It’ll return a long number, which you can confirm for yourself by evaluating hash.class. You can read about this behavior here, but it’s not very important. It can get confusing and weird.

– If you see a # before a method name in documentation, it means it’s an instance method. Don’t type it like that in your code, go ahead and replace it with a period when you use it. Class methods are denoted in documentation with a leading period just as they would appear in code, like String.try_convert, for example.

– Nerds call the # sign a pound or a hash, usually, and sometimes an octothorpe. Not a hashtag, but that’s fun to say to piss them off, like saying Frisco to Friscans. Likewise, ! is usually called a bang rather than an exclamation point.

– “Syntactic sugar” is any type of syntactic shortcut a language allows, e.g. the plus operator (“+“) is actually an instance method of the Fixnum class and can be called with dot notation like so:
4.+(3)
Ruby has a lot of syntactic sugar. It’s nice.

– The Class#class method has got to be one of the most useful debugging tools. Because Ruby is dynamically typed (i.e. variables can be changed from strings to numbers), you’ll often find that what you’re working with isn’t what you think it is. Run print thing.class to see what’s up.

– Class#methods is useful too; it returns a list of all methods available to that object.

– The Enumerator#map method. It cycles over a list of things just like #each, and it returns a list just like #each, but it’s very different and independently extremely useful. It’ll return a new array or hash that has been modified according to what you do to its elements inside the block passed. In other words:
[1,2,3].map{ |x| x + 1 } returns [2,3,4]

– Once you’ve understood the basic concepts surrounding Arrays and Hashes, read up on the lower-level data structures they represent! Arrays traditionally have an immutable size, and Hashes (outside of Ruby, they’re called hash tables, dictionaries, or maps) do not. This has to do with how things are stored in memory. Skim: Hash tables and arrays.

– If a company offers you free meals and does your laundry, that’s a bad thing. It implies that they want you to spend most of your free time there, and encourages the notion that developers are exceptional, super committed nerds. They’re not. They’re humans doing jobs. It’s a cool job but still.

– Programming is a people job. It’s not going to save you from human interaction, if that’s what you’re after. As my teachers liked to say, projects almost never fail for technical reasons.

– Don’t get too attached to JavaScript frameworks, but learn them as you need.

– Ruby and vanilla JavaScript will both be around for a while and you can get attached to them with some security.

– Don’t get hyphy about functional programming, either, but learn it. It is very useful but is not the second coming.

Leave a comment

Filed under code