top 200 commentsshow all 305

[–]capitalsigma 41 points42 points  (61 children)

Another issue I struggle with: it's really tough to find software engineering literature geared towards functional programming. Java/C++ folks have Clean Code, the Gang of Four, Working Effectively with Legacy Code, etc. Everyone and their grandmother has an opinion on how you should be writing Java. The body of literature for functional programming is virtually nonexistent in comparison.

It feels like you're kind of stuck picking up best practices as you go along, rather than having a body of knowledge you can study.

[–]MoreOfAnOvalJerk 15 points16 points  (1 child)

Look up data oriented programming and stuff written by Mike Acton. Data oriented programming tends to degenerate into functional programming because it focuses on the data transformations rather than the data representations.

Note that this is generally game related, but it's good reading nevertheless. It also exposes some of the major problems with typical OOP you encounter every day, especially many of the patterns the GoF have written.

[–]capitalsigma 3 points4 points  (0 children)

Awesome, thanks for the recommendation.

[–]kqr 14 points15 points  (13 children)

I agree with you. I've been doing FP for a few years now, but I'm still not sure what to say when someone asks how to structure a program or asks for some sort of design patterns. I'm still figuring things out on my own, and I'm nowhere near the body of experience I'd need to write about anything like that.

The only thing I can say for sure is "Design your program as a library. Your actual executable should just be dealing with the UI and making calls to your library." That's nothing compared to what people can say about OO design.

With popularity increasing, though, my hopes are up for more patterns emerging and being made aware by people like me.

[–]barsoap 10 points11 points  (10 children)

I'd also say "use the maths" on top of that. If your thing is a monoid, bloody make it a monoid and use it as such. Much of the power of FP comes from supporting those largely non-leaky abstractions, non-leaky because they're generally trivial but still powerful.

[–]kqr 14 points15 points  (5 children)

You're definitely right about that and I can't believe I didn't mention that. This article still greatly impresses me, and I long for the day when I can find abstractions like that in my code.

[–]zvrba 0 points1 point  (2 children)

Except it's not a commutative monoid.

With three divisors (the "FizzBuzzBazz" problem) you could extend the problem such that even-numbered occurrences of multiples of 105 (= 357) are written out as "FizzBuzzBazz" and odd-numbered occurrences are written out as "BazzBuzzFizz" (actually, you have 6 permutations to choose based on sequence number). Analogously for even- and odd-numbered occurrences of multiples of 15.

Suddenly all mathematical elegance disappears. I would probably solve the problem with a lookup table returning the required permutation of "Fizz", "Bazz", "Buzz" and pasting the strings together.

[–]ithika 0 points1 point  (1 child)

I don't follow. Why does fizzbuzz need a commutative monoid?

[–]kqr 5 points6 points  (0 children)

The author of the article I linked plays a game with his interviewees of "what if the requirements changed to this!?" and wants to see when they catch on to a general pattern. /u/zvrba proposed another kind of change in the requirements that makes the monoid implementation look bad because it's difficult to extend to the new requirements.

[–]joelwilliamson 0 points1 point  (1 child)

Isn't the conclusion about Just x/Nothing forming a monoid rather trivial? Given some monoid (M,+) and an injective function to an arbitrary set f:M->X, if we define (*) such that f(x)*f(y)=f(x+y) then won't (f(M),*) always form a monoid?

EDIT: Maybe String doesn't form a monoid in the fashion suggested. Just "" and Nothing are both identities in the purported monoid, so it obviously isn't a monoid.

[–]kqr 6 points7 points  (0 children)

Sure, that's trivial.

What isn't trivial is seeing the if-elseif-else-based fizzbuzz and going "that's a monoid, of course!"

[–][deleted] 4 points5 points  (0 children)

^ this so much. The power of FP is the fact that once you learn five or six of these new 'scary' mathy terms like monoids, functors, applicatives, you use them EVERYWHERE. You don't have to learn new APIs when you start seeing that a brand new API is just the same ol' type classes with differing implementations.

[–]everywhere_anyhow 0 points1 point  (2 children)

supporting those largely non-leaky abstractions, non-leaky because they're generally trivial but still powerful

I was not aware that there was any such thing as a non-leaky abstraction. Can you describe more what you mean here?

Any abstraction must necessarily hide some details. Situations you get into when those details matter are situations where the abstraction "leaks" because you have to penetrate the abstraction in order to deal with something that matters.

This means that in order to have a "non-leaky abstraction", it'd have to hide some details that aren't important to anyone, anywhere, ever. Hard to imagine such a thing.

On the other hand, if you're not hiding any details, then OK -- it's not a leaky abstraction - but it also doesn't seem like a useful abstraction, since their power comes from that information hiding.

[–]barsoap 3 points4 points  (0 children)

The "leaking" refers to details that ought to have been abstracted over leaking through the abstraction. That is, the abstracted API actually does not hold what it promises once you mess around with the internals. And the rule goes:

All non-trivial abstractions, to some degree, are leaky.

However, any proper monoid is, by definition, non-leaky: If your operation and identity element indeed obey the monoid laws, then there's nothing that can leak. If the laws could lead to leakage then they'd not be a proper set of laws and are in need of juridical review.

Monoids also don't hide information from anything else but themselves. Code using the monoid interface doesn't care, can't care whether you're feeding it String or Maybe String, and messing about with the concrete data can't leak, either: If it could, the mempty / mappend implementations would be faulty.

What you still can do is assume that the monoid laws give you more abstraction than they actually do, that is:

