Live data from Hacker News

Javascript Arrays and Functional Programming

zabanaa.github.io

31–40 of 92 posts

Re: Javascript Arrays and Functional Programming

#31
I don't know if I'm delirious but I remember a few years ago when articles like this were very common on HN. Then all of a sudden it felt like everyone had "learnt" it and all that got upvoted was very complicated articles explaining some esoteric JS thing.

Now it seems we're back again with. Another example is the article explaining "this" which is on the front page again. It almost feels cyclic, like it's time for the new generation of programmers to learn the quirks.

It's probably an incorrect observation but it feels like the front page has developed with me. Like we all started on square 1, evolved together and now it's time to graduate and leave room for the new generation.

Re: Javascript Arrays and Functional Programming

#32

TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…

Man, I had just worked up the nerve to start a personal dev blog but you've just scared me straight off.

Who cares what other people think? Do what you want.

Re: Javascript Arrays and Functional Programming

#33

Earlier quoted context omitted.

Because (a) we don't have an unambiguous definition of what functional programming is and (b) we don't have a better term for what this style of programming is. I guess it could be called combinator-oriented programming or similar.

Sounds more like "coding with map, reduce and filter" to me. It beats complex for-loops where mapping, reducing and filtering are all mixed in together but I wouldn't call it functional programming.

As mentioned in one of the comments, this is nowhere near the definition of functional programming.

> It beats complex for-loops

Nvm. I still prefer for loops in most cases, in some way it's easier to understand for me if I read it some months later. For example the reduce function I would write something like this:

  getPlayersByCountry= ( footballPlayers= [], players= {} ) ->
    for player in footballPlayers
      if players.hasOwnProperty player.country
        players[ player.country ].push player
    return players

  playersByCountry= getPlayersByCountry footballPlayers, {France: [], England: [], Spain: []}
I guess it's mere a matter of taste.

Re: Javascript Arrays and Functional Programming

#34
This hardly covers any functional patterns that javascript is capable of. You can compose functions, avoid stack overflows in tail call recursion, use immutable values, etc. I've seen articles on pattern matching with Typescript or trampolining code but this is simple a descriptive look at three basic javascript functions. If you're interested in more of a functional approach in JS take a look at Immutable.js and/or https://pattern-matching-with-typescript.alabor.me/.

Re: Javascript Arrays and Functional Programming

#35

TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…

From my comment below: "Thank you for this! I've been learning JS for React and .reduce, .every and .some are new to me! Super helpful" I feel like learning is always easier in smaller bitesizes and the person wrote something very clear and digestible. Sounds like it wasn't aimed at more advanced programmers like yourself

The blog post has tremendous value to the right audience, no doubt about that. But it's worse than worthless for its actual target audience because the article makes those people feel like they're supposed to get it, and they probably feel shitty when they don't (I did). Even though they shouldn't. No one expects you to read that blog post and get it if you've never used Map or Reduce before. It's misleading and disheartening to the target audience. It's a pretty easy fix. Just change who you're talking to.

Re: Javascript Arrays and Functional Programming

#37

I accept that this is a widely used phrase now but I never understood why just using map/filter/reduce and avoiding state is enough for code to be called "functional programming". Most functional languages feature pattern matching, algebraic data types, purity, currying, strong typing, type inference, recursion instead of loops and types that cannot be null. It's a completely different style of coding. Adding map/fil…

> Most functional languages feature pattern matching, algebraic data types, purity, currying, strong typing, type inference, recursion instead of loops and types that cannot be null.

It's only fairly recently that the set of functional programming languages for which that is even approximately true became the center of FP attention. For quite a long time, the flagship family of “functional programming” languages was the Lisp family, members of which for the most part feature none of those except possibly idiomatic recursion over iteration (though many Lisps include constructs that work like iterative loops, even though they may be implemented under the covers with recursion.)

Re: Javascript Arrays and Functional Programming

#38

TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…

Someone on the internet wrote something but you don't like it. The appropriate reaction is to be quiet and go read something else.

Slagging the author for giving something to the world for free doesn't help anyone and it's almost certainly going to discourage the sharing which everyone on the internet has benefited from.

Re: Javascript Arrays and Functional Programming

#39

TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…

Man, I had just worked up the nerve to start a personal dev blog but you've just scared me straight off.

I highly encourage you to start a blog for yourself, not for any assumed audience. You'll gain important skills.

* Better understanding the topic by trying to re-teach it

* Improve writing skills. Programming is basically writing but with even crazier grammar freaks.

* Employers interested in possibly hiring you will have a better idea of what you know & enjoy

* Provide yourself (and possibly your company) with documentation for the future.

Lastly if you need encouragement by someone more established than me, here's Troy Hunt at NDC Oslo 2017 - https://www.youtube.com/watch?v=-MUhcgXBj_A

Re: Javascript Arrays and Functional Programming

#40
post #3

JavaScript has an advantage on Python in this style, because Python lambdas are hideously ugly and JS anonymous functions are less hideously ugly. In Python it tends to be cleaner (and sometimes faster) to write list comprehensions instead of map() and filter(), especially since Python also has lazy generator comprehensions.

Python actually discourages using map anf filter. Which is kind of weird to me but whatever.
Post reply on HN