News for hackers. Stuff that matters.
Re:The Flub Paradox by tempodox on Monday June 08, 2015 @08:13AM (#9678439)
Those are very keen observations and not commonly voiced in that combination. I can't remember the last time I read an article about the development of PLs that I agreed so much with.

If I had to venture a guess about future development in PLs, there would only be one pattern that I find reliable enough: In a rough birds eye perspective, PLs have moved from hardware-specific things handling mutable state to more formally defined beasts fed by mathematical concepts. That's one trend I expect to continue, but then also not ad infinitum. In my view, Haskell is a good example of how you can overdo it, with the best intentions: concepts that are beautiful and frictionless in pure math become a cumbersome burden and an impractical cognitive load when translated too directly into a PL. I want more math in PLs, but I feel we haven't found a good balance yet. Maybe this turns out to be a moving target, too.

There are two languages I expect to keep their (niche) places for the foreseeable future: C and Lisp. Both are such a peculiar mix of properties that they are incredibly hard to beat in their respective domains. Maybe the same goes for Ada and Java, I wouldn't want to do any injustice :)

Re:The Flub Paradox by pron on Monday June 08, 2015 @09:00AM (#9678675)
There are a couple of things I disagree with.

First, you are lumping together trends in academia with trends in the industry, and the two are not always in tandem, though they certainly influence one another. For example, Go, a language that certainly goes against this trend, is gaining popularity much faster than any academic or academically-influenced languages (of course, it's easy to grow fast when you're small, but it's more academically inspired languages are just as small). This mixing of the domains which in reality is quite complex is also apparent in your examples. C is one of the most popular languages in use, and has been for a few decades; Lisps have been around even longer and has never broken beyond around, say 1% of production projects (except maybe for a very short while in the eighties).

Second, you say "I want more math in PLs" when referencing Haskell. While it is true that pure-FP, because of its relationship to some types of logic, lets you prove some properties about your code in the code itself, that does not make it any more mathematical than other languages and other approaches. For example (and I give this example often, but only because I'm really impressed by that language), Esterel, a language designed in the eighties is an imperative language with lots and lots of global side effects, yet it allows you to verify its correctness absolutely, and you don't even need to write the proof yourself (it verifies temporal properties that are especially hard to prove using PFP). Esterel and languages (mostly graphical languages) inspired by it have been used by the industry orders of magnitude more than PFP languages for domains where correctness is crucial. That PFP allows you to write some proofs in code does not mean that there aren't better ways to verify programs mathematically. PFP is the answer if what you're asking for is more second-order logic in your PL; it's just one of many if you're just asking for more math (in fact, it's just one of many even if you want more interesting type systems).

Also, it's hard to trace influences, but I believe that the focus on immutability that is finding its way into more and more languages is actually inspired by Erlang and later Clojure, two languages that have little to do with PFP, and a lot to do with the design of multi-core and distributed systems. It was not the current academic trend of pursuing the Curry-Howard correspondence as a software verification technique, but an industry solution for the problem of handling concurrency.

Re:The Flub Paradox by vanderZwan on Monday June 08, 2015 @11:31AM (#9679697)
For those who want to see what Esterel is all about, Céu is a modern language inspired by it (or at least its synchronous concurrency approach).

http://ceu-lang.org/

Re:The Flub Paradox by wz1000 on Monday June 08, 2015 @10:02AM (#9679080)
> Haskell is a good example of how you can overdo it, with the best intentions: concepts that are beautiful and frictionless in pure math become a cumbersome burden and an impractical cognitive load when translated too directly into a PL.

Why do you say this?

Sure, Haskell is radically different from most programming languages out there, even ones that claim to be 'functional'. But that does not mean it is 'overdone'.

With traditional imperative languages, you have years of experience behind you. Anytime you see a problem, you have those years of experience to guide you in choosing an appropriate way of solving it. All those idioms that you learn over decades of programming add up.

The problem with Haskell is that because it is so radically different, all that experience is largely useless. You start again from scratch. Remember the first time you learnt how to drive. It was confusing and you paid a lot of attention on every action and every turn. Eventually, with experience, it becomes instinctive and you don't even think about it under normal circumstances. Now, imagine that you wake up tomorrow, with all of that instinct gone. It would be utterly disorienting and scary.

Now, time for an anecdote: I've spent the bulk of the past one and a half years learning Haskell, with a couple of years of experience with other, partly 'functional' languages like Scheme and Python. In the beginning, I was extremely confused, and whenever I came across a problem, I had no idea of how to express myself in Haskell. This was completely alien to me. No other language I had come across had left me so lost.

However, in a few months, I came to learn functional idioms and began to grasp the language. What really appealed to me was how expressive the language was once you knew how to "speak" it. If you have to become 'fluent' in anything, you have use and think in it repeatedly. Eventually, it becomes second nature.

Because of how so many things in Haskell are based on solid mathematical foundations, it is extremely easy to generalize and most importantly, compose. Haskellers tend to draw a lot of inspiration from category theory(which I've also taken a liking too). The essence of the concept of "composition" is a category. It often astounds me how simple, generic functions and combinators can be strung together to form complex programs. I haven't come across this level of generality and composability in any other programming language.

Programming in Haskell, once you learn to "speak" it, reduces cognitive burden by a huge margin. Often, you deal with concepts so general there is only one way to implement them. You don't have to care about details of the underlying representation, because the number of representations is extremely vast. This is initially extremely disconcerting, and is probably the reason why people face so many problems with monads. The concept is so general, and has no single "concrete representation" that would make you grok it. When you ask "what is a monad?", people answer in a vast variety of ways. In truth, the only correct way to describe a monad is the monad laws. Anything that follows the monad laws is a monad. Those three laws are it. Newcomers are often astounded by that. How can that be it? The laws don't really say anything! They can't say much because they can be used to describe a vast number of things, from IO to exception handling to parallelism to non determinism. When you write code for a generic monad, you don't care about any of those detail, and what the monad you are dealing with actually is. All that cognitive burden is thrown away. In the beginning, it seems scary, but after a while I realised how liberating it actually was.

Re:The Flub Paradox by tempodox on Tuesday June 09, 2015 @07:38AM (#9685231)
> You start again from scratch.

You describe my situation with Haskell quite exactly, and I agree you have good points. The non-monad parts of Haskell are, after all, the most beautiful PL I've ever seen, and that puts me between a rock and a hard place.

My difficulty with monads comes from the very reason why they're so powerful: You can do anything with them, but at the cost of the monadic form taking center stage and the original problem's form getting almost lost, scattered across the functions implementing the monad laws. Maybe that's not so bad, but I haven't adjusted my thought process to that yet.

Re:The Flub Paradox by wz1000 on Wednesday June 10, 2015 @09:12AM (#9691841)
For me, monads are just as beautiful as any other part of the language. Like almost everything new, you just have to work with them for some time, until you build intuition for the underlying mathematical object and everything just "clicks".
Re:The Flub Paradox by codygman on Tuesday June 09, 2015 @05:27AM (#9684800)
> In my view, Haskell is a good example of how you can overdo it, with the best intentions: concepts that are beautiful and frictionless in pure math become a cumbersome burden and an impractical cognitive load when translated too directly into a PL.

Can you give some examples of concepts that are a cumbersome burden and cause impractical cognitive load in Haskell? Perhaps some example code?

Re:The Flub Paradox by tempodox on Tuesday June 09, 2015 @07:53AM (#9685305)
Partially, I can explain by quoting myself from another answer:

My difficulty with monads comes from the very reason why they're so powerful: You can do anything with them, but at the cost of the monadic form taking center stage and the original problem's form getting almost lost, scattered across the functions implementing the monad laws. Maybe that's not so bad, but I haven't adjusted my thought process to that yet.

Or try to temporarily throw some debug logging into a deeply nested function that doesn't have the IO monad in its return type. Maybe that's the wrong type of thinking for this language, but there doesn't seem to be a “howto” on what to do instead...

Re:The Flub Paradox by michaelochurch on Monday June 08, 2015 @10:17AM (#9679199)
Haskell isn't "overdone". It's extremely principled and requires that, for example, you put the existence of stateful effects (e.g. I/O) in the type system. It requires you to specify state (to a degree, and with escape hatches); it doesn't eliminate it.

Haskell isn't that much of an investment when you consider what is gained. See, learning any new code base takes 3-6 months, and if the code is great, you learn a lot. If the code is garbage, well... perhaps you learn what not to do. Compared to the slog of learning a new corporate codebase, the effort involved in learning Haskell isn't that much... and the hope with Haskell is that the next software project you write won't be unmanageable... and I think that even average-case Haskell realizes it. (I focus on the average case because, of course, you can write shitty code in any language and you can write good code in any language, but languages differ in what tends to happen on average.)

Re:The Flub Paradox by _dps on Monday June 08, 2015 @02:09PM (#9680931)
I would be interested in your thoughts here because Haskell has always seemed, theoretically, a great fit for me but it has never panned out in practice.

I believe you and I have a common-enough mental framework (theoretical-leaning applied math Ph.D., happy to hold forth on e.g. algebraic geometry, information theory, nonlinear dynamical systems etc.). I look at Haskell and it certainly feels clean and beautiful like all the mathematics that I love. But then I try to use it and, objectively, I get less done (even though I knew what an endofunctor was before even seeing Haskell!).

My longest stretch of trying to use Haskell every day was about 3 months at which point I was still substantially less productive than my preferred mix of C/Python/Lua (I mainly do heavy-lifting numerical work coupled with low-latency server designs). I also feel like I get more done in OCaml.

So, you being someone whom I identify as similar in skills to myself, I ask you: what gives? :-)

Re:The Flub Paradox by codygman on Monday June 08, 2015 @02:47PM (#9681298)
I've never taken a calculus class and I'm very productive in Haskell. Maybe knowing all of the applied Math and that there is a better solution available in Haskell keeps you from being productive?

I take the route of solving problems the first (or second) way I come up with, then take advantage of how easy it is to refactor Haskell code when I have a better solution later.

For instance I didn't understand Monads too well while writing my first Haskell program and just did everything in continuation passing style.

Re:The Flub Paradox by marcosdumay on Monday June 08, 2015 @04:28PM (#9682148)
Well, depending on your problems, Haskell may simply not be the correct answer. It shines complex behavior for example, but "numerical work" normally means simple behavior (but highly optimized), and I'd be wary of it on low latency applications.

Haskell is powerful, but won't solve all the problems on the world.

Re:The Flub Paradox by _dps on Monday June 08, 2015 @05:10PM (#9682442)
This is an excellent point and maybe you gave me a good compact summary of the situation. Perhaps you can tell me if you agree.

The kind of work I do tends to involve a small number of low-variability data types, and the ROI on complex logic (w.r.t. computational performance) has to be very high for it to be accepted into a project. We don't shy away from complex logic, but we do have a high hurdle for it to cross before it becomes a net win.

In contrast, Haskell is perhaps best for large numbers of high-variability datatypes where complex logic is inevitable, regardless of performance costs. And it helps precisely by encoding as much of the complex logic (e.g. safety rules) into the variability and expressiveness of the type system.

I guess all that may be obvious, in hindsight. But I think your comment helped me crystallize the distinction. So, thanks :)

Re:The Flub Paradox by marcosdumay on Tuesday June 09, 2015 @01:37PM (#9687304)
That's what I was trying to say (and much more precise).

Yet, I'd look at codygman's answer. It's a library that tries to improve memory locality by using more complex logic, and hides everything under Haskell abstractions so it's easy to use.

I'm not currently working on this area, so I can't really tell what it's good for.

Re:The Flub Paradox by codygman on Tuesday June 09, 2015 @05:20AM (#9684763)
> Well, depending on your problems, Haskell may simply not be the correct answer. It shines complex behavior for example, but "numerical work" normally means simple behavior (but highly optimized)

To give a rebuttal to Haskell not being good for "numerical work", you might be interested in this pre-alpha numerics library:

https://github.com/wellposed/numerical#performance-faq

I'm tempted to agree with you re: low latency, then I run across stuff like this:

https://github.com/tomahawkins/atom

I believe it (or a similar library) are used in quite a few of a certain companies (or multiples) flagship applications, though I can't recall the details.

Re:The Flub Paradox by michaelochurch on Monday June 08, 2015 @03:49PM (#9681828)
Haskell took me a while, because there weren't many great resources on how to write many kinds of "real" code in Haskell. The quality of material is getting steadily better.

I think you've got a good 6-12 months before Haskell is more productive for you than OCaml or a C/Python/Lua stack. If you're coming from Java, you're more productive than you were at 1 month in Haskell (you still know very little Haskell, but you're pwning your former Java-toting self)... but in your case, you already know quite a few high-level languages. So it's not surprising that you get less done in a language that forces you to contend with monads (which aren't as hard as they're made out to be, but they're one more new concept) just to have state. If you're coming from Java, you're more productive in Haskell almost instantaneously, before you really even know it. If you're coming from Python, you're less productive day-by-day because the compiler keeps burning you, but you find long-term development going faster due to fewer code breakages. If you're coming from Ocaml... the short answer is that they're both great languages with more in common than not (although I prefer Haskell) so it's not surprising that it takes a while to get up to your prior speed (because your prior speed is so much higher than that of someone from Java).

Real World Haskell is a good book, though a bit slow and dated. Learn You a Haskell is a decent intro book but it has some gaps. I'm working on a Summer Haskell Course at my company and will be publishing the slides. And Chris Allen recommends the CS 194 course that Penn offers (you can find it online). Resources are out there.

Re:The Flub Paradox by tempodox on Tuesday June 09, 2015 @08:05AM (#9685352)
I think you've got a good 6-12 months before Haskell is more productive for you than OCaml or a C/Python/Lua stack.

Though merely anecdotal, that data point eases my mind a bit. I come from Assembler, Lisp, C, OCaml, so maybe my difficulties are par for the course.

Re:The Flub Paradox by Dewie3 on Monday June 08, 2015 @09:02AM (#9678688)
Haskell is a research language with lazy evaluation. Also with a lot of fun type-stuff. I guess you could make a language which tries to be immediately pragmatic. But it is more focused to try to focus on a relatively small area and see how far you can push those concepts.

Haskell is just one datapoint. Are PLs moving in one uniform direction, upwards to some kind of "ideal" state? Arguably not until we manage to collapse all the myriad aspects of both programming languages and things they try to solve, and within which constraints (such as those pesky limited digital computers).

Is "math" some formalism that is ideally totally divorced from hardware? Then what about formalisms that try to model some kind of computation? What about linear logic and being able to model the disciplined handling of resources such as memory and handles? Is that incompatible with pure functional programming? Not really, since effectful functional programming is a thing, and effects that are encapsulated (such as mutating a local variable inside a pure function) isn't an effect from the view of the caller of the pure function. What about using types to easily[1] declare the layout of memory, such as using SoA over AoS? I'm sure I've seen some paper on that.

[1] Or at least more easily and less ad-hoc than what you typically would do in C/++.

Re:The Flub Paradox by quchen on Monday June 08, 2015 @11:53AM (#9679860)
> Haskell is a research language

The language standard is from 1998, and is mostly unchanged since then. We now have Haskell 2010 and quite a few compiler extensions, but none of the experimental ones are necessary to be used in production. The researchy ones have their benefits, but they also make it pretty clear that they are things not to be toyed with lightly in production code.