| > Forcing people to use methods complicates things for no reason. No, it doesn't. All functions are in fact objects and most are methods in JavaScript, and there is nothing else. Methods (== properties assigned function object values) are the natural way to express things in JavaScript. Trying to pretend that this is not the case, and trying really hard to emulate (free) functions (which, to stress this point once more, do not exist in JavaScript) makes on the other hand's side everything more complicated than strictly needed. > Why not just have state and logic separated? That's a good idea. This is also completely orthogonal to the question on how JavaScript is supposed to be used. JavaScript is a hybrid langue. Part Small Talk, part Lisp. It's common in JavaScript since inception to separate data (in the form of objects that are serializable to and from JSON) from functionality (in the form of function objects). JavaScript was never used like Java / C++ / C#, where you glue together data and functionality into classes, and still isn't used like that (nevertheless they've got some syntax sugar called "class" at some point). > Why force everything into some horrible combination? Nobody does that. At least not in JavaScript. Still that does permit to use methods. Functions themself are objects. Using objects is the natural way for everything in JavaScript as there is nothing else than objects. Everything in JavaScript is an object. And any functionality the language provides is through methods. Working against the basic principles of a language is a terrible idea! (In every language, btw). It complicates everything for no reason and has horrible code abominations as a consequence. > If I want to use my method in another place I have to bring all the state along with it. No, you don't. You need only to bring the data that you want to operate on. The nice thing is: You get the functionality right at the same place as the data. You don't need to carry around anything besides the data that you work on. The alternative is needing to bring the modules that carry the functionality that you want to apply to the data you need also to have around… As an example: `items.map(encode)` is nicer to write and read than `List.map items encode`. You don't need to carry around the `List` module when the method can already be found on the prototype of the data object. Also it's more clear what's the subject and what's the object of the operation. > I can't move my logic anywhere because it's tied to the contextual state. That's just not true in JavaScript. Nothing is easier then passing functions objects around, or change the values of properties that reference such function objects. JavaScript is one of the most flexible languages out there in this regard! You can even rewrite built-in types while you process them. (Not that I'm advocating for doing so, but it's possible). > The style of the program itself is a weakness […] You did not present any facts that would prove that claim. > […] that's why people imitate another style. No, that's not the reason. You don't need to imitate Haskell when you want to write functional programs in a Lisp derived language… ;-) People are obviously holding some cargo cult ceremonies when trying to write Haskell in JavaScript. Your other opinions are based on wrong assumptions. I'm not going into that in detail, but some small remarks: > For example we know the shortest distance between two points is a line. In Manhattan¹? ;-) > O(N) is definitively more "good" then O(N^2). Maybe it's more "good"… But it's for sure not always faster, or even more efficient, in reality. Depending on the question and your resources (e.g. hardware) a brute force solution may be favorable against a solution with a much lower complexity on paper. Welcome to the physical world. Where practice differs from theory. > But the shortest distance between two points? Nobody argues about that (I hope some pedantic person doesn't bring up non-euclidean geometry because come on). You don't need to look into non-euclidean geometry. Actually, even there the shortest distance between two points is a "straight line". Only that the straight line may have some curvature (because of the curved space). But you didn't even consider that "distance" is actually something² about that one can actually argue… > You can't. The definition of bias is that the person who is biased is unaware of it. No, that's not the definition³. > Nobody truly knows who is blind and who is not. Nobody truly knows anything. What's the point? What was actually the point of your comment, btw? --- ¹ https://en.wikipedia.org/wiki/Taxicab_geometry
² https://en.wikipedia.org/wiki/Distance
³ https://en.wikipedia.org/wiki/Bias |
It is, I just worded it differently. See the "cognitive biases" part on your citation. They use "reality" in place of what I mean by "unaware". If you think something incorrect is reality, then you are "unaware" of how incorrect your thinking is, because you think it's reality. These are just pedantic factoids we're throwing at each other.
>What was actually the point of your comment, btw?
The point is that FOR PROGRAMMING, nobody truly knows which camp is the cargo cult. Everyone is blind. Stick with the program.
>Welcome to the physical world. Where practice differs from theory.
This is called pedantism. Like did you really think you're telling me something I'm not aware about? Everyone knows this. But the pedantic details of the optimizations the compiler and the CPU goes through to execute code is besides the point, obviously I'm not referring to this stuff when I'm trying to convey a point.
>In Manhattan¹? ;-)
Your again just being pedantic. I'm perfectly aware of non-euclidean geometry, but you had to go there. I had a point, stick to the point, pedantism is a side track designed to muddy the conversation. Why are you muddying the conversation?
Is it perhaps that you're completely and utterly wrong and you're trying to distract me from that fact?
>Trying to pretend that this is not the case, and trying really hard to emulate (free) functions (which, to stress this point once more, do not exist in JavaScript) makes on the other hand's side everything more complicated than strictly needed.
Bro, my little paragraph arguing against you was just a random factoid. I don't care for your argument and I don't even care for mine. The whole main point is to say that we can endlessly spew this garbage at each other the needle doesn't move forward at all. Nobody can win, because we have no way of establishing an actual winner. Thus with no way of knowing who's right there's no POINT in it.
All I am saying and this is the heart of my argument, is that YOUR topic, your team of "don't be a cargo cult" is no different from all the other teams.
I thought I made that obvious that my factoid was sarcastic, but you fell for that quick and instantly retaliated with your own factoid. Man Not gonna go down that rabbit hole.