Hacker News new | ask | show | jobs
by ZackOfAllTrades 5439 days ago
A rambling side note:

If you come from a javascript background, you will have a leg up on most people in terms of learning clojure. You get used to inlining functions pretty regularly.

What I am encountering as I chew through Programming Clojure though is that I had no idea what I could have been doing in javascript all this time. I would look at C and laugh about how they have to define an extra function for event handling. It just seemed so verbose.

Looking back at the javascript I wrote/write, I really wish I had understood what I could have been doing with functions, mappings, and apply. I didn't/don't write javascript: it's just C with some in-lined functions.

Moral of the story: Inhale the Zen of Crockford(http://javascript.crockford.com/) and exhale the suck of W3 schools.

2 comments

Please don't call them inlined functions. That has a very precise and very different meaning in common usage, so you're likely to confuse a lot of people.
And to clarify, grandparent probably wants the terms 'first class function', 'anonymous function' or 'lambda' (depending on the specific usage.)
You are totally right. For somebody like me who did learn from W3 initially though, those first class functions are conceptually and in practice "inline" functions. If you are talking to somebody who knows the difference between inline functions and first order functions, then you probably don't need to tell them to learn more about how to use higher order functions. But if first class functions are conceptually the same as "inline" functions to a person, then they would probably benefit from the advice to learn more about higher order functions. How would you suggest explaining how to handle an event without using the word "inline"? Explain how functions are first class and go from there?
"If you come from a javascript background, you will have a leg up on most people in terms of learning clojure. You get used to inlining functions pretty regularly."

You'd be better off listing the languages that don't have some sort of 'inline functions' than claims about javascript superiority here; Heres a handful of common imperative/OO languages that have an analogous construction: Python, Ruby, C#, Visual Freaking Basic Dot Net, Smalltalk, Objective C and other C languages with Apple's blocks extension, probably PHP and Lua…

Of those Languages you listed, many don't have implemented function closures correctly.

Python doesn't allow you to mutate variables from enclosing scopes (by default, at least).

Ruby's blocks aren't first-class, they have to be converted to a Proc object first (and argument passing works differently than for methods).

Smalltalk blocks don't have to be able to call themselves recursively by the ANSI standard (most implementations allow that, but eg. Squeak/Pharo does not by default).

C on OSX doesn't have GC, so you have to manually specify which variables you want to capture (and how).

JavaScript was originally supposed to be Scheme, and thus has implemented lexical closures better than most other languages. ('this' however... don't want to talk about that train wreck)