Slashdot Mirror


OCaml For the Masses

CowboyRobot writes "Yaron Minsky of Jane Street argues that the time has come for statically-typed functional languages like OCaml and Haskell. He cites many reasons and illustrates what he says is the most important, concision: 'The importance of concision is clear: other things being equal, shorter code is easier to read, easier to write, and easier to maintain.'"

36 of 338 comments (clear)

  1. haskell for the masses? sure, but only... by tulcod · · Score: 4, Insightful

    haskell for "the masses" is possible as soon as "the masses" has a degree in mathematics. java and php are copy-and-paste languages, functional languages simply take more thinking to compile at all, and i think many programmers are not prepared to do that to the required degree, although i'd love to be proved wrong.

    1. Re:haskell for the masses? sure, but only... by rvw · · Score: 2

      I'm sorry to say that you're mistaken. Please read up some more on how and for what people use Haskell, before saying such things (without proof).

      If I enter "Haskell" in Monsterboard, I get zero results. You probably refer to academic work, but where in the commercial world is Haskell used?

    2. Re:haskell for the masses? sure, but only... by gstoddart · · Score: 2, Funny

      See, as an old school user of vi, emacs doesn't make the case for a functional language being useful.

      In fact, quite the opposite. :-P

      --
      Lost at C:>. Found at C.
    3. Re:haskell for the masses? sure, but only... by gilleain · · Score: 2

      I'm sorry to say that you're mistaken. Please read up some more on how and for what people use Haskell, before saying such things (without proof).

      Oh please no - that proof ... it doesn't have to be written in Haskell, does it?

    4. Re:haskell for the masses? sure, but only... by Darinbob · · Score: 2

      Lisp is used for just about everything possible. Compilers, editors, games, window systems, etc. Lisp isn't really in the same category as pure functional languages like Haskell. But pure functional languages have been used to do a whole lot of larger applications as well, editors, compilers, etc.

      The big problem is that in a lot of programs you need more than just the pure functions; you need I/O and other side-effects. Functional languages have these but they often feel like odd bits tacked on that corrupt the simple language rules.

    5. Re:haskell for the masses? sure, but only... by HiThere · · Score: 3, Insightful

      You misunderstand thing. General purpose languages, such as the C or Algol family (which includes, among others Java, Python, and Ruby) do, indeed, include concepts from functional languages. But they don't RESTRICT you to those concepts. It's the insistence that everything be unchanging that is the weakness in the purely functional languages. The Scheme family is the only group of that to have any measurable use. (Note that Lisp is NOT a functional language, even though the concept originated via a subset of Lisp.)

      There's much to be said for having the ability to have invariant elements in functions. There's very little in having the requirement that everything be that way. Note that many existing languages that have invariant strings ALSO have mutable strings. Java to name just the most popular example. So by all means allow functions to declare their values invariant. This allows lots of different kinds of optimization. But don't insist that all functions do so. And definitely don't insist that everything be invariant.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    6. Re:haskell for the masses? sure, but only... by shutdown+-p+now · · Score: 2

      It's not a pure functional language, but most pragmatic FP languages aren't pure. OCaml is not pure, either.

      I'll grant you that F#'s object model (taken wholesale from .NET) is less suitable for this type of language than OCaml's one, but aside from that, what are the irritating constraints?

    7. Re:haskell for the masses? sure, but only... by martin-boundary · · Score: 2

      Be specific man! There as in "come across this thread" or there as in "irritated"? Really, the next time you make a comment like that, is it too much to ask to bind the referenced variable that represents your meaning? Closures! Closures!

    8. Re:haskell for the masses? sure, but only... by fusiongyro · · Score: 2

      You missed the part about the author being at Jane Street Capital?

    9. Re:haskell for the masses? sure, but only... by AuMatar · · Score: 2

      So if it's simple in an imperative approach but difficult in a functional one- why the fuck are you using a functional one to begin with?

      That's why no functional language has ever been successful. It's a beautiful model that just doesn't work. And no number of epicycles like monads will ever fix the problem that you're off on your base assumptions.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    10. Re:haskell for the masses? sure, but only... by Bill,+Shooter+of+Bul · · Score: 2

      Yup, Haskell shops don't post job openings, they head hunt.

      --
      Well.. maybe. Or Maybe not. But Definitely not sort of.
  2. They're not equal though... by Anonymous Coward · · Score: 5, Insightful

    The importance of concision is clear: other things being equal, shorter code is easier to read, easier to write, and easier to maintain.

    All other things are not equal though, are they? Procedural programming is easier for humans to understand: most of us do no not think in a way that maps easily to functional programming.

    1. Re:They're not equal though... by Anonymous Coward · · Score: 3, Insightful

      Or most of us didn't learn to program in a functional language, so our brains are used to thinking imperatively. Or were you born understanding code?

    2. Re:They're not equal though... by m50d · · Score: 2

      All other things are not equal though, are they? Procedural programming is easier for humans to understand: most of us do no not think in a way that maps easily to functional programming.

      Quite the opposite actually, and that's the real advantage of functional programming; I don't think "do this to the first item in the list, then do it to the second, then...", I think "do this to every item in the list". Procedural was popular because it corresponded to what the computer was doing, and in the early days knowing exactly what the computer was doing was very important, but functional maps much more closely to human reasoning.

      --
      I am trolling
    3. Re:They're not equal though... by Waffle+Iron · · Score: 3, Insightful

      Or most of us didn't learn to program in a functional language, so our brains are used to thinking imperatively. Or were you born understanding code?

      Our brains think imperatively because life is imperative.

      Imperative languages dominate computing because the real world is imperative.

    4. Re:They're not equal though... by Waffle+Iron · · Score: 3, Insightful

      god no, why do you asset that life is imperative?

      Because each of us exists as one location in 4-dimensional spacetime. Our existence is a single thread moving uniformly forward through time, attending to one task at a time. Almost nothing in the real wold is stateless or immutable. Our brains evolved to deal with this reality.

      but apart, remember programming isn't something natural of the human, is learned.

      When I looked at the first BASIC program listing I encountered almost 40 years ago, I immediately understood what it meant. I didn't have to learn anything to relate to it. It's a list of steps to take, just like we do every day in the physical world.

      Most CS students struggle for a long time just to get a grasp on recursion, much less the various high-powered concepts from functional languages.

  3. Re:Give me a call when... by tuffy · · Score: 2, Informative

    Both Ocaml and Haskell can compile directly to native machine code and aren't tied to decrepit virtual machines. In particular, Haskell's compiler is written in Haskell for optimal bootstrappy fun.

    --

    Ita erat quando hic adveni.

  4. Re:Give me a call when... by Anonymous Coward · · Score: 2, Informative

    You mean like right now? Haskell's pretty mature, and it's been able to compile to native code for years. It's pretty straight forward to talk to C (the universal ABI) with Haskell (well, as straight forward as anything is in Haskell).

    OCaml has been mature for nearly a decade, by the way. Without the success it's had, languages such as Haskell and F# wouldn't be around. It also can compile to native code, and has been able to since inception.

    PS, the .NET VM isn't really decrepit, it's much more performant than the JVM is. Sadly, mono isn't nearly as mature as the actual .NET virtual machine.

  5. Re:Give me a call when... by Nimatek · · Score: 2

    They compile to native machine code, FYI.

  6. Re:It's all about state by Laz10 · · Score: 2

    Take a look at Scala collections.

    Scala lists look and feel immutable, but under the covers they are really mutable to remain more performant.

  7. Re:Give me a call when... by Vanders · · Score: 2

    the "platform" ABI on e.g. UNIX is meant for C programs

    Huh? No it isn't. The API may most often be expressed in C, but the ABI is language agnostic.

    keep in mind the only types in C are bytes, half-words, words, double words

    Huh? The C standard doesn't define anything in terms of "bytes", "half-words" or "double words". In fact those terms are largely meaningless in the context of C: the standard offers very few guarantees about the width and endianess of it's native types. C didn't even gain portable fixed-width types until C99.

  8. Re:Needs platform adoption first. by Laz10 · · Score: 3, Interesting

    This is why I think Scala will succeed.

    Scala has all the advantages that the article mentions AND you can integrate and reuse your old Java or .NET code and libraries.

    It's there. The tooling doesn't suck half bad anymore. The world just needs to find out.

    I personally think that Scala will win over the 10% best Java programmers as soon as the tooling is comparable to Javas.
    And that might happen within the next 1-2 years.

  9. Practicality drives use by grimmjeeper · · Score: 2, Interesting

    'The importance of concision is clear: other things being equal, shorter code is easier to read, easier to write, and easier to maintain.'

    But there's the rub. Other things are not equal. Functional languages require the developer to approach problems with an entirely different mindset. There is a steep learning curve to really understand how they work. And I'm not talking about just the syntax. Functional languages are fundamentally different than procedural languages. Truly understanding how they work requires a lot more brainpower than procedural languages.

    While it's admirable to espouse what you see to be a more elegant and "better" solution, you need to be pragmatic. Getting the millions of software developers in the world to put the effort to completely change their way of thinking just isn't going to happen. The cost/benefit ratio is questionable at best, given that a lot of people could train for a long time and still have difficulty with the basic concepts of functional languages.

    Procedural languages are the norm because they're a lot simpler. Procedural languages (including "C with classes" and the like that masquerade for OOP/OOD) are useful to many more people simply because there is less to understand about how they work. It's easier for people to approach problem solution in a procedural way than it is for them to think about it functionally. And that's why functional languages, no matter how elegant or "great" they may be, will never really break into the mainstream.

    1. Re:Practicality drives use by mbone · · Score: 4, Insightful

      'The importance of concision is clear: other things being equal, shorter code is easier to read, easier to write, and easier to maintain.'

      That was the idea behind APL. You could do amazing things in one line of code. I never, however, knew anyone who used it who thought it was easier to read, easier to write or easier to maintain.

  10. Re:Two line summary of TFA by Anonymous Coward · · Score: 2, Informative

    I have the perfect hammer.

    Would that be the C family of languages used all over the place?

  11. Re:Another functional programming fan by dkleinsc · · Score: 5, Interesting

    My favorite code to read is OOP stuff written by coders who understand and make use of functional programming concepts. They know how to write things that are stateless when that makes sense, and use state in an appropriate manner when that makes sense.

    And yes, by all means use it when appropriate. But don't think that Lisp is always the right language for scripting your text editor (dodges blow from Emacs partisan).

    --
    I am officially gone from /. Long live http://www.soylentnews.com/
  12. Re:Give me a call when... by Korin43 · · Score: 2

    Glascow Haskell Compiler:

    GHC compiles Haskell code either directly to native code or using LLVM as a back-end. GHC can also generate C code as an intermediate target for porting to new platforms. The interactive environment compiles Haskell to bytecode, and supports execution of mixed bytecode/compiled programs.

  13. Re:Shorter code? by shmlco · · Score: 4, Insightful

    If shorter, more concise code was always better, we'd have switched to APL years ago.

    We didn't.

    --
    Any sect, cult, or religion will legislate its creed into law if it acquires the political power to do so.
  14. Concision? by digitig · · Score: 2

    APL is very concise and is famously easy to read and maintain. Oh, wait...

    --
    Quidnam Latine loqui modo coepi?
  15. Re:Shorter code? by Anonymous Coward · · Score: 2, Insightful

    True, so on one end you have bloated, verbose languages like Java and Cobol and on the other end you have terse, unreadable languages like Perl and APL. So the key is finding the right balance. Ideally you want a language which is both readable and expressible. One that encourages reduction of repetitious code. One that allows you to build the abstractions to best express your intent as a programmer in a maintainable way.

    I'm of the opinion that C syntax is not best suited for this. Lisp is better, but everyone screams about the parens despite the fact that you have curly braces, parens, square braces and semicolons all over the place in the C languages.

  16. Use F# by alphabetsoup · · Score: 2, Interesting

    F# is essentially OCaml for .Net, so you get the full access to the .Net library. Also the best thing about F#, in my opinion, is since it is a .Net language, you can mix and match it with C#. So you can use functional approach for most part of your program, yet drop to C# when you require.

  17. Good news! by toby · · Score: 2, Interesting

    We have found the problem with the software business.

    Bad news: It's you and your 100,000,000 ignorant & unwilling to learn clones.

    --
    you had me at #!
  18. Any studies to back up the "small code" thesis by istartedi · · Score: 2

    Are there any studies to back up the "smaller code is better" thesis? My own experience and that of many others leads us to diasgree; but our anecdote and/or sentiment is no better than theirs.

    1. Quantify terseness.
    2. Assign terseness value to language.
    3. Quantify qualities of interest (maintainability, etc.).
    4. ???
    5. Science!

    --
    For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
    1. Re:Any studies to back up the "small code" thesis by istartedi · · Score: 2

      That's interesting but I think the question is more along the lines of whether or not

      (c1 ? f1 : f2) , (c2 ? f3 : f4)

      is more or less error prone than the if-else example they used. Imagine a hypothetical terseness maximizing language where the () may be ommitted if there are no arguments

      Actually you don't have to imagine that. The code would be more compact in point-free style which doesn't require the parens (like Forth):

      f1 f2 c1 if drop f3 f4 c2 if drop

      Not sure if that's valid Forth; but you get the idea. Once again, very compact. Understandable? Less error prone? The cyclomatic complexity is the same; but the programmer has to manage a stack in their head. I think that would be more error prone.

      --
      For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
  19. Data vs algorithm by Hentes · · Score: 2

    Functional languages are good for inplementing algorithms and imperative languages are good for handling data. It happens that in most real-life situations we need the latter.

  20. Re:To prove its usefullness, by chromas · · Score: 2

    First ghost!