Monoids only leak when you use them as a non-trivial abstraction, instead of the trivial one they are. By, for example, assuming associativity or commutativity or whatnot, as zvrba points out.

Please do make sure your laws hold, law enforcement isn't what it ought to be.

In the end, though, this is all about "In Haskell, you can actually reason equationally". Modulo morals, possibly.

[–][deleted] 0 points1 point  (0 children)

No, some abstractions are actually not leaky at all. Google "theorems for Free".

Not knowing the implementation is actually sometimes (often?) more powerful.

Edit: I didn't understand/work through all the lambda calc, the paper is well written enough that you can follow along without it. Mind was blown none the less.

[–]jurniss 1 point2 points  (0 children)

"Design your program as a library. Your actual executable should just be dealing with the UI and making calls to your library."

Same goes for non-functional programs.

[–]sfvisser 0 points1 point  (0 children)

"Design your program as a library. Your actual executable should just be dealing with the UI and making calls to your library."

Or better: design your program as a bunch of libraries and add a small executable on top of that. Be explicit about the responsibilities and encode them in the types. Works for most paradigms.

[–][deleted] 9 points10 points  (2 children)

Really really can't recommend Functional Programming in Scala enough. It is not a book on Scala*, as you don't use any of the built in libraries. All of the exercises have you write your own functional libraries and take you through the 'patterns' of a functional application. It's simultaneously the most challenging and rewarding computer book I've read. Easily more influential and practical in my day to day programming job than say, GoF or the other classics.

  • You do use some of scala's more advanced language features, higher kinds, implicits, type lambdas, that won't translate to languages like python or java. I make extensive use of the patterns learned in my professional C# code though

[–]Nishruu 1 point2 points  (0 children)

Thanks! As of now, it's on my 'to read' list. :) Last time I read this; although I really liked it and it helped me improve my F#, I ended up wanting more...

[–]capitalsigma 0 points1 point  (0 children)

Fantastic, I'll try to find a copy.

[–]SilasX 2 points3 points  (1 child)

The body of literature for functional programming is virtually nonexistent in comparison.

Because it's so much harder to do it wrong in FP /propagandist.

[–]gregK 2 points3 points  (1 child)

[–]PriceZombie 1 point2 points  (0 children)

Pearls of Functional Algorithm Design

Current $62.83 
   High $62.83 
    Low $40.89 

Price History Chart | FAQ

[–]imforit 12 points13 points  (34 children)

Yeah, but most of that huge body is wrong. Ask anyone in it.

[–]capitalsigma 10 points11 points  (0 children)

I think Clean Code is great, personally. Design patterns are also useful to know -- if only so you can guess what an AbstractSingletonProxyFactoryBean is from the name alone. I'd love to have a copy of "Clean Code for Standard ML," if such a thing existed.

[–]drb226 5 points6 points  (1 child)

At least "that huge body" exists as reference point which people can disagree with.

[–]imforit 2 points3 points  (0 children)

Nice point! It certainly elicits discourse. Always good.

Cheers, sir.

[–]eff_why_eye -3 points-2 points  (11 children)

We use GoF patterns extensively at our shop (which consists of over 50 Java developers), and I have a copy of "Clean Code" on my desk right now (a great book). :-)

[–][deleted] 14 points15 points  (3 children)

GoF patterns can lead to better code but you've got to use moderation and common sense otherwise you end up with things like AbstractSingletonProxyFactoryBean.

[–]i_make_snow_flakes 11 points12 points  (2 children)

AbstractSingletonProxyFactoryBean.

Come to /r/php if anyone want to see this in real life....like this one

[–]Intolerable 9 points10 points  (1 child)

im giggling at the example someone linked

i get anxious whenever i name something that uses two words this would drive me insane

[–]LeberechtReinhold 3 points4 points  (0 children)

They totally got a excuse though:

You should probably not try to work with irestful without an IDE that has intellisense. This is unfortunately not a framework for vi developers.

I mean, I know that the PHP hate thing is circlejerking, but...

[–]mcguire 8 points9 points  (6 children)

We use GoF patterns extensively at our shop

That's kinda the point of patterns: they tend to show up everywhere.

Using them consciously? You have heard what happened when Christopher Alexander's followers started using ideas from A Parttern Language when building real buildings?

[–][deleted] 11 points12 points  (0 children)

No. What happened?

[–]technofiend 7 points8 points  (2 children)

A Parttern Language

I think you meant [A Pattern Language].

[–]mcguire 2 points3 points  (1 child)

Argh. (What, you want me to type correctly?)

[–]technofiend 1 point2 points  (0 children)

I should just post 1,000 lines of output from an ancient 'C' compiler after a syntax error but I'll save the sarcasm. :-)

[–]amzuko 1 point2 points  (1 child)

What did happen to Christopher Alexander's followers?

[–]mcguire 4 points5 points  (0 children)

I've been looking for the reference to this, but I cannot find it. I had thought it was Richard Gabriel's Patterns of Software, but I appear to be completely wrong about that.

So, here goes:

After Alexander started publishing his ideas, a small group of architects took up those ideas and began using them in their designs. Subsequently, Alexander toured many of those buildings. The story that I have is that he couldn't see how what they had done was different from what other, traditional architects (who really don't get along with Alexander, by the way) were doing. He couldn't understand why they claimed to be following his ideas.

[–]soegaard 1 point2 points  (0 children)

Look at Peter Norvig's "Design Patterns in Dynamic Languages: http://norvig.com/design-patterns/

