Live data from Hacker News

JavaScript at 20

brendaneich.github.io

231–240 of 327 posts

Re: JavaScript at 20

#231

I wonder whether `let` should be used everywhere now making `var` effectively obsolete? Mixing both declaration styles looks bad.

I use `const` instead of `var` almost everywhere and use `let` in the few cases that actually require reassignment.

Re: JavaScript at 20

#232

Earlier quoted context omitted.

There's a whole world of problems to fix before you even get to the problem of Javascript. Right now, the world only has 3.5 base browser engines. Those browser developers have no interest in adding a new standard language like Python, even though more people prefer that to Javascript. So, if you were to develop a new browser language, you need to build a new browser from scratch, and then move a billion people to it…

Man, python on the server and in the browser. What a world that would be.

In all my personal projects, I write Go on server and Go in the frontend. It is a very nice, although less populated world.

Re: JavaScript at 20

#233
post #69

JavaScript is like English. It incorporates the best parts of other languages. Starting from Java, you can now see the clear influence of Python in ES6/7 with generators and string templates. I think this is JS's greatest asset.

don't forget the destructor pattern.

Re: JavaScript at 20

#234
post #71
post #21

I find it very interesting that he says asm.js was "discovered" rather than "invented". Clues to a person's philosophy.

It's a minor quip. Are numbers real? Would you say we discovered them, or invented them? Do ideas exist even if you haven't thought of them yet? If so then they are discoveries.

Everything is a discovery. No one sat down and said now I am going to invent or think up something called numbers.

A thing happens because of what happened before it, and before that thing another thing happened etc.

Re: JavaScript at 20

#235
post #188

"Haters gonna hate." Anyone claiming that JS is the "worst thing to happen to the web" and/or that some other language would miraculously solve all of the problems present in JS should do the following, "Go create it." Don't whine about the barriers and how a new language would never be adopted because "JS is already everywhere." There are plenty of people already trying to solve this problem by actively doing someth…

I sometimes wish Javascript would take more hints from Python in getting some of the details right. For instance, it would be nice if == would work so that ["foo"] == ["foo"] and { foo: 1 } == { foo: 1}. But I suppose fixing that would be a too bold move. I like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them)…

> like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them) that seems to be half of most programming tasks is definitely a step backwards compared to Python.

I'm a Python fan but I can't disagree more on that point. Python has terrible lambdas, and poor idioms when working with collections (list iteration over chainable/fluid interfaces).

Underscore.js, which at this point stands for 'idiomatic JS for collections', and the ES5 methods on arrays (filter/map) which are largely supported now provide a better way to handle arrays & hashes than idiomatic Python. With ES6 fat-arrow functions it's even better.

It's one of Python's biggest weaknesses when compared to other dynamic languages IMO -- that the idiomatic way to deal with 'collections' is not a chainable/fluid pattern, but instead to do multiple list comprehensions, or use the ugly filter-plus-lambda patterns which compose badly.

Double evens in a list:

ES6:

   [1, 2, 3]
       .filter(x => x % 2 == 0)
       .map(x => x * 2)
ES5:

   [1, 2, 3]
       .filter(function(x) { return x % 2 == 0 })
       .map(function(x) { return x * 2 })
Python:

    map(lambda x: x * 2,
        filter(lambda x: x % 2 == 0, [1, 2, 3]))

    # or
    evens = [x for x in [1, 2, 3] if x % 2 == 0]
    [x*2 for x in evens]
The ES6 & ES5 JS examples are both clearly superior syntax IMO. More readable and the anonymous functions support multi-line so extend to more use-cases.

EDIT: Removed the word 'objective' because I'm talking syntax.

Re: JavaScript at 20

#236
post #188

Earlier quoted context omitted.

I sometimes wish Javascript would take more hints from Python in getting some of the details right. For instance, it would be nice if == would work so that ["foo"] == ["foo"] and { foo: 1 } == { foo: 1}. But I suppose fixing that would be a too bold move. I like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them)…

> like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them) that seems to be half of most programming tasks is definitely a step backwards compared to Python. I'm a Python fan but I can't disagree more on that point. Python has terrible lambdas, and poor idioms when working with collections (list iteration over cha…

> ES6 & ES5 JS are both objectively better IMO.

This sentence reveals a deep misunderstand of either what "objectively" means.

(FWIW, I prefer the ES5/ES6 syntax to Python here, as well; I just don't mistake that preference for something other than subjective.)

Re: JavaScript at 20

#237

Earlier quoted context omitted.

> like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them) that seems to be half of most programming tasks is definitely a step backwards compared to Python. I'm a Python fan but I can't disagree more on that point. Python has terrible lambdas, and poor idioms when working with collections (list iteration over cha…

> ES6 & ES5 JS are both objectively better IMO. This sentence reveals a deep misunderstand of either what "objectively" means. (FWIW, I prefer the ES5/ES6 syntax to Python here, as well; I just don't mistake that preference for something other than subjective.)

As humans, there is always subjectivity, even in things we declare objective. I'm willing to admit that :)

It's easy to pedantically point out I used 'opinion' in the same sentence as 'objective' but I'd hope you could apply 'the context of programming' to gather what I actually meant.

When we say 'objective' over matters of syntax I tend to think of 'If you put N programmers in a room they'd all agree this was better syntax'. That's how I feel about the above examples I posted.

That said I've edited my comment so I don't inflame other commenters to point out my glaring contradiction :)

Re: JavaScript at 20

#238
post #182
post #122

Edit2: When do you switch off your transpiler and serve native ES6? In 2020? Original: What do you do in 2017? What if you already code in ES6 and transpile it to JS5 at the moment. Do you simply switch from serving JS5 to JS6? Older browsers (todays current browser) don't support "class", "let" and other new syntax constructs. The just fail with JS errors. Can one browse the web with IE11 and iOS 8 Safari in 2017? (…

> When do you switch off your transpiler and serve native ES6? In 2020? Never, probably. Why would you? When most browsers support ES6 you would want to write in ES7, or 8, or TypeScript, or CoffeeScript, or — most likely — in some new exciting language that will transpile to JS.

> Never, probably. Why would you?

For me at least, running a build script in order to develop is worse than simply refreshing the page.

Re: JavaScript at 20

#239
post #188

Earlier quoted context omitted.

I sometimes wish Javascript would take more hints from Python in getting some of the details right. For instance, it would be nice if == would work so that ["foo"] == ["foo"] and { foo: 1 } == { foo: 1}. But I suppose fixing that would be a too bold move. I like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them)…

> like Javascript, in many ways it's a neat little language, but manipulating the small little ad-hoc data structures (arrays and hashes, and combinations of them) that seems to be half of most programming tasks is definitely a step backwards compared to Python. I'm a Python fan but I can't disagree more on that point. Python has terrible lambdas, and poor idioms when working with collections (list iteration over cha…

Doing good Python would help. You don't need the backslash on the first, making it a little cleaner:

    map(lambda x: x * 2,
        filter(lambda x: x % 2 == 0, [1, 2, 3]))
But the list comprehension version is just completely wrong:

    [x*2 for x in [1, 2, 3] if x % 2 == 0]
Which, in our subjective world, is cleaner than the ES5 version and almost as clean as the ES6 version.

Re: JavaScript at 20

#240

I wonder whether `let` should be used everywhere now making `var` effectively obsolete? Mixing both declaration styles looks bad.

As I understand it, yes, 'var' is now obsolete. 'let' does the same thing with less confusing semantics.

I disagree, function scope is not going away. So I still have to understand that. If I mix in lexical scope, I now have to think about 2 scopes, which makes my life worse.
Post reply on HN