News for hackers. Stuff that matters.
Re:Functional programming is not popular because it is weird... by austincheney on Tuesday September 14, 2021 @03:56AM (#28521646)
> JavaScript became popular because of the browser

That is a very popular perspective. In the past I have seen this sentiment used heavily by people who hate JavaScript as a means to rationalize how JavaScript could have become popular at all.

Unfortunately this sentiment is disqualified by data.

The browser became a popular platform in the late 90s and early 2000s as business and social interest on the web grew. JavaScript has been around cross-platform in a mostly consistent way since 1998 due to the publication of early current standards.

This did not make JavaScript popular though. JavaScript would not become popular for more than a decade later.

In 2008 a couple of things happened. Chrome launched offering the first JavaScript JIT. Before this JavaScript was hundreds of times slower than it is now. Also, jQuery started gaining popularity at this time which allowed employers to hire any dumbass off the street to write in it. Douglas Crockford also heavily evangelized the language for its expensive capabilities: functions as first class citizens, optional OOP (easily ignored/bypassed), native lexical scope.

A little after that around 2009/2010 Node.js launched and GitHub became common knowledge. It’s about this time that JavaScript exploded in popularity. The web was already popular for more than a decade before this.

> Functional programming is less popular because no major successful platform has adopted a functional language as the preferred language.

I would argue functional programming is incredibly popular but less common in the workplace because OOP conventions are what’s taught at school.

Re:Functional programming is not popular because it is weird... by juki on Tuesday September 14, 2021 @04:44AM (#28521961)
> Unfortunately this sentiment is disqualified by data.

Your comment seems to support, rather than disprove, the claim.

JS was around for years without much success before the browser became a popular platform for applications. People used to only write applications for the server or for platforms like Java and Flash that were just embedded as plugins in the browser. They only started using JS after improvements to browsers made it a better platform than the alternatives.

Re:Functional programming is not popular because it is weird... by zone411 on Tuesday September 14, 2021 @04:21AM (#28521792)
This shows JavaScript as being popular since at least 2004 (beginning of the dataset) https://trends.google.com/trends/explore?date=all&q=javascri... and this is closer to my recollection.
Re:Functional programming is not popular because it is weird... by kryptiskt on Tuesday September 14, 2021 @06:09AM (#28522508)
Javascript became mainstream with the Web 2.0/AJAX hype of 2004. It was still Google's "fault", but it was the slick Google Maps site (and also GMail) and not Chrome that was the inciting factor. With an assist from Microsoft's Web Outlook and XMLHttpRequest.

Really, the reason Chrome invested heavily in optimizing Javascript was because it had started to be widely used in more than trivial scripts.

Re:Functional programming is not popular because it is weird... by antris on Tuesday September 14, 2021 @04:09AM (#28521715)
> I would argue functional programming is incredibly popular but less common in the workplace

It would help if someone defined what constitutes "using functional programming".

I mean, this is functional programming:

   function add(a, b) { return a + b }
From my experience, every developer does functional programming to a certain extent, it's just the extent that varies.
Re:Functional programming is not popular because it is weird... by hasmanean on Tuesday September 14, 2021 @06:31AM (#28522657)
Functions were invented by functional languages…but they originally were a lot more flexible than the way most procedural languages use them now.

Let’s try rewriting your example this way

add = function(a,b) { + a b }

Why is this better? Because + is a function, and add is an object, so you can then refactor the code to say this

add = +

Try doing that in C.

As I see it the code for some programs has a high degree of symmetry (ie repeated patterns), and the best language is a notation the let’s you capture that the best.

If you find yourself cutting, pasting and modifying things slightly each time, then your language is holding you back.

Test-script code is the best example of this…particularly hardware tests. You have the same code copied and pasted dozens of hundreds of times.

Thoreau once said that government is best that governs least. That language is best that makes you type the least.

Re:Functional programming is not popular because it is weird... by kaba0 on Wednesday September 15, 2021 @02:18AM (#28535831)
> add = + > Try doing that in C.

Function pointers. They are abused to no avail in C programs. It has the original callback hell, not JS. (And that is mainly because C has no proper way for abstractions)

Re:Functional programming is not popular because it is weird... by iainmerrick on Tuesday September 14, 2021 @04:40AM (#28521935)
Yes, that's functional programming! I think you're right to say that many programmers use FP much of the time. The modern trend is definitely to borrow many FP techniques and use them inside an imperative shell.

Your example is strict FP, where a and b are fully evaluated before add() executes. There's also non-strict FP, where everything uses lazy evaluation by default. That has some big advantages but also a few pitfalls, and generally makes things significantly weirder when compared to imperative languages.

Pure FP is where you only have functions and expressions, no variables at all. I think that's where most mainstream programmers draw the line -- sometimes you just want to store something somewhere, without being forced to jump through what seem like weird hoops.

The original elevator pitch for Haskell was that it's a "non-strict, purely functional" language (aimed a unifying a bunch of different research languages, plus the proprietary language Miranda).