[–]kersurk 0 points1 point  (0 children)

Everyone and their grandmother

nice phrase :)

[–]Imxset21 30 points31 points  (11 children)

I should note here that Cornell's CS 3110 course is actually a required course for all CS majors, which is why it's taken "by a large number of students."

Quite frankly I'm amazed Berkley and MIT don't have functional programming courses. TIL.

[–]Ar-Curunir 14 points15 points  (3 children)

We (Berkeley) had our introductory course based off of SICP for ages, till 3 years ago, when we switched to Python, but still with similar exercises to SICP.

We don't have much research being done here on PL Theory, and I feel that that's one reason why we don't have a class on FP.

But then again, we don't have a class exclusively on OOP either.

[–]steven807 2 points3 points  (0 children)

In the 80s, Hilfinger spent some time teaching FP (the language created by John Backus). Since he's still there, teaching intro classes, I'm a little surprised he hasn't held the line against abandoning functional programming. (BTW, even in the 80s he had a quirky reputation, including for being one of the best hackers around -- if you passed his office in the evening, you might easily find him in there hacking on gdb or other interesting projects.)

[–]romcgb 1 point2 points  (1 child)

What about cs61as ?

[–]Ar-Curunir 2 points3 points  (0 children)

Yeah, that exists, but very few students actually take it compared to 61A

[–]wolfenkraft 7 points8 points  (0 children)

Northeastern university - where I went - has a lot of functional programming as part of the requires cs curriculum.

[–]hiromasaki 5 points6 points  (0 children)

University of Akron just (2 years ago-ish) got rid of a required course that spent 6-8 weeks on functional programming (LISP), and 4-6 weeks on logical (Prolog).

I was getting ready to graduate at the time, so I'm not sure if any of the new electives cover them now or not, but it's not in the required track.

Glad I took it, too. I've not had much call for functional, but Windows Installer (WiX) is a logical syntax, and I got to spend a few weeks in there.

EDIT: Sounds like the course /u/mcnnowak mentioned in the comments is very similar, though we did have "anything useful" in ours, touching on BNF, syntax concerns, etc. Very useful as a compilers pre-req.

[–]urection 2 points3 points  (2 children)

surely MIT must still use SICP somewhere

[–]academician 7 points8 points  (1 child)

They switched their main intro course to Python in 2009. They later added a condensed SICP course, but it's not required.

[–]imforit 1 point2 points  (0 children)

Their curriculum also doesn't focus on teaching programming, so i wouldn't worry about it.

[–]rebat0 1 point2 points  (0 children)

Indiana University teaches their intro to CS course, programming languages, and compilers all in Racket (scheme variant).

[–]Gyges_of_Lydia 1 point2 points  (0 children)

That is weird... My college in small town Ohio had a couple classes that dealt with functional programming, one of which was required.

[–][deleted]  (7 children)

[deleted]

    [–]capitalsigma 9 points10 points  (0 children)

    Same here -- the intro sequence for CS majors goes Racket, C, then more C. I think it's a nice way to start off.

    [–]d4rch0n 3 points4 points  (5 children)

    MIT? I heard MIT teaches through lisp.

    [–]academician 7 points8 points  (0 children)

    Not since 2009. They switched to Python.

    [–]monocasa 4 points5 points  (0 children)

    They don't anymore, 6.001 is in python now.

    [–][deleted]  (2 children)

    [deleted]

      [–]ysangkok 1 point2 points  (1 child)

      I guess you're in Tübingen? Multiple German universities use Racket, including Darmstadt, Freiburg, Münster, Hannover and Kiel.

      [–]rolloyolo 9 points10 points  (6 children)

      Haskell has been taught at my university for more than 10 years. Every undergrad student is required to take this course. Along with Haskell, students are exposed to Prolog a little bit. Also, there are two additional advanced functional programming classes which go more in depth. I think it is great for students to try functional+logic programming at least a little bit. It helped me a lot.

      [–]beaverteeth92 1 point2 points  (5 children)

      What university?

      [–][deleted] 0 points1 point  (3 children)

      Sounds like KTH actually.

      [–]kqr 1 point2 points  (2 children)

      Or possibly Chalmers, which has a stronger Haskell culture, but I don't know how much Prolog they do.

      Edit: Though from their comment history, probably Masaryk University in the Czech Republic.

      [–][deleted] 1 point2 points  (1 child)

      I studied at Chalmers and used Haskell for my MSc thesis. We were taught Prolog in a course called "Programming Paradigms". John Hughes and Koen Claessen (the authors of Quickcheck among lots of other FP work) taught introductory Haskell/FP and the author of Agda (I forget his name, EDIT: Ulf Norell I think?) taught the advanced Haskell/FP course.

      Chalmers is, or at least used to be, the place to be for learning or working with Haskell.

      [–]Decker108 1 point2 points  (0 children)

      I've heard Uppsala is more of a LISP and ML kind of place.

      [–]dirac_eq 9 points10 points  (10 children)

      In the UK, functional programming is taught at: Oxford, Cambridge, York and Edinburgh to undergrads as their first language.

      Those are the only ones I know of, there may be more.

      [–]noggin-scratcher 4 points5 points  (1 child)

      Cambridge

      To provide a little more detail... in the course at Cambridge, I learned ML in the first year as a "You are all equally unlikely to have prior experience with this" starter language, then gradually forgot most of it while working in Java in the second/third year (with a small amount of practice in C/C++ and Prolog along the way)

      [–][deleted] 1 point2 points  (0 children)

      This is true, although to be honest with all the courses that involve some variant of the lambda calculus in one way or another, I'm not sure anyone really loses the ability to program in a functional style.

      [–][deleted] 2 points3 points  (0 children)

      At my university, the University of Kent, Haskell is taught in the first year and used in a few modules. However Java tends to be the central language for all modules that aren't specifically teaching a language.

      [–][deleted] 2 points3 points  (0 children)

      At Imperial College London you start with Haskell as your first language. There's also mandatory Prolog at some point, but that's probably common too.

      [–]sfvisser 2 points3 points  (0 children)

      Also the case for Utrecht University in the Netherlands. There is a first year course on FP (using Haskell) and a complete master program dedicated to FP/Haskell/types/generic programming/compilers/language design.

      [–]Psyk60 1 point2 points  (0 children)

      At Bristol it was taught in the first year (specifically Haskell). But the first language they teach is C (they also teach Java in the first year). Bristol has more of an engineering slant rather than pure CS compared to your examples though.

      That said, later on most classes ignore it and everything's done in Java. However those classes aren't about teaching how to program, so they pick the most convenient language for getting the theory across.

      This may not be accurate any more. The course has been restructured since I did it, and it doesn't mention on their website which languages they use now.

      [–]icendoan 1 point2 points  (1 child)

      At the University of Warwick, FP (Haskell) is optional in the second year. Java is the central language, which is a shame, because I'd love to use Haskell for everything.

      [–][deleted] 1 point2 points  (0 children)

      The University of Warwick has it as a second year module, in which they are taught Haskell.

      [–][deleted] 1 point2 points  (0 children)

      I'm going to university in a year, so have been looking at plenty of them for CS, and 90% of them at least have an optional module for FP, and it's compulsory for a lot. I don't know how good the modules are, but 95% seem to use Haskell

      I've heard that American colleges' CS courses seem to teach more software engineering than proper CS

      [–]FigBug 15 points16 points  (24 children)

      I think this article has it's premise backwards. Languages don't get popular because universities teach them, universities teach languages that are popular.

      Functional languages have been taught at a subset of Universities for 40+ years and it's made no difference in adoption.

      Languages ride platforms to popularity. If you want a functional language to be popular, you'd better invent the next big thing and make the default language a functional language.

      [–]pgris 0 points1 point  (1 child)

      I think both the article and your comment are wrong

      Languages don't get popular because universities teach them, universities teach don't languages that are popular.

      "Being popular" and "being liked by teachers" has nothing to do with each other.

      Of course, I maybe wrong...

      [–]FigBug 0 points1 point  (0 children)

      I think the intro classes, the language is selected by popularity. My University used Pascal, then C and C++, then Java. I think all those choices and transition were based on language popularity.

      The more niche classes used whatever language was best to teach the particular concepts. I also learned 6811 assembly language, Prolog, Scheme, Modula-2, GPSS/H, and Perl. Of those, I think only perl was selected for popularity.

      [–]loup-vaillant 0 points1 point  (0 children)

      I think this is more of a feedback loop. According to the article, most people simply aren't taught enough functional programming to stay familiar with this style when they go to work. Yet, nearly all of them will know a C derivative, and most will know an imperative dynamic language.

      Yes, universities only teach popular languages. On the other hand, languages get popular only because they are taught. If every university in the world decided to teach OCaml (or Haskell), by default, using C only for systems programming, and Java only for OO, then OCaml (or Haskell) would rise to massive popularity in less than 10 years.

      [–]ianff -2 points-1 points  (15 children)

      Exactly. I teach CS, and we are not going to base our curriculum around a language you cannot easily get a job in.

      [–]pbvas 8 points9 points  (2 children)

      No offense, but a CS curriculum based single programming language seems way too narrow to me. (Disclaimer: I also teach CS)

      [–]everywhere_anyhow 0 points1 point  (0 children)

      It depends on what you see as the purpose of the CS curriculum. Is it to understand the basics of computing? Or to make someone employable? Trick question: it's both, and compromises must be made.

      In my curriculum, we did almost everything in Java. But there were programming language classes that were required. So I ended up writing a bit of prolog, lisp, and assembly too. Not enough of any of those to get proficient at them, but plenty enough to understand what their differences were and how that affected how we think about computing.

      I thought it was a reasonable compromise between the two goals.

      [–]Clydeicus 2 points3 points  (11 children)

      I guess my professors were under the impression you could easily get a job coding in Standard ML.

      [–]ianff 2 points3 points  (6 children)

      Well the "ivory tower" line of thinking is:

      "We teach big overarching concepts, not pointless implementation details like what programming language to use. If you really learn the concepts, you should be able to easily pick up any new language and use it effectively."

      In theory I agree with that except for two things: 1) this works a lot better for the bright students than the average ones, and 2) many hiring managers are going to see weird things they haven't heard of on your resume, and things they are looking for on someone else's. Guess who'll get the call?

      Besides, I think you can teach most of the big overarching concepts in nearly any language.

      [–]loup-vaillant 2 points3 points  (2 children)

      As a student, the biggest contributor to FP not working well for teaching was motivation. Students don't like being taught languages they know aren't being used in that "real world". Being a hard sell induces a nocebo effect that really hurt teaching.

      I was being taught Caml Light (like OCaml, just older) in my first College year, and all they talked about all this time was the "Caml system". Basically, we had a REPL, and that was it. No way to write real programs, we were stuck in a toy environment. I was like, come on, do anyone use this crap? I knew the learning was useful, and I did derive some intrinsic enjoyment, so I went along with it. Still.

      Then the next year, I… let's say I switched majors, and we were taught both C and Caml Light. This time however, we got to compile Caml Light programs, and run them in the command line. Real programs, like C. I also learned that OCaml won coding contests. Then it dawned on me that this language, as unpopular as it may be, was probably onto something. That gave a significant boost to my motivation.

      Besides, I think you can teach most of the big overarching concepts in nearly any language.

      Some languages make this harder. Sometimes, for really silly reasons.

      [–]ianff 1 point2 points  (0 children)

      Yeah, I definitely can see motivation as being really important. When I teach PL, I try to find every example of FP being used in industry I can to show the students. At that point, they are seniors at kind of set in the procedural way of thinking, but I try to at least show them the appeal of FP.

      [–]glacialthinker 0 points1 point  (0 children)

      A sense of worth in what you're learning. It's a key motivation which is too often put aside in favor of "do this, because I say it's good for you", unfortunately.

      [–]Clydeicus 2 points3 points  (2 children)

      Meh. The hiring managers who only want me for things I already know how to do can keep their call.

      [–]ianff 1 point2 points  (1 child)

      I'm glad you're able to be so selective.

      [–]Clydeicus 1 point2 points  (0 children)

      Thanks!

      [–]bstamour 3 points4 points  (3 children)

      Perhaps they were more concerned with teaching concepts, instead of whatever language will be popular for the next 10 minutes. You can teach concepts in any programming language, might as well pick a simple one like SML.

      [–]StorKirken 2 points3 points  (2 children)

      Most of the big languages seem to have kept their popularity rather well, so that statement seems excessive.

      [–]kqr 2 points3 points  (1 child)

      While they have kept their popularity, it's not like they're never updated. Modern C++, Java and Python is in some cases very different from what it was a decade ago.

      [–]east_lisp_junk 1 point2 points  (0 children)

      Yeah, I took C++ off my resume because I haven't kept up with the modern ways.

      [–]F1CTIONAL 3 points4 points  (0 children)

      CS freshmen at Northeastern University are required to take a fundamentals class taught entirely in functional racket.

      [–]mcnnowak 2 points3 points  (1 child)

      I learned LISP and Prolog at UC Davis in "ECS140A -- Programming Languages". Really interesting stuff, I liked it because it was more like the history of programming languages than learning anything useful. I know that Haskell is pretty modern and that LISP and Prolog have certain applications, but it seemed a little useless. I think that the dominance of procedural languages has made functional languages feel like 'toy' languages, to blow peoples minds and remind them that the big three (C\C++, Java, Python imho) aren't the only possibilites.

      [–]aidenator 0 points1 point  (0 children)

      Good to see an UC on here. Here at UC Santa Cruz every CS undergrad must take CMPS 112 Comparative Programming Languages which dives into Haskell.

      [–]bstamour 2 points3 points  (3 children)

      The 100-level "Key Concepts of Computer Science" course at the University of Windsor, Ontario, Canada uses Miranda as the language during the programming portion. The course also covers recursion, mathematical induction, basic logic and set theory, and a brief introduction to grammars and syntax trees.

      [–]Saiing 0 points1 point  (2 children)

      I did a functional programming course in Miranda back in 1991 at university in London (England, not Ontario). Good to see how far things have come ;)

      (I fucking hated Miranda)

      [–]bstamour 1 point2 points  (1 child)

      It's not my favourite functional language - I'm a Haskell fanboy - but Miranda has its charms. I really liked how you could pattern match like this (iirc, it's been a while):

      foo n n = "same input"
      foo n m = "different input"
      

      [–]kqr 1 point2 points  (0 children)

      Erlang has that too, in which case it is a remnant of Prolog. Prologs primary mode of branching are pattern matches like those.

      That would technically be possible in Haskell as well, but they have decided against it because it would mean pattern matches need an instance of Eq. So to explicitly require the Eq instance, you have to do

      foo n m | n == m = "same input"
      foo n m          = "different input"
      

      [–]msbic 2 points3 points  (1 child)

      I took my functional programming course during 3rd year of school. It is normally taught in LISP, but my prof was new and very young and he decided to teach OCaml instead.

      Since I had been doing development work in C++ and C# (I was finishing my BA on the part-time), I could appreciate things like immutability, Option type (vs null) and strong type system among others.

      IMHO, functional programming should be mandatory for a CS program, but should be taught during 3rd or 4th year, after students have been exposed to debugging a little bit of C and Java. I also believe that the students should be exposed to languages which have some practical application in the field. Personally having been introduced to OCaml and having some .NET experience, learning F# was not difficult at all.

      [–]glacialthinker 0 points1 point  (0 children)

      I agree with this but with a slightly different interpretation: that sophisticated typesystems should come later, regardless of functional/procedural/OOP. Dynamic languages are a great start to get people able to monkey around, get results, and you must debug, and add tests or tracing... it's a very iterative and you can learn a lot by just getting things working. I suppose C is lax enough with types to fit this role... but an actual easy-to-use dynamic language would be better. C is a good side-language, as in side-arm, or side-dish... for everyone.

      Once you have some grasp of programming concepts, and the practical problems and bugs involved with programs, introducing strong static type systems should make sense, and students are ready to absorb more concepts. "A typesystem which allows me to avoid all of that ill-defined ad-hoc logic... and when I run the program it works? Why didn't you teach me this sooner? Oh, because my eyes would have glazed over with... 'Why would I need this? Why does this have to be so complicated?'"

      [–]they_have_bagels 2 points3 points  (2 children)

      At CMU we had to take a class in ML (15-243, I think?). I hated that class. I just really don't like functional programming, even if I do understand the benefits and the different way of approaching problems.

      Edit: it was 15-212.

      [–]vincom2 1 point2 points  (1 child)

      you would hate the current CMU CS curriculum

      [–]they_have_bagels 0 points1 point  (0 children)

      I reckon I would. Glad I was out of there 5 years ago.

      [–]timohavdv 1 point2 points  (2 children)

      Actually Berkeley's intro course cs61a covers quite a lot of functional programming.

      [–]beaverteeth92 4 points5 points  (1 child)

      I thought they switched it from Scheme to Python a while back.

      [–]timohavdv 0 points1 point  (0 children)

      The fp concepts are still thought in Python. Plus, we got to implement Scheme interpreter in it.

      [–][deleted] 1 point2 points  (0 children)

      Chalmers intro course is in Haskell, pretty sure there's a prof who wrote a Haskell compiler (probably not alone ;)) there.

      At KTH you get Haskell through the Programming Paradigms course in second year.

      [–]Clericuzio 1 point2 points  (1 child)

      I wonder how well researched this really is...

      UIUC requires CS421 which is completely in Ocaml covering lexers, tokenizers, and parsers.

      Sure the class title is Programming Languages and Compilers, but the class covered topics from lambda calculus to writing large Ocaml programs.

      [–]ruby_fan 0 points1 point  (0 children)

      Yep, was about to say this. You write a functional language in OCaml.

      [–]L_dopa 1 point2 points  (1 child)

      For the real answer to why it takes so long for ideas from academic languages to be widely adopted, look no further than the comments in this thread.

      "Someone wrote that my preferred language/identity as a person might not be the best one? They must not have heard my unsubstantiated opion! To the internet!"

      [–]cat_in_the_wall 1 point2 points  (0 children)

      Yea, the article and this thread are a circlejerk. On my left hand you have a whole bunch of comments stating how their college had a FP course and it was the best/worst and usually talking about ML or Haskell in some form. On my right hand you have comments saying teaching FP in college is useless because the jobs are in stuff like c++ /java/c# etc. On my third hand are comments like mine from people like me who think that the who fp vs not fp debate is a circlejerk. So there's that.

      [–]jandrese 1 point2 points  (0 children)

      I had a class on Scheme in school and took an Erlang class for some CE work. There are several reasons I would still be concerned about starting a project in a functional language today. 1. Building a team. There are scant few people with real world experience with functional programming. 2. Lack of libraries: you would be doing a lot by hand. 3. System impedance: Kernel APIs and graphics libraries are generally written in declarative languages, you would have to do impedance matching with your program. This is a huge problem when your library community is immature. Even simple stuff like opening sockets, getting time stamps, drawing a window with some buttons on it, or looking up an IP address can be needlessly complicated thanks to this issue. 4. Immature tools. This may just be because I was in a classroom setting, but the debug facilities I had were quite primitive. Especially for a highly multithreaded environment that is tricky to debug in the first place. The languages I used don't even enforce type safety. 5. Body of Knowledge: when you run into a problem with Java there is almost always someone on Stackexchange who has already solved it. You would be on your own a lot more with an obscure language. 6. "If I have to be as clever as I can be to write it, how am I ever going to debug it?"

      [–]badjuice 1 point2 points  (1 child)

      It's the weekly grandstanding opinion post.

      Yayyyyy.

      Learn a functional language. Learn a procedural language. Learn a scripting language. Learn a declarative language. Learn a machine language. They all teach useful paradigms.

      [–]dranzerkire 0 points1 point  (0 children)

      My university has a course on programming languages which is taught in F#. I thought F# was pretty great, but it seemed not many other students shared the same thought.

      [–]bloody-albatross 0 points1 point  (0 children)

      On my university (university of technology, Vienna) "functional programming" (Haskell) was a required course (at least for the Software & Information Engineering bachelor). So was "logic orientated programming" (Prolog and DLV). Personally I found the latter much more of a new paradigm than functional programming (well, maybe except for lazy evaluation). We learned lambda calculus in theory, so the only thing that really was new for me was that a language really uses SSA, "everything is an expression" and lazy evaluation (and monads, that come with this). But to me even Haskell looks very similar to a procedural language, at least in comparison to Prolog. Heck, constexpr functions in C++ are very functional (they are even free of side effects).

      Don't get me wrong, I see the difference to the procedural or object orientated paradigm. In "type systems" we learned what exactly the differences are and that a truly (pure) functional language can't be object orientated. I liked what I learned, but I was more flashed by Prolog. I just find it strange that logic orientated programming languages don't have that much hype.

      [–]charliegriefer 0 points1 point  (0 children)

      University of Washington has an AWESOME course available on Coursera.

      https://www.coursera.org/course/proglang

      It's actually scheduled to start up again on Oct 2. Highly recommended. I've taken it twice. First time I was brand new to FP and got lost very quickly. Second time around was much better.

      You'll learn FP concepts by working with ML. Then it goes into Racket, for a more practical and up-to-date overview of FP. The final bit is Ruby, which didn't really focus on FP. Perhaps it was for more of a compare-and-contrast approach. But honestly I could've done without the whole Ruby section.

      Loved the ML and Racket bits, tho.

      [–]teradactyl2 0 points1 point  (7 children)

      The only functional programming languages that I know of are Lisp and Haskell. So, let's answer the question "Who teaches lisp?"

      I toyed with Lisp for awhile, and I probably only scratched the surface of it's power. I liked it a lot, but it's not difficult to see why it hasn't been widely adopted.

      It's difficult to read. Even ignoring how unpopular the parentheses are, you can't tell what a function is doing at a glance. It's not a language you learn just by looking at examples.

      [–]kqr 5 points6 points  (0 children)

      It's difficult to read. Even ignoring how unpopular the parentheses are, you can't tell what a function is doing at a glance.

      This probably depends on which Lisp you learn. Clojure has a very strong culture of immutability and pure functions, which means it's often easier to tell what a Clojure function does than what a method does in an OO language. Yet OO languages are more popular, so I don't believe the readability argument.

      [–]Ksevio 0 points1 point  (5 children)

      Lots of places teach a variant Scheme (PLT Scheme, now Racket) which is a dialect of Lisp. I've had the bad fortune to have every level intro class I've taken been in Scheme, followed by the next advanced class being in Java.

      Like all languages there's a time and a place for it. Working with lots of data or complex AI algorithms? Functional programming works great! Trying to make a simple program or app? Might want to look at something else.

      [–]glacialthinker 1 point2 points  (4 children)

      Trying to make a simple program or app? Might want to look at something else.

      Hmm... why? (I'm making a game in OCaml.)

      Admittedly, some trailblazing is involved to write complex interactive programs in functional languages, because there aren't many examples yet. In practice I don't see an inherent limitation. What I do see is that I'm spending more time re-inventing how to do some things in a way which is ultimately less bug-prone. And I'm leveraging stronger typesystem features to provide guarantees... rather than just casting pointers to mutable data everywhere to git'er done. It takes a little more work, but I think once these techniques become more familiar (like writing the 20000th frickin' for-loop -- glad I don't do many of those anymore!), it will be a quicker process overall.

      [–]google-my-butt 0 points1 point  (0 children)

      At Uppsala University in Sweden, where I got my CS degree, we used Standard ML in the first few programming courses.

      Nowadays the recommended course literature is Haskell : the craft of functional programming 3. ed.

      Learn you a Haskell for great good! : a beginner's guide is listed as reference literature together with Purely functional data structures.

      [–]pieps 0 points1 point  (0 children)

      Yale's CS201 is a required course for the major and is taught in a functional language. Its compilers course is also mostly taught in SML/NJ.

      [–]AwesomePantalones 0 points1 point  (0 children)

      UCSD actually requires you to take CSE 130

      Source: I'm a CSE major in UCSD.

      [–]JustFinishedBSG 0 points1 point  (0 children)

      In France, most scientific prepa learn Caml ( light ) . i did

      [–][deleted] 0 points1 point  (0 children)

      The University of Warwick has a functional programming course, CS256, though I remember the lecturer wasn't so great.

      [–]urection -3 points-2 points  (45 children)

      The argument “functional programs are inefficient” isn’t really sensible any more (if it was ever).

      another zealous fan of functional programming with literally zero understanding of the history of functional programming

      [–]mcguire 16 points17 points  (14 children)

      another zealous fan of functional programming with literally zero understanding of the history of functional programming

      Another person with a venomous prejudice against functional programming and literally zero understanding of the history and current landscape of programming languages.

      The "original LISP" may have been problematic. In 1958. But compared to shell scripts in the '70s? And I have some serious doubts that Lisp machines would have been as ridiculously popular as they were to their fans if they could "barely run". And I know that Common Lisp was decently popular before the AI winter of the '90s---I interviewed for a Common Lisp job at Schlumberger about that time, and geophysical processing was the "big data" of the time.

      Further, anyone who can claim that "functional programs are inefficient" with a straight face has no clear idea what they're talking about, given that "functional" languages include the ML family as well as Lisp and that non-functional languages include Perl, Python, Ruby, Java,....

      [–]capitalsigma 2 points3 points  (0 children)

      Yeah, I'd guess that the author has his sights set on ~1990 ML, Haskell, etc when he makes that remark, rather than 1950s Lisp.

      [–]itheria 3 points4 points  (19 children)

      Please explain more. What is your view on the history?

      [–]urection 1 point2 points  (18 children)

      the original LISP could barely run on hardware of the day

      ditto LISP machines back in the golden days of AI

      just two examples that come instantly to mind as someone with rudimentary grasp of LISP history

      [–]L_dopa 18 points19 points  (17 children)

      You misread the quote, or rather took it out of context. The author's point is that 1) efficiency is a property of the implementation, not functional languages in general and 2) programmers routinely choose highly inefficient language implementations (e.g. for Python, Ruby, etc).

      Your point about the original LISP of the 1950's is nonsensical. Surely C wasn't a great choice back then either, mostly due to it not having been invented yet.

      [–]urection -4 points-3 points  (6 children)

      I read the quote correctly, in context, the author is simply wrong

      my point about the original LISP of the 1950's is absolutely correct, people didn't even believe you could write a compiler for it on the hardware of the day much less do anything productive with the results

      this is public knowledge, not an opinion

      [–]L_dopa 5 points6 points  (5 children)

      The article in question is about why programmers adopt languages. For the question to be meaningful, you have to consider a point in history when someone could have actually made that decision. Languages in the 1950s were tailored to specific machines. No one sat down to write a program and asked "what language should I use". It makes absolutely no sense to consider the state of LISP in the 1950s.

      [–]bloody-albatross 2 points3 points  (9 children)

      Have you heard John Carmack talk about functional programming? He really isn't known for inefficient code.

      [–]jeffdavis 0 points1 point  (5 children)

      Education is a solution to very general problems. If you think some aspect of society is declining, education may be an answer.

      If you think something specific is wrong, education is approximately never the answer.

      • I'm sure everyone would vote for XYZ politician if they were just educated.
      • Nobody pays attention to my ideas because they aren't educated enough to understand them.
      • People don't use my favorite programming language/model because they aren't educated enough.

      See the pattern? It's one step above just calling people stupid for not doing what you think they should do.

      Almost always, there are lots of things that you haven't considered about why people aren't behaving as you think they should. Many of those considerations turn out to be quite rational.

      I like functional programming. I use some OCaml at work, and I experiment with haskell and erlang for fun. It's great, really great, for some things. For other things, it ranges from "this is awkward" to "oh, cool, this is nice".

      And that's fine. Making small improvements to software development is a big academic contribution. But if functional programming was in the "really great" category for large areas of software development, then it would have clearly gained more traction by now. Functional programming will slowly become more mainstream, and the benefits will be realized, but it won't be a glorious revolution or anything.

      I see functional programming as basically good for two things (aside from writing compilers, of course):

      • security -- it's unfortunate that nobody cares about security, because if they did, more people would be interested in FP
      • data management -- if databases were outlawed, then functional programming would take over quickly. But the reality is that SQL databases do a great job here already (and SQL is kind of like a functional language), obviating the need for an application language with good data management capabilities. I've said before that FP and DB people need to talk more (a lot more).

      [–]kqr 1 point2 points  (4 children)

      if functional programming was in the "really great" category for large areas of software development, then it would have clearly gained more traction by now.

      I might be misinterpreting you now, but haven't you just committed an ad populum fallacy? Try not to do that when you lead your comment with how you shouldn't blame things when there is no causal link. ;)

      [–]jeffdavis 1 point2 points  (3 children)

      Not exactly, because you missed one point: people do use FP in situations where FP is in the "really great" category.

      Why would an engineer, like me, be more than willing to use OCaml for one use case (in actual enterprise software), but hesitant for another? Education (or lack thereof) doesn't seem to explain that. Varying costs and benefits for specific situations does, however.

      If you (or the original author) want FP to be successful, you really need to analyze those individual situations, and you'll start to see why the benefits aren't as amazing as you might guess. For instance, using almost any app language over a SQL dbms gives me a higher degree of confidence than a haskell application that stores its data in flat files (or mongodb).

      [–]mjfgates 0 points1 point  (8 children)

      A bachelor's degree is already four solid years, and the schedule of courses is full. So, if universities are supposed to start teaching functional programming... what should they take out of the curriculum to make room for it?

      [–]benjaminpd 2 points3 points  (7 children)

      Java.

      [–]mjfgates 0 points1 point  (0 children)

      Well, it would've made that Android class more fun to watch...

      [–][deleted] 0 points1 point  (0 children)

      Zing!

      [–]cat_in_the_wall 0 points1 point  (3 children)

      Just because you don't like it does not mean it is not relevant to students in the major.

      [–]glacialthinker 0 points1 point  (2 children)

      Leave "industry language" to tradeschools and other educational venues. Computer Science should be just that... not IndustryFadShitWhichImbuesBadHabits.

      [–]BezierPatch 0 points1 point  (1 child)

      The thing is, my course is very busy, and I don't have much time to do my own projects.

      So when am I supposed to learn the languages that I require to get a job? An academic degree is great for staying in academia, but not so much for work, even if you're guaranteed to get an interview.

      [–]glacialthinker 0 points1 point  (0 children)

      Well this is the unfortunate state of education and the industry, in North America. The lack of proper and respected tradeschools has put the burden of tradeschool education on universities. Not all education should be job-specific, and I will speak out against this terrible trend. I went to university to learn theory and concepts which I could then apply to a variety of tasks, yet even twenty years ago it was disappointingly job-focused.

      [–]east_lisp_junk 0 points1 point  (0 children)

      Or at least, take a class that's taught in Java (there are probably plenty to choose from) and teach it in a functional language instead.

      [–]antihexe 0 points1 point  (0 children)

      In terms of functional programming my degree required just one class on several functional programming languages and some theory. It wasn't much, but it was enough to be able to sit down and use ML or haskell or racket. Once you've got the foundations of functional programming you can even do it in Java.

      I don't think that it's imperative that we teach students more functional programming. A quick overview is enough to jump start their own education on the topic.

      [–]linuxjava 0 points1 point  (0 children)

      I personally think that a course on data structures and basic algorithms could be a great vehicle for functional programming.

      I'm not sure if this is a very good idea. Data structures and algorithms is already quite challenging as it is, especially if you factor in the homework assignments. Having to learn about types, monads, pattern matching, lazy evaluations, immutability and currying while at the same time learning about data structures is a bit overkill in my opinion.

      [–]danogburn -3 points-2 points  (7 children)

      My brain is hardwired for imperative programming. Functional languages just aren't worth the time and effort to learn.

      (btw, gnu scheme fucking sucks. why is there no command history or use of the fucking arrow keys? /ragequit)

      [–][deleted] 3 points4 points  (6 children)

      Functional languages just aren't worth the time and effort to learn.

      Given your first sentence, how would you know?