News for hackers. Stuff that matters.
Re:‘This’ in JavaScript by mattmanser on Thursday August 03, 2017 @05:21AM (#14918108)
Crazy we're still talking about it.

I thoroughly understand `this` now after over a decade working in javascript, as well as thoroughly understanding `this` in Typescript which I use more now.

And I still make a mistake at least once a week. I know what I've done as soon as the code fails, but it's still so ridiculously easy to get into a context you didn't think you were.

Of all the mistakes made in javascript, `this` stands head and shoulders above everything else, with its arm round the prototypal class structure.

Re:‘This’ in JavaScript by christophilus on Thursday August 03, 2017 @05:51AM (#14918228)
I almost never use "this" in my JS code. I find that when you use a functional style of development, you largely avoid the "this" pitfall.
Re:‘This’ in JavaScript by mattmanser on Thursday August 03, 2017 @08:27AM (#14918916)
That debate is long over.

If there's anything that a decade of functional style being "the next big thing" has taught us, functional style is not "the next big thing" and most programmers don't work well in it.

Re:‘This’ in JavaScript by disantlor on Thursday August 03, 2017 @09:57AM (#14919584)
i strongly disagree with this. half of my posting history on here is evangelizing FRP in javascript (in my case via bacon.js).

it has dramatically reduced the amount of time i spend on these and many other sorts of problems. honestly it makes programming way more fun. maybe haskell is a bit extreme for most situations but the concepts are not.

Re:‘This’ in JavaScript by mattmanser on Thursday August 03, 2017 @11:31AM (#14920432)
While you may love functional, and I'm not saying you shouldn't, I think you're strongly disagreeing with the statement you think I'm saying, "functional is bad", rather than the actual statement I'm making which is "functional programming's had many chances to become a mainstream language and it never takes off (outside a few specialities)".

What evidence do you have that functional is taking off? Since this board was around, every couple of years there's been a flurry of 3 months when a chunk of the community bangs on about functional programming.

First it was Lisp, then Erlang, then Haskell, then F#, then Scheme. I might have got the order wrong.

And it never, ever, ever takes off because while 10% of programmers find functional truly brilliant, the other 90% can't work with it.

For context, in that time Ruby (via Rails), Python (via Django and use in Science), javascript server-side (Node.js), Go, Swift, Rust and now possibly Kotlin have all taken off. Plus various other techs like NoSQL.

Re:‘This’ in JavaScript by christophilus on Saturday August 05, 2017 @02:40AM (#14934503)
Hm. I guess it depends on your definition of mainstream.

In the front end space, functional programming is taking off, I think. Could be wrong, but React + Redux + immutablejs is a popular and very functional approach to UI.

Elixir appears to be on the same trajectory as Rails in it's early days. Anectodally, I know a lot of Rails devs and shops that are now primarily Elixir.

Most mainstream languages have adopted functional styles and best practices. Higher order functions, a general acknowledgement of the benefits of immutability, etc.

Fp may not be mainstream, whatever that means, but it's more popular than I can ever remember it being.

Re:‘This’ in JavaScript by zhte415 on Thursday August 03, 2017 @11:12AM (#14920258)
This could depend on industry. In finance, functional is not the next big thing, but required. Needs context.
Re:‘This’ in JavaScript by spinningarrow on Thursday August 03, 2017 @07:46AM (#14918692)
I may have misunderstood but do you mean that the prototypal class structure is also a mistake? If yes, in which way?
Re:‘This’ in JavaScript by mattmanser on Thursday August 03, 2017 @08:21AM (#14918882)
They ended up having to add classes (albeit as syntactic sugar).

Argue its advantages all you want, but I'd say that's representative of what a failure it's been. One of the last languages supporting prototype-based inheritance has basically given up on it.

Personally, I find it an awkward way to try and encapsulate code, generally, it has terrible performance to boot.

Re:‘This’ in JavaScript by MoTTs_ on Thursday August 03, 2017 @11:45AM (#14920548)
> One of the last languages supporting prototype-based inheritance...

Actually, all this time, both Python and Ruby use what we would call prototype-based inheritance.

https://www.reddit.com/r/node/comments/6oqiyn/is_es6_complet...

https://www.reddit.com/r/learnjavascript/comments/6c6use/how...

Re:‘This’ in JavaScript by Raphmedia on Thursday August 03, 2017 @09:37AM (#14919411)
Was there ever any issues with prototype-based inheritance? I've always assumed that they added classes simply because of stubborn classical-based programmers who couldn't bother to learn JavaScript correctly.
Re:‘This’ in JavaScript by spinningarrow on Thursday August 03, 2017 @10:50AM (#14920046)
That was my impression as well, especially since the class-ish syntactic sugar doesn’t improve performance either.