|
Re: Time is the New Memory
|
Posted: Sep 23, 2009 12:14 PM
|
|
> > I'm also not sure functional programming is as much > > awkward as it is unfamiliar to the mainstream. I.e., it > is > > awkward to people because they are unfamiliar with it. > I > > find it awkward sometimes, especially when I would need > to > > use recursion to be full-on functional. I do use > recursion > > sometimes, but since I'm working in Scala, I can also > just > > use a while loop and a var, and I do that from time to > > time. I make sure it is all local, so each thread would > > get its own copy, then it's perfectly fine to do it the > > way its done in Imperative-stan. > > > > If you forget the word "functional" and just say final > > variables, immutable objects, and methods that just > return > > a value based on just the passed data without having > any > > side effects, that really doesn't sound that unfamiliar > or > > awkward. String is an immutable object. Is > > java.lang.String awkward for Java programmers to use? > How > > about String.valueOf(5)? That's a pure function. I just > > operates on its input, returns a value, has no side > > effects. I doubt that's awkward for Java programmers, > and > > neither are final variables. What is awkward, probably > > however, is using recursion instead of looping. > Recursion > > isn't that hard to understand and I figure most Java > > programmers know what it means and how to do it, but > it's > > not the way we usually have done things in > > Imperative-stan, so we're not used to it. > > That's good for simple things like a string, but if more > ambitious things are tried, then FP gets very complex > quickly. Just witness how difficult it is to manipulate > trees (search for Huet's zipper pattern), for example...I > seriously doubt that the majority of programmers will ever > understand such things as the zipper. And then there are > other complex stuff...for example, in trying to program a > game in Haskell, one has to use something like > Haskell/Arrows and be familiar with concatenative > programming...pure FP certainly isn't for the common folks. > That may be true. I don't know. I've never heard of "the zipper," and don't know Haskell. I'm not sure pure FP is what anyone was talking about here. Is Clojure trying to be pure FP? I don't know Clojure much yet, but it looks from the outside like it offers ways to do mutation. It just tries to make it more explicit. Scala for sure isn't pure FP. Behind an actor, for example, you can do things just as imperative as you want so long as you're sure not to share that mutable data with other actors or threads. In fact you can write Scala in the same way you write Java if you want.
What I find has made my code better is not going pure FP, which I've never done, but turning the knob more towards the functional style. I haven't experienced that the functional style added complexity, possibly because I've been doing a hybrid functional/imperative style. Actually I was always doing a hybrid. It's just prior to my exposure to Scala I wrote more imperative and less functional. Now it is the other way around.
|
|