Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/283875483748294657

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. eachEach object would know how to do things that object does. orOr anything it's parents class does as well. So I can simply tell Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. But that function only does one specific thing. Would I simply have a say() method floating around and call it with an equivalent of Person() argument so I know what kind of thing is saying something?

So I can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base?

For reference, my primary experience with OOP is pythonPython, phpPHP, and some c#C#. The languages that I am looking at that have functional features are scalaScala and haskellHaskell. Though I am leaning towards scalaScala.

Basic Example (pythonPython):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. each object would know how to do things that object does. or anything it's parents class does as well. So I can simply tell Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. But that function only does one specific thing. Would I simply have a say() method floating around and call it with an equivalent of Person() argument so I know what kind of thing is saying something?

So I can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base?

For reference, my primary experience with OOP is python, php, and some c#. The languages that I am looking at that have functional features are scala and haskell. Though I am leaning towards scala.

Basic Example (python):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. Each object would know how to do things that object does. Or anything it's parents class does as well. So I can simply tell Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. But that function only does one specific thing. Would I simply have a say() method floating around and call it with an equivalent of Person() argument so I know what kind of thing is saying something?

So I can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base?

For reference, my primary experience with OOP is Python, PHP, and some C#. The languages that I am looking at that have functional features are Scala and Haskell. Though I am leaning towards Scala.

Basic Example (Python):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')
deleted 42 characters in body
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 310

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. each object would know how to do things that object does. or anything it's parents class does as well. So iI can simply tell Person().speak()Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. butBut that function only does one specific thing. Would I simply have a say()say() method floating around and call it with an equivalent of Person()Person() argument so iI know what kind of thing is saying something?

So iI can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base.?

For reference, my primary experience with OOP is python, php, and some c#. The languages that I am looking at that have functional features are scala and haskell. Though I am leaning towards scala.

Any help or examples is greatly appreciated.

Basic Example (python):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. each object would know how to do things that object does. or anything it's parents class does as well. So i can simply tell Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. but that function only does one specific thing. Would I simply have a say() method floating around and call it with an equivalent of Person() argument so i know what kind of thing is saying something?

So i can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base.

For reference, my primary experience with OOP is python, php, and some c#. The languages that I am looking at that have functional features are scala and haskell. Though I am leaning towards scala.

Any help or examples is greatly appreciated.

Basic Example (python):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. each object would know how to do things that object does. or anything it's parents class does as well. So I can simply tell Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. But that function only does one specific thing. Would I simply have a say() method floating around and call it with an equivalent of Person() argument so I know what kind of thing is saying something?

So I can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base?

For reference, my primary experience with OOP is python, php, and some c#. The languages that I am looking at that have functional features are scala and haskell. Though I am leaning towards scala.

Basic Example (python):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')
Source Link
skift
  • 685
  • 2
  • 8
  • 14

Functional programming compared to OOP with classes

I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. each object would know how to do things that object does. or anything it's parents class does as well. So i can simply tell Person().speak() to make the person talk.

But how do I do similar things in functional programming? I see how functions are first class items. but that function only does one specific thing. Would I simply have a say() method floating around and call it with an equivalent of Person() argument so i know what kind of thing is saying something?

So i can see the simple things, just how would I do the comparable of OOP and objects in functional programming, so I can modularize and organize my code base.

For reference, my primary experience with OOP is python, php, and some c#. The languages that I am looking at that have functional features are scala and haskell. Though I am leaning towards scala.

Any help or examples is greatly appreciated.

Basic Example (python):

Animal(object):
    def say(self, what):
        print(what)

Dog(Animal):
    def say(self, what):
        super().say('dog barks: {0}'.format(what))

Cat(Animal):
    def say(self, what):
        super().say('cat meows: {0}'.format(what))

dog = Dog()
cat = Cat()
dog.say('ruff')
cat.say('purr')