A Brief Collection of Convenient Lies about Functional Programming 91

Posted by Michael Feathers Mon, 23 Mar 2009 15:19:00 GMT

  1. A value is the instantaneous state of an object. – In OO languages, we have objects. In FP languages, we throw out the object and instead manipulate the values it would take on over time.
  2. Algebraic data types are classes. – Every case in an ADT is a state that an “object” can be in.
    
    data Tree = Empty 
              | Leaf Int 
              | Node Tree Tree
    
    When we write functions over ADTs, we are obliged to cover all of the cases. So, for instance, if we define depth for Empty, we have to define depth for the Leaf and Node cases as well. When we do, we can evaluate depth t for any tree value and have a well-defined result.
  3. The functions which we define over an ADT can be considered its public interface. – There’s a school of thought which says that encapsulation doesn’t matter in an functional programming language because values are immutable and corruption can’t happen. Nothing could be further from the truth. If we add or remove a case from an ADT all of the functions which pattern match against it are impacted. While we don’t need to have an encapsulation boundary as tight as we might have in an OO language – it pays to be conscious of how far ADTs travel in a program. Encapsulation is the act of forming a boundary by transforming an ADT into some other form of data.

Each of these statements is a lie, an artful simplification, but they are a convenient and not entirely false way of thinking about functional programming until it becomes second-nature.

Comments

Leave a response

  1. Avatar
    Curtis Cooley about 1 hour later:

    Wow, I’m obviously a Novice at functional programming because almost none of this made sense. Where does a Novice go to get the information for this to make sense?

  2. Avatar
    Sadek Drobi about 1 hour later:

    You can add to that the lie that a pattern matcher is a more powerful switch statement :)

  3. Avatar
    niv about 3 hours later:

    Sorry, but where did you get this stuff? I’ve read tons of functional programming papers, texts, and I don’t think I’ve ever read something like “(...) encapsulation doesn’t matter in an functional programming language because values are immutable and corruption can’t happen.”

  4. Avatar
    Michael Feathers about 4 hours later:

    niv: It’s really just something I’ve heard in conversation. There’s this notion that we don’t really need to be concerned about the fact that the structures we match upon are not encapsulated. I don’t think I’ve run across a book which discusses the extent of an algebraic data type either except to point out that it can be restricted to a module. That seems a bit too narrow for much of the code I’ve seen.

  5. Avatar
    Patrick Logan 3 days later:

    For an algebraic type, the public interface is the algebra itself.

    Functions that use algebraic types are dependent on the public interface of the type.

  6. Avatar
    nike shoes hosting 8 months later:

    I don’t think I’ve run across a book which discusses the extent of an algebraic data type either except to point out that it can be restricted to a module. That seems a bit too narrow for much of the code I’ve seen.

  7. Avatar
    iphone fix 12 months later:

    yeah, you are absolutely right.

  8. Avatar
    disney restaurants about 1 year later:

    That seems a bit too narrow for much of the code I’ve seen and Never say more than is necessary.

  9. Avatar
    latin shoes about 1 year later:

    Most problems happens before testing, nice post anyway!

  10. Avatar
    latin shoes about 1 year later:

    would you mind updating your blog with more information?

  11. Avatar
    jewellery about 1 year later:

    But the discussion has its way of strengthening the definition overtime.

  12. Avatar
    Steam Showers about 1 year later:

    Learn to differ between systematic and unsystematic risks. One is what you can hardly avoid, and the other one is what you can do. Steam showers

  13. Avatar
    yalova emlak about 1 year later:

    Thank you very much for this article.I like its.As to me it’s good job.

  14. Avatar
    cheap vps about 1 year later:

    cheap VPS

  15. Avatar
    iPhone repair about 1 year later:

    You gotta take a lot of math if you wanna study programming, dunno why though. I guess if you wanna do it for kicks then you won’t need much mathematics but programming majors require you take like 3 semesters worth of calculus and differentials.

  16. Avatar
    Promotional merchandise about 1 year later:

    Which also has a double edged sword, made of words. Words are the first and foremost triggers for emotion.

  17. Avatar
    Corporate Branding about 1 year later:

    Math puts you in the mood, prepare your brain to understand programming, If you’re really good at math you’ll shine in programming ONLY if you like programming. your brain is ready dude,

  18. Avatar
    bag manufacturer about 1 year later:

    n OO languages, we have objects. In FP languages, we throw out the objec

  19. Avatar
    antiaging about 1 year later:

    You can interface to quite a few different databases with the correct libraries. Microsoft’s Visual C++ for instance allows binding to Microsoft’s JET engine (used by Access), SQL and a couple of others.

  20. Avatar
    oscillating tool about 1 year later:

    The whole programming language of C is a procedural language. Any code from there would qualify. PHP and Perl are also popular.

  21. Avatar
    Rangemaster 110 about 1 year later:

    nice points there

  22. Avatar
    iphone repair about 1 year later:

    Informative article, thanks for the information

  23. Avatar
    Bill David about 1 year later:

    Nice :) Really like the title. And the post about programming lies is really cool too. Thanks for this. ecommerce website

  24. Avatar
    Hal Smith about 1 year later:

    :P Nice post. Yes you are true to say these lies are very common among programming practices. Thanks for sharing. affiliate marketing

  25. Avatar
    Gina C about 1 year later:

    I didn’t know these were untrue or lies as you call them. Thanks for bring me up to date. Now I can see why these are like that, specially about the one with algebraic data types being considered are classes. online casino list

  26. Avatar
    John Molk about 1 year later:

    Thanks for putting it right and yes the data types are often considered as classes by many programmers. This is because of their behavior within the code. But textually this is wrong and they are just datatypes with different properties than those of classes. casino bonus list

  27. Avatar
    kim russel about 1 year later:

    I really thought those data types were classes. They share the same behavior :). This is new to me, thanks for this post. I knew the one about the instantaneous state of the object but not this. make money online

  28. Avatar
    Justine about 1 year later:

    No these are not same, they are intended for different purposes. Nice post!sterling silver jewelry

  29. Avatar
    Designer Bags about 1 year later:

    Thanks for ur nice sharing!!It help a lot!

  30. Avatar
    Alina about 1 year later:

    Yes I agree with above comments, This blog is absolutely helpful for serious learners. make money online

  31. Avatar
    Hal about 1 year later:

    This blog is pretty helpful for all level of software engineers and students. I cant stop visiting it!affiliate marketing

  32. Avatar
    Angie John about 1 year later:

    Short little article. Enjoyed reading it.affiliate marketing

  33. Avatar
    Billy about 1 year later:

    I am new to programing or more to say I am a beginner in almost every language but not yet up to pro level at any one yet. Which language you guys suggest?internet forum

  34. Avatar
    Pandora about 1 year later:

    It is my favorite patter name (not favorite pattern, just name).

  35. Avatar
    pandora about 1 year later:

    An important feature about buying on the web is you are free to see anything the provides, whereby a store it may be tough to type nonetheless their stock to get the right thing. Parents love gifts which have been remarkable. Try to existing your own mommy utilizing a reward that may be individualized, just as one illustration a wedding ring using their identify personalized inside. Rare metal wedding rings create fantastic items given that they immortalize your current mom?¡¥s title within precious metal. Any platinum necklace along with a pendant produces a fantastic items for the mum, as well as items which can be generally disregarded

  36. Avatar
    michael van der ham about 1 year later:

    At last I found an interesting article. Nice effort .keep it up. michael van der ham

  37. Avatar
    http://www.blacktowhiteiphone4.com about 1 year later:

    Want to buy the hotest white iphone 4 Conversion Kit? www.whiteiphone4.com will be your best online store. Don’t hesitate to buy the charming iphone 4 Conversion Kit!

  38. Avatar
    silicone spray about 1 year later:

    Very interesting and informative article indeed. I have to admit that I always follow your website because it is full of various information about everything. silicone spray

  39. Avatar
    cracked iphone about 1 year later:

    Great article! Thanks for the advice!

  40. Avatar
    accounting services about 1 year later:

    I don’t think I’ve run across a book which discusses the extent of an algebraic data type either except to point out that it can be restricted to a module. That seems a bit too narrow for much of the code I’ve seen.accounting services

  41. Avatar
    fix iphone about 1 year later:

    Your article has all the information I was looking for. You stated the facts very well. :) Thanks!

  42. Avatar
    mimosa hostilis about 1 year later:

    Great! Thanks for the great informative post and you effort. I think the above article is valuable for all concerned people.

  43. Avatar
    smart battery charger about 1 year later:

    This is all very new to me and this article really opened my eyes.Thanks for sharing with us your

    wisdom.

  44. Avatar
    ssara about 1 year later:

    The information forwarded is indeed very helpful. Foreclosure Help in North Carolina

  45. Avatar
    Hollywood Dermatologists about 1 year later:

    Your article has all the information I was looking for. You stated the facts very well. :) Thanks!

  46. Avatar
    jaclyn about 1 year later:

    This article about Lies with the Functional Programming is great! Thanks for the advice! eyelash growth products

  47. Avatar
    laptop screen repair about 1 year later:

    Algebraic functions are a must have in programming, even a novice must be familiar with them.

  48. Avatar
    E Liquid about 1 year later:

    At last I have seen a use for Algebraic functions. Keep up the informative articles!

  49. Avatar
    Big pony over 2 years later:

    Thank you for sharing,it is very helpful and I really like it!

  50. Avatar
    weight loss over 2 years later:

    Your article has all the information I was looking for. You stated the facts very well. :) Thanks!

  51. Avatar
    panic attacks over 2 years later:

    Math puts you in the mood, prepare your brain to understand programming, If you’re really good at math you’ll shine in programming ONLY if you like programming. your brain is ready dude, thanks

  52. Avatar
    How To Get Rid Of Blackheads On Nose over 2 years later:

    Thank you for sharing,it is very helpful and I really like it!

  53. Avatar
    okey oyunu oyna over 2 years later:

    great.

    internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.

  54. Avatar
    canada goose jackets over 2 years later:

    Awww thank you so much :D

  55. Avatar
    mkv to avi converter over 2 years later:

    A value is the instantaneous state of an object. I agree this

  56. Avatar
    convert mkv to avi over 2 years later:

    coming again

  57. Avatar
    christian louboutin shoes on sale over 2 years later:

    What a wonderful article!

  58. Avatar
    beats by dr dre headphones over 2 years later:

    The article is dull. beats by dr dre studio, beats by dr dre pro, beats by dr dre solo, beats by dr dre headphones, monster beats dr dre headphones

  59. Avatar
    Bowtrol over 2 years later:

    hmm ,i’m not sure if this is what i’m looking for but anyway this is interresting and could be useful some day,thanks for taking time to write such cool stuff

  60. Avatar
    beats by dre store over 2 years later:

    useful some day,thanks for taking time to write such cool stuffhigh quality headphones new design headphones

  61. Avatar
    ysbearing over 3 years later:

    Slewing bearing called slewing ring bearings, is a comprehensive load to bear a large bearing, can bear large axial, radial load and overturning moment.

  62. Avatar
    Tips For Bowling over 3 years later:

    PC stuff just lowers the general acceptance of good work and replaces it with bogus poetry that celebrates values that in themselves are probably quite worthy.

  63. Avatar
    holsson34 over 3 years later:

    Good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks Helen Olsson

  64. Avatar
    Cheap Beats By Dr.Dre over 3 years later:

    she does not forget The busy more than in public,

  65. Avatar
    ssara over 3 years later:

    Useful but still need to learn a lot to well process it. allegations impact on crime

  66. Avatar
    beats by dre Australia over 3 years later:

    Very interesting thing, like!

  67. Avatar
    Beats By Dre Canada over 3 years later:

    Very first, the two fresh machines and other technology via digital processor chip with unique Sony technologies

  68. Avatar
    Dr Dre beats Headphones Canada over 3 years later:

    S-expansion of all-digital running to distinguish involving the bass as well as stereo,

  69. Avatar
    beats by dr dre over 3 years later:

    A university studentbeats by dr dre caught by the enemy, the enemy tied him at the poles,just beats solo headphones purple and then asked him: say, where are you? You do not say it electrocuted! Scheap dr.dre beats studio headphones balck/yellowtudents back to the enemy a word, the result was electrocuted, he said: I am TVU.Hot sale beats by dr dre pro headphones

  70. Avatar
    computer over 3 years later:

    Good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks Helen Olsson

  71. Avatar
    dentist medford or over 3 years later:

    I just came across your blog and reading your beautiful words. I thought I would leave my first comment but I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

  72. Avatar
    iphone contacts backup over 3 years later:

    All-in-one solution to backup iPhone contacts and SMS, transfer iPhone video, songs, ebooks, photo, call list and more to computer or iTunes

  73. Avatar
    sallyerma over 3 years later:

    I have been searching all over the blogs for a relevant article related to this topic for a paper I am writing. I’ll be sure to come back to your blog for other valuable information next time I need solid information on this subject. layered hairstyles

  74. Avatar
    Office 2010 over 3 years later:

    This article is GREAT it can be EXCELLENT JOB and what a great tool!

  75. Avatar
    military electronics over 3 years later:

    We can handle any of your military component needs

  76. Avatar
    boat shipping over 3 years later:

    This post is exactly what I am talking about lots of people getting together and writing about subjects they enjoy! Thank you and maybe when you get time you can check out.

    boat shipping

  77. Avatar
    Easy to do hairstyles over 3 years later:

    Thank you very much for this article.I like its.As to me it’s good job

  78. Avatar
    http://athales.com/services-reparation/services-reparation-ipad-et-tablette/reparation-ipad.html over 3 years later:

    Merci de votre partage, je l’aime bien, y compris les amis et les articles sont également très utiles, je vous remercie pour tout le monde profiter du plaisir! reparation ipad

  79. Avatar
    short hairstyles for women over 3 years later:

    This is an intelligent blog. I’m serious. They have so much knowledge on this subject, so much passion. They also know how to do habitancy rally behind him, apparently from the answers. You’ve got here is not to find the obvious.

  80. Avatar
    mbtshoe over 3 years later:

    Australia Beats By Dre Studio dr dre beats headphones beats studio beats pro beats solo hd pro headphones music Official store Monster Beats By Dre Pro

  81. Avatar
    Government jobs over 3 years later:

    Thank you for sharing,it is very helpful and I really like it!

  82. Avatar
    Sarkari Naukri over 3 years later:

    hmm ,i’m not sure if this is what i’m looking for but anyway this is interresting and could be useful some day,thanks for taking time to write such cool stuff

  83. Avatar
    Bank jobs over 3 years later:

    Awww thank you so much :D

  84. Avatar
    Classifieds over 3 years later:

    You gotta take a lot of math if you wanna study programming, dunno why though. I guess if you wanna do it for kicks then you won’t need much mathematics but programming majors require you take like 3 semesters worth of calculus and differentials.

  85. Avatar
    celebrity gossip over 3 years later:

    I like its.As to me it’s good job

  86. Avatar
    best short haircuts 2012 over 3 years later:

    It is perfect time to make some plans for the future and it’s time to be happy. I have read this post and I really really like the topic about gadgets.

  87. Avatar
    Wedding Hairstyles 2011 over 3 years later:

    “It is perfect time to make some plans for the future and it’s time to be happy. I have read this post and I really really like the topic about gadgets. “

  88. Avatar
    louboutin sales over 3 years later:

    A Brief Collection of Convenient Lies about Functional Programming 87 hoo,good article!!I like the post!120

  89. Avatar
    corporate catering philadelphia over 3 years later:

    aint that the truth thanks for clearing that up

  90. Avatar
    asian handbags over 3 years later:

    I am just a start up programmer and I think this is something that I should consider researching as well.

  91. Avatar
    hermes bolide price over 3 years later:

    Women handbags are considered as fashion statement that can make or break each outfit that a woman is wearing?

Comments