News for hackers. Stuff that matters.
Re:Ask HN: Reasons behind renaissance of functional programm... by pixelmonkey on Sunday April 27, 2014 @11:30PM (#7658101)
IMO, it's something of a backlash against the rise of class-focused, object oriented languages (e.g. Java, C++, Ruby) leading to some complexity in the last decade.

Pendulum now swinging back the other way. Functional, data structure oriented programming has many benefits above old-school procedural programming e.g. C, Fortran. But it also doesn't have the baggage of mainstream OO languages. Thus, this feels like an appealing -- and new -- ecosystems.

This -- along with a rediscovery of some functional concepts that seem have more importance in a distributed setting, like immutable data, purity, higher-order functions -- have led to some renewed interest.

Re:Ask HN: Reasons behind renaissance of functional programm... by williamcotton on Monday April 28, 2014 @01:05AM (#7658272)
Part of the issue with Object Oriented design is how they maintain state and deal with their dependencies.

A pure function has a very portable interface that makes it suitable for the distributed and social nature of the way we create software together.

These kinds of problems were not envisioned by the creators of the original Object Oriented systems like Smalltalk. Objects were designed for personal computers and building and using software designed for personal computers.

While shared workspace environments were explored in systems like Self, they were always designed around the objects being these visual instances running in a GUI.

Objects detached from a system like Self or Smalltalk lose a lot of their powers of abstraction. They are not and have never been portable, even if they were designed to be reusable.

Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @01:37AM (#7658361)
> A pure function has a very portable interface that makes it suitable for the distributed and social nature of the way we create software together.

Citation needed. I personally don't talk to other programmers in terms of functions, but I use plenty of metaphors and analogies that come with my evolutionary capabilities to use natural language (math, on the other hand, was something I had to learn).

Re:Ask HN: Reasons behind renaissance of functional programm... by williamcotton on Monday April 28, 2014 @02:02AM (#7658429)
I'm citing my own experience as a professional.

Programmers talk to other programmers in terms of functions all the time. Every API you use exposes functionality. If that API assumes some sort of state, that can cause issues for the consumer of the API. It also forces whatever entity is maintaining state be tightly coupled to the consumer and leads to centralized systems.

If the API does NOT have state and instead uses a token based system for authentication and access permissions it is operating in a functional manner. State is maintained outside of the function.

The less coupled that two modules are the more portable that they are. You can bundle up something like the "express" npm package and ship that off to whomever. You can easily build modules on top of an express application by passing the entire app to another module. This pattern has been used to build an entire ecosystem of loosely coupled middleware.

These are not Object Oriented designs. They aren't entities that communicate by sending messages to one another while floating around in some global workspace. They are interfaces that pass state around as arguments to function calls.

Global state is very nicely demonstrated in how modules can be shared between Node and Browser Javascript. What is global? All of the I/O. Files, XHR, mouse clicks, sockets... all of these are the inputs and outputs and all are handled by "window" or "process" or other global state.

Modules can be easily be reused between the server and client if they do not interface at all with any sort of global state.

Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @02:24AM (#7658490)
> Programmers talk to other programmers in terms of functions all the time.

I seriously doubt it. In order to talk in terms of only functions, you would need to give up identity...because what is identity but not a key for encapsulated state? Without identity, you really are talking with just values, but you have problems describing things with handles. There is no single Bob, just a new Bob who is reconstituted each time you talk about him. Naming anything is weird, and the pure lambda calculus of course avoids it. Most APIs are not purely functional, but somewhat object-oriented (oriented around identity) if only in a few key aspects that are needed to do anything at all.

Re:Ask HN: Reasons behind renaissance of functional programm... by weavejester on Monday April 28, 2014 @03:49AM (#7658725)
You can have identity without encapsulated state, you just need something that's sufficiently unique, such as a UUID or SHA hash.
Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @04:07AM (#7658771)
It is the same thing actually, either will give you the other.
Re:Ask HN: Reasons behind renaissance of functional programm... by weavejester on Monday April 28, 2014 @04:14AM (#7658788)
How does a raw UUID equate to encapsulated state? Adding a UUID doesn't inherently hide or restrict access to data.
Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @05:38AM (#7658991)
Think about it like this: as long as you have an identity, someone can remember something about you...and therefore state!

If you didn't have an identity, then that would be impossible, it is like a superpower where no one could "remember" who you are, and therefore nothing about you.

A UUID is synonymous to state, and in fact, procuring and propagating these IDs would be the main step to implementing state in a pure language.

Re:Ask HN: Reasons behind renaissance of functional programm... by williamcotton on Monday April 28, 2014 @09:10AM (#7659616)
A signed access token is how identity is provided in a stateless environment.

Take Facebook OAuth for example. A user logs in, is provided with a signed access token by FB, and then uses that token to prove to an application that the owner of the secret key has granted them permission. The owner in this case was Facebook itself.

This can be verified by the server by comparing the:

var expectedSignature = crypto.createHmac('sha256', FACEBOOK_OAUTH_CLIENT_SECRET).update(encodedData[1]).digest('base64').replace(/\+/g,'-').replace(/\//g,'_').replace('=','');

with the signed request signature:

var signature = signedRequest.split('.',2)[0];

and making sure that they're the same.

This way the server never needs to maintain sessions, cookies, or a whole bunch of other crappy, centralized, coupled, insecure methods for building networked software. The server only needs the secret keys of whatever access tokens users might be providing. The access token contains the userId or any other relevant information. If the server needs more information about the user, it can provide the access token to another API that returns more information about the user, again, based solely on the access token, just by passing state INTO whatever system/function/service needs it.

If this server is sitting in front of a database all that the server cares about is what the access permissions are of whatever incoming request it is dealing with. It still doesn't need to maintain state. The database is maintaining state, but the server is just verifying that the request can make the changes to the state of the database.

All with the wonders of functions, modules, and APIs that try to operate without managing their own internal state, which again, is the main feature of functional programming languages.

Re:Ask HN: Reasons behind renaissance of functional programm... by weavejester on Monday April 28, 2014 @08:54AM (#7659541)
You said "encapsulated state". I was wondering why you thought it was encapsulated, which is usually a term for information hiding.

I'm also not certain why you think this conflicts with the idea of talking "in terms of functions".

Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Sunday April 27, 2014 @11:40PM (#7658116)
This has gone on in academia for awhile, you are now considered mainstream if you embrace FP as the way, and you are considered a rebel if you instead believe that OOP is still the way.

I predict that there will eventually be a FP backlash that reverses the situation again (hey, look how easy objects are to use vs. this crazy FP stuff!?).

Re:Ask HN: Reasons behind renaissance of functional programm... by pcarbonn on Monday April 28, 2014 @02:08AM (#7658443)
Logic programming, the third programming paradigm, will come to the rescue...
Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @02:25AM (#7658495)
Sure, the database junkies will never give that up.
Re:Ask HN: Reasons behind renaissance of functional programm... by FranOntanaya on Monday April 28, 2014 @02:54AM (#7658580)
I guess 2020 will be the year of procedural programming then.
Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @05:44AM (#7659000)
Why? Both OOP and FP are supersets of procedural programming, so in any case, it is the year of procedural programming already.
Re:Ask HN: Reasons behind renaissance of functional programm... by coolsunglasses on Monday April 28, 2014 @01:23AM (#7658318)
Question - why didn't you seek help in learning FP?
Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @01:35AM (#7658359)
I worked with Martin Odersky team for awhile, and I saw the way...was to use some FP and a lot of the cool OO stuff that Scala provided (traits!). Scala is one of the most advanced OO languages out there.
Re:Ask HN: Reasons behind renaissance of functional programm... by coolsunglasses on Monday April 28, 2014 @03:03AM (#7658601)
I'm very familiar with the PLT field, including OO languages like Scala and the history of its development. I was asking precisely because of your work on scalac. Much of your code had to get thrown out/refactored/cleaned up. The impression was that you didn't understand the FP part. Your recent comments on HN reinforce that.

But that's besides the point. I'd like to find out what gaps can be filled so you no longer find FP difficult to understand or use. What material have you tried so far?

Re:Ask HN: Reasons behind renaissance of functional programm... by seanmcdirmid on Monday April 28, 2014 @03:49AM (#7658720)
That is complete BS, I didn't drink the Kool-Aid and was able to get the job done in a way that didn't use mega pattern matching functions, which are particularly loved by some (especially scalac) but not all. Martin also preferred lazy evaluation over incremental and reactive computation, and that was that. If you look at my recent IDE demoes (on YouTube or just see my papers), you'll see where Scala could have gone vs. where it is now.

The Scala community eventually drifted away from OO, but it could have gone very differently.

Re:Ask HN: Reasons behind renaissance of functional programm... by CmonDev on Monday April 28, 2014 @07:29AM (#7659245)
What about the baggage of the old-school functional languages?