Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

There is a common misconception that "OO" is completely contrary to "functional". These things can go hand-in-hand very well. In your example, I guess an "Ant" can be modeled well as an abstract data type, which can be straight forward implemented using classes and objects. Transitions between "Ant states" can be naturally modeled using functions, which will lead you to a functional approach as far as your "Ant" class is an immutable type.

And be aware that "objects" can be interchanged by the functional concept of a closure, since objects are the poor man's closures are the poor man's objects are the ... ;-):

http://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-meanhttps://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-mean

http://stackoverflow.com/questions/501023/closures-and-objectshttps://stackoverflow.com/questions/501023/closures-and-objects

There is a common misconception that "OO" is completely contrary to "functional". These things can go hand-in-hand very well. In your example, I guess an "Ant" can be modeled well as an abstract data type, which can be straight forward implemented using classes and objects. Transitions between "Ant states" can be naturally modeled using functions, which will lead you to a functional approach as far as your "Ant" class is an immutable type.

And be aware that "objects" can be interchanged by the functional concept of a closure, since objects are the poor man's closures are the poor man's objects are the ... ;-):

http://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-mean

http://stackoverflow.com/questions/501023/closures-and-objects

There is a common misconception that "OO" is completely contrary to "functional". These things can go hand-in-hand very well. In your example, I guess an "Ant" can be modeled well as an abstract data type, which can be straight forward implemented using classes and objects. Transitions between "Ant states" can be naturally modeled using functions, which will lead you to a functional approach as far as your "Ant" class is an immutable type.

And be aware that "objects" can be interchanged by the functional concept of a closure, since objects are the poor man's closures are the poor man's objects are the ... ;-):

https://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-mean

https://stackoverflow.com/questions/501023/closures-and-objects

Post Made Community Wiki by Sean McMillan
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625

There is a common misconception that "OO" is completely contrary to "functional". These things can go hand-in-hand very well. In your example, I guess an "Ant" can be modeled well as an abstract data type, which can be straight forward implemented using classes and objects. Transitions between "Ant states" can be naturally modeled using functions, which will lead you to a functional approach as far as your "Ant" class is an immutable type.

And be aware that "objects" can be interchanged by the functional concept of a closure, since objects are the poor man's closures are the poor man's objects are the ... ;-):

http://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-mean

http://stackoverflow.com/questions/501023/closures-and-objects