filmov
tv
Can you do Functional Programming in any language?

Показать описание
Can you do functional programming in any language? Is it possible to do #functionalprogramming in C, in Java, in assembly, in Ruby, or do you need a functional language? What is a #functionallanguage anyway?
Transcript
Can you do functional programming in any language? Is it possible to do functional programming in C, in Java, in assembly, in Ruby, or do you need a functional language? What is a functional language anyway?
My name is Eric Normand, and these are my thoughts on functional programming. The short answer is yes, you can do functional programming in any language.
Functional programming is a paradigm. It's all in your mind. It's how you break down problems. It's how you see things. It's how you think about the problem, and how you structure solutions.
If you're thinking about the thing in terms of actions, calculations, and data, then yes. You can do functional programming in any language. Just like you can do #objectorientedprogramming in any language.
Object-oriented programming is also a mindset. It's a paradigm. You could figure out how to make an object system with messages passing around in C.
In fact, I've done that before. What I found though, and what I think a lot of people find when they do something like that, when they create a little object-oriented system in a language like C, is that so much relies on the discipline of the programmer because you could always slip out of that object-oriented programming. You can sneak behind the nice veneer you put on, and just mess with pointers, and do all the C stuff that C allows you to do.
If you're doing functional programming in C, you would have all of those same possibilities. They would tempt you. People who are really good at functional programming, who are used to it, who are well versed in how to solve problems with it, they tend to...and they like functional programming, too. They're choosing to do functional programming.
They're going to have a better time because they're choosing to use functional programming. It is a choice that they are imposing on the language on the program that they're writing. Even if the language doesn't provide something, they will write it themselves.
They have this discipline. That is what allows them to do functional programming, even when the language is not really helping them. That's my short answer. A short answer is yes, you can do functional programming in any language.
The long answer is you probably don't want to. One reason is that relying on discipline might work if you're writing a small program or you're writing a program by yourself or on a very small team, you can handle the discipline of it.
You can handle the copy on right discipline or the append only semantics or the lack of any help figuring out what is an action and what is the computation. It's all discipline. You have to know this thing is an action. I shouldn't call it from a computation or a calculation.
[background sounds only]
Eric: The other thing, the other part of the question is, if you're going to...yes, you can do functional programming in, let's say JavaScript. If you don't know functional programming, you're not going to learn it in JavaScript. It's like trying to learn to speak a natural language, like trying to learn.
Let's say you don't speak Spanish. You're going to try to learn Spanish just from people who also don't speak Spanish. Maybe just from a book. You have no help. Sure you can do it with tons of willpower. Or you could get on a plane. You can fly it to a Hispanic country, a country that speaks only Spanish. You can start picking up this and that.
You have people to ask for help. All the signs are in Spanish. It's just immersion in Spanish. You're going to pick it up. You're going to feel like this need to learn it. Even if you still learn it from a book, there's a lot of stuff pushing you in that direction.
That's been my experience with functional programming in other languages that you can do it. If you don't already know functional programming, you're going to feel it's not right. You're not going to learn it. You're never going to get over that hump because you can always just revert back to whatever the language is, whatever is natural for that language.
That's what I find, is people who say, "Oh, I know functional programming. Sorry, I'm learning functional programming. I've heard I can do it in JavaScript." You're going to learn this much functional programming and not really get the meat of it. There's a lot of people who...it's all cool. They don't get very deep into functional programming.