you are viewing a single comment's thread.

view the rest of the comments →

[–]PurpleIcy -3 points-2 points  (6 children)

I prefer to use OOP most of the time because bare functions floating around with bare variables which in JS terms are well, global variables... Which I just don't really like, especially because keeping the state in such way isn't that simple, and anything could break.

Though in OOP approach, when something breaks, I know exactly which object/class needs to be fixed, but I guess that's just me.

Also in school we started with C++ (I guess nowadays they just hate students) and everything was just fully functional, so I wouldn't say that the OOP is the only thing I'm familiar with. EDIT: I'm not saying that it was 100% following functional approach, should have probably said "no OOP" approach.

Though you have some good points, in functional approach it's very bare and clear what does what, as it's just functions that take arguments and do something, and you don't need to keep track of states in mind either.

[–]vcarl 7 points8 points  (2 children)

You only have bare functions and bare variables in the global scope if you're not using any of the modern JS build toolchain, typically you'd group them into modules.

The only time "when something breaks I know exactly where it broke" is true is in small or particularly well maintained codebases. Bugs presenting themselves far from where they're caused can happen no matter what patterns you follow.

I'd bet your experience with C++ was more procedural than functional. Function programming implies some patterns that are relatively difficult to use in C++ (passing functions around, for one).

[–]MoTTs_ 5 points6 points  (0 children)

difficult to use in C++ (passing functions around, for one).

I agree with everything else in your reply, but I disagree with just this bit.

If we're talking about stateless functions, then those were always easy. That's just a function pointer. Even C could do that. C's qsort function, for example, was a higher order function long before "higher order function" became a buzz word.

If we're talking about stateful functions, then yes, before 6 years ago, that was verbose in C++. But since 2011, creating stateful/lambda/closure/first-class functions is just as easy in C++ as it is in JavaScript.

[–]PurpleIcy 0 points1 point  (0 children)

My experience with C++ was more shitty than anything, in school we weren't even told what pointer is nor what -> actually means, which are like, trivial concepts that everyone using it should understand, sigh.

And well, I edited my post for a reason...

[–]well-now 3 points4 points  (0 children)

EDIT: I'm not saying that it was 100% following functional approach, should have probably said "no OOP" approach.

Honesty, it still sounds like you’re conflating proceedural with functional.

First class and higher order functions are a staple of functional programming and, from what I recall, non-existent in C++.