tags:

views:

76

answers:

2

I find php's Object Orientation somewhat verbose and unsavory. I love working with the cleanliness of functions, and my ideal is to code in php from as close to Clojure's excellent approach to Functional Programming as can be done & still make sense in php.

As I move towards F.P., I've found that it's hard to keep a group of related functions cohesive. In OO, that would be done with shared state and methods that exist as part of the same class. Is there some aspect of F.P. that can be used to help with that?

+2  A: 

maybe namespaces in php 5.3 ?

zolex
+1  A: 

Turning a group of PHP functions into a simple static class is not really that verbose.

class MyClass{

  //all your other existing functions here
  function existing_function(){
   //do something
  }

}

MyClass::existing_function();

I mean, from here, you can do all types of nifty things like make the methods private or protected... but you seem to be against the advantages of OOP, so I'll save that for a different discussion.

Mike Sherov
This is a good answer, but I'd like to point out that the use of classes doesn't necessarily make OOP, and is fully compatible with functional programming.
GZipp
It would actually be more a pseudo-namespace instead of OO. (And it is the first stap on the way most FP programmers I know/knew slowly but steadily came to the OO park).
Wrikken
@GZipp, this is true, but my main goal was to point out that using classes is not that verbose and is a valid way of grouping functions together even if you aren't bothering with the rest of OOP.
Mike Sherov
@Wrikken, that's why my answer was sort of tongue-in-cheek. The first step in Fowler's Refactoring for turning procedural design into objects is to put common functions into a big static class and extract and mold from there.
Mike Sherov
+1, I've actually used this approach to keep phunction (http://sourceforge.net/projects/phunction/) organized into more cohesive [virtual] namespaces.
Alix Axel