Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I just started with functional programming (with JavaScript and Node.js) and from the look of things it looks as if the code I am writing would grow to be one hell of a code base to manage, when compared to programming languages that have a sort of object oriented paradigm.

With OOP I am familiar with practices that would ensure your code is easily managed and extensible. But am nore sure of similar convention with functional programming.

share|improve this question
3  
JavaScript is an object oriented language, so go on and use your OOP skills using Node.js –  Jonas Nov 26 '11 at 15:10
4  
try functions. Those will solve almost every problem. –  tp1 Nov 26 '11 at 17:00
4  
Here's a great resource on keeping your node source code neat and tidy and therefore manageable: nodeguide.com/style.html –  danielrbradley Nov 26 '11 at 17:20
2  
As far as I know, the only functional programming feature JavaScript has is lambdas (more accurately, nameless functions) and function passing. If you want to learn functional programming, you should probably look into something like Haskell or F#/OCaml or Scala or Lisp. –  Rei Miyasaka Nov 26 '11 at 20:01
add comment

3 Answers

up vote 3 down vote accepted

In practice, a large functional codebase will still need to be divvied up in some sort of structural system. If you are comfortable in OOP, classes remain the natural structuring element. You strive for "functional objects": conceptually related functions are placed together in a class. Of course, you avoid non-conversational state and reliance on instance variables.

Going beyond structure, there are certain techniques, such as partial function application, that are preferred in the functional world for extension, maintainability, and generalization. Learning to recognize these opportunities can be difficult when working in a hybrid functional/object mode, though. Personally, I think it is a good idea to work in a hybrid mode but to study and play in a more pure environment, such as that provided by Haskell.

share|improve this answer
add comment

Rather than abandoning OOP for FP, try augmenting it with some FP patterns. Any time you need to process a collection is a good candidate and points to a common set of FP methods like map, fold and reduce. Take a look at underscore.js and backbone, an MVC framework that makes extensive use of the former.

share|improve this answer
add comment

Functional programming languages enjoy a lot of powerful concepts to build high quality code, for example: Partial applied functions, functions compositions (this one is really powerful and my favorite), macros, higher order functions. And not to forget immutable data structures.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.