Your SlideShare is downloading. ×
0
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

The secret of Functional Programming revealed!

1,427

Published on

Slides from a ZipTalk i did for the development team at PSWinCom. Code samples in C#.

Slides from a ZipTalk i did for the development team at PSWinCom. Code samples in C#.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,427
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. The secret of Functional Programming revealed!
  • 2. What we have heard..
      • In Functional Programming you only use functions!
        • So no classes or objects..?
  • 3. What we have heard..
      • In Functional Programming you have no variables!
  • 4.
    • Functional Programming
    • seems like a couple of steps 
    • backwards..
  • 5. "Functional Languages are at a higher level of abstraction than object-oriented languages. Though they are more difficult to understand, you can express bigger ideas with less code ."
    • Bruce A. Tate
    • Seven Languages in Seven Weeks
  • 6. Why FP is incredible!
      • Reduces bugs
        • easier to test 
        • easier to trust
      • More compact code
        • no variables
      • More elegant
        • closer to mathematics
        • proofs of correctness
  • 7. And the multi-core hype...
      • Functional Programming promises to make concurrent and parallell programming easier
  • 8. Language differ in their support of Functional Programming
  • 9. Key Concept
    • Referential transparency: 
    • A function always returns the same result, as long as the same arguments are passed into it.
  • 10. No side effects!
    • The purpose of a function is to do nothing other than return a result.
      • No variables must change (be mutated)
      • No visible effects (dialog box, "bing", etc.)
      • No access of external data (files, keyboard, etc.)
      • No reference to variables defined elsewhere
  • 11.
    • Functional programmers say side effects makes your code dirty !
    • The technical term: 
    •                  Imperative code
    • Imperative code is the opposite of functional code  
    • (What about OOP?)
  • 12. Euler problem #1:
    • Find the sum of all the multiples of 3 or 5 below 1000.
    If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
  • 13. Imperative solution..
    • static int Solution(int limit)
    • {
    •      int sum = 0;
    •      for (int i = 1; i < limit; i++)
    •      {
    •          if (i % 3 == 0 || i % 5 == 0)
    •          {
    •              sum += i;
    •          }
    •      }
    •      return sum;
    • }
  • 14. Recursive solution..
    • static int Solution(int limit)
    • {
    •      if (limit == 0) return 0;
    •      int c = limit - 1;
    •      if (c % 3 == 0 || c % 5 == 0)
    •      {
    •          return c + Solution(c);
    •      } 
    •      else
    •      {
    •          return Solution(c);
    •      }
    • }
  • 15. Using Linq..
    • static int Solution(int limit)
    • {
    •      return Enumerable.Range(1, limit - 1)
    •          .Where(i => 
    •              i % 3 == 0 || i % 5 == 0)
    •          .Sum();
    • }
    Learn to love starting functions with return!
  • 16. FP is insane!
    • &quot;All you can do without side effects is push a button and watch the box get hot for a while.&quot;
    • Simon Peyton Jones
  • 17. So what's the secret?
    • There must be some kind of magic that makes you able to implement &quot;normal&quot; programs..
    • Or..?
  • 18. The Philosophy of FP
    • You should break your program into two parts:
      • The biggest part: 
        • Completely functional, free of side effects 
        • This is the clean part!
      • The smaller part: 
        • Has all the side effects 
        • Interacts with the user / rest of the world 
        • This is the dirty part!
    • A program like this is written in a functional style .
    • (Compare to MVC)
  • 19.  
  • 20. Getting started with FP
      • Start using System.Linq for everything:
        • Where           (a.k.a. filter / select )
        • Select           (a.k.a. map / project )
        • Aggregate       (a.k.a. fold / reduce )
        • SelectMany       (a.k.a. mapcat )
      • Practice the clean / dirty separation rules
    •  
      • If time, learn a FP language, then take what you've learned back

×