Live data from Hacker News

Is JavaScript getting worse?

buzzdecafe.github.io

81–90 of 117 posts

Re: Is JavaScript getting worse?

#81
post #62

Earlier quoted context omitted.

Just because a tool is in a box doesn't mean its useful. Considering the relative cleanliness, refactorability of code coming from the functional world (see Haskell and the like), it is debatable whether OOP is a "good" style to develop at all! If I look at most of the libraries commonly used in production JS, pretty much none of them apply classic OOP principles.

Just because it's possible to write a program without a tool, doesn't mean it's more productive. Functional programming doesn't even directly oppose OOP, it opposes imperative. It is absolute basics of CS that there is data and logic and many problems are easy to reason about as logic modifying data (state). OOP is a tool that allows to encapsulate some data and logic that go together. Functional programming doesn't…

Without backing a horse exactly:

* FP as I understand it doesn't much oppose imperative or even most of OO. It opposes non-composability using discipline from pure/total languages.

* Even if you want to encapsulate data and logic together like you suggest, you only need to buy 10% of OO to get that (ADTs, existential types, modules, what-have-you do it fine if not far better). The remaining 90% may be a waste or actively harmful.

* FP, as I practice it, means using the simplest possible thing in a world where simple things compose nicely. This may end up being some kind of full-scale OO, I'm eager to try to find places where it does, but so far it hasn't ever.

As a meta note, "my kind of FP" is the Haskell type of purity and other such nonsense.

Re: Is JavaScript getting worse?

#82
post #76
post #33

Earlier quoted context omitted.

No, because it can only throw if there's a flaw in the code. Not randomly according to the argument passed to the function. Unless I'm missing something, it will either always throw, or never throw.

If a statement didn't throw before and might start throwing now, that would be a problem for existing code wouldn't it?

No because the let keyword didn't exist before. So existing code won't suddenly start to throw. The article's author is making a terrible, bogus argument.

Re: Is JavaScript getting worse?

#83
post #62

Earlier quoted context omitted.

Just because a tool is in a box doesn't mean its useful. Considering the relative cleanliness, refactorability of code coming from the functional world (see Haskell and the like), it is debatable whether OOP is a "good" style to develop at all! If I look at most of the libraries commonly used in production JS, pretty much none of them apply classic OOP principles.

Just because it's possible to write a program without a tool, doesn't mean it's more productive. Functional programming doesn't even directly oppose OOP, it opposes imperative. It is absolute basics of CS that there is data and logic and many problems are easy to reason about as logic modifying data (state). OOP is a tool that allows to encapsulate some data and logic that go together. Functional programming doesn't…

> Functional programming doesn't even directly oppose OOP, it opposes imperative.

Just to be pedantic, OOP is (a kind of) imperative programming: goals are achieved by performing a sequence of actions in the world. In functional programming, goals are achieved by defining values; the evaluation order is an implementation detail.

It could be argued that OOP is "more imperative" than, for example, procedural programming, since in an OOP approach, "the outside world" includes everything other than the current object (due to dynamic dispatch).

Re: Is JavaScript getting worse?

#84

> let considered harmful Did people actually use the side-effect var-hoisting intentionally within their code? Pretty much any JS style-guide worth its salt suggests manually moving var declarations to the top of scope since it's nice to know ahead-of-time which indicators of state you should be keeping an eye on. The idea of inspecting a variable that is later-on defined with let seems baffling to me. I can't think…

I tend to declare vars with their context. Especially in functions that are (unfortunately) longer than usual, having all vars at the top makes for a mess.

But I don't think the `let` syntax is going to be a problem for people who write plain JavaScript. It's more likely to it might become a problem for languages that compile to JavaScript. (For example, soak operators in CoffeeScript.)

Re: Is JavaScript getting worse?

#85
post #75

Earlier quoted context omitted.

How exactly can OO be "shoehorned" into a language which is already OO?

He meant proper OO as opposed to the shanty prototype one.

Since you've not defined it, I'll assume "proper OO" is referring to Alan Kay's formulation: http://c2.com/cgi/wiki?HeInventedTheTerm

In that case, his opinion on class vs. prototypes is that it misses the point: http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-...

As an aside, prototypes are strictly more powerful than classes, so they're no "shanty": http://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/De... (esp. section 6)

Re: Is JavaScript getting worse?

#86

This is one of the few posts about javascript that I've encountered that sees hoisting as a good thing. I like `let`.

Have you read the linked article about typeof? Normally, it's safe to do typeof possiblyUndeclaredVariable, but if later in the function you do let possiblyUndeclaredVariable it starts the scope defined as "uninitialized", which causes typeof to throw.

>it's safe to do typeof possiblyUndeclaredVariable

What would be the usecase of typeof'ing something undeclared in a block scope and then declaring the let further down?

Even more so with strict mode which does't really allow you to use undeclared variables anyway.

Re: Is JavaScript getting worse?

#87

Earlier quoted context omitted.

Well, even if you prefer classes, you've now got to reason about prototypes and classes, and possible mixtures of both.

ES6 classes are nothing more than syntactic sugar for the existing prototypical inheritance model.

Multiple equivalent syntaxes (syntaces?) still adds a cognitive load.

Re: Is JavaScript getting worse?

#88
post #62
post #34

Earlier quoted context omitted.

ugh, really sick of this meme. OO is a tool in the box, it's useful a lot of the time, sometimes it isn't. The reason ES6 introduces the `class` keyword is that people are doing that already .

Just because a tool is in a box doesn't mean its useful. Considering the relative cleanliness, refactorability of code coming from the functional world (see Haskell and the like), it is debatable whether OOP is a "good" style to develop at all! If I look at most of the libraries commonly used in production JS, pretty much none of them apply classic OOP principles.

> it is debatable whether OOP is a "good" style to develop at all!

You've drank way too much Kool-Aid here.

First of all: there are many different styles of OO, some more cumbersome than others, some so far removed from "classic OOP principles" that it takes effort to see how are they related. It's utterly useless to talk about "OOP style" as if it was a well defined, canonical set of rules - because it's not.

Second: there's nothing that makes OOP and FP be in opposition to each other. You should be aware - and if you're not, you should feel ashamed - that closures, one of basic FP tools, were supported in Smalltalk 20 years before Haskell.

Third: just as with OOP, things coming from FP are not uniformly "better" in any sense. Just as with every other paradigm, FP languages frequently have features needed only because they are FP. It makes very little sense to adopt those. Many really interesting features meant for solving real problems (and not for solving problems with a paradigm) are steadily coming to non-FP languages anyway.

> If I look at most of the libraries commonly used in production JS, pretty much none of them apply classic OOP principles.

Once again: either you have no idea what OOP is or you have no idea how JS libraries look like. For every http://ramdajs.com/docs/ you get hundreds libraries which implement their own kind of OO, starting from jQuery and Backbone.

Re: Is JavaScript getting worse?

#89
post #81

Earlier quoted context omitted.

Just because it's possible to write a program without a tool, doesn't mean it's more productive. Functional programming doesn't even directly oppose OOP, it opposes imperative. It is absolute basics of CS that there is data and logic and many problems are easy to reason about as logic modifying data (state). OOP is a tool that allows to encapsulate some data and logic that go together. Functional programming doesn't…

Without backing a horse exactly: * FP as I understand it doesn't much oppose imperative or even most of OO. It opposes non-composability using discipline from pure/total languages. * Even if you want to encapsulate data and logic together like you suggest, you only need to buy 10% of OO to get that (ADTs, existential types, modules, what-have-you do it fine if not far better). The remaining 90% may be a waste or acti…

>FP as I understand it doesn't much oppose imperative or even most of OO

I think this is definitely true, if you take 'oppose' as 'incompatible'. If we look the design concept and plot them, there will be axes, and I think this is what we'll see.

>* Even if you want to encapsulate data and logic together like you suggest, you only need to buy 10% of OO to get that

That's also true, but it's not an argument against the seed of usefulness of the 10%. We have kitchen sinks because people pick and choose features at will.

>* FP, as I practice it, means using the simplest possible thing in a world where simple things compose nicely.

Same here, and everyone should practice this when they look at any function, or object method, trying to make it as atomic as possible.

> This may end up being some kind of full-scale OO

I don't think it's any more useful shoehorning a program into "everything objects" more than "everything is functions".

My point was to say that the core goal of OOP is a great one, it simply codifies something that people have done in C when they put structs and procedures in the same header file. Let's not throw the baby out with the bath water.

Re: Is JavaScript getting worse?

#90
post #26

Earlier quoted context omitted.

Except, now you have one that you expect and the other you don't. This doesn't make the language anything but more inconsistent. I prefer consistency inside a language far more than familiarity between languages.

Remember, it's not the function that's throwing the exception, it's the runtime. In order to make it not throw an exception, we'd have to special case typeof to make the runtime behave differently just for it. /That/ is inconsistent.

This throws an error:

    typeof x; // throws an error
    let x = 1;
This doesn't:

    typeof x; // returns "undefined"
    var x = 1;
While using variables before declaring them is bad practice, I think it's fair to argue that this behaviour is inconsistent.
Post reply on HN