|
|
>> If you make a typo in a Haskell program, the program stops and says
>> "error: you tried to access the first element of an empty list". If you
>> make a typo in a C program, the program stops and says "error:
>> segmantation fault".
>
> And?
And if your program stops with an exception, you can catch and handle
it. If it segaults, AFAIK you can't do anything about it.
> Actually you can catch exceptions in most systems, and you can resolve
> the exact location of the crash using a debugger.
C and C++ have debuggers which are actually useable. I'll give you that one.
>> By contrast, the Haskell version doesn't use
>> any remotely advanced features of Haskell, just a few case expressions
>> with some basic pattern matching. No monads, no typeclasses, no
>> existential types, nothing. Just plain ordinary pattern matching.
>
> Because you wrote it so. The C++ version could also have been written to
> be as verbose and straightforward as possible. It's not like you *have* to
> write dense code.
No, BUT EVERYBODY DOES.
Nobody told this C++ programmer "hey, please write this in the most
complicated way possible". He just did, out of habit.
Personally, I don't have a problem with being able to incriment or
decriment a variable just by saying "x++" or whatever. It's a nice
shortcut. But when you reach the point of performing an assignment and
incriment at the same time... well, *I* certainly wouldn't write code
like that. I'd be forever having to double-check whether the incriment
happens before or after the assignment, and so on.
>> For me, the question is not how obscure it looks, but how difficult it
>> is to explain it.
>
> Many Haskell one-liners would probably take entire books to explain.
Haskell allows you to do clever and rather opaque things such as compute
a list of all the prime numbers in the universe in a one-liner, or
Pascal's triangle, or the Fibonacci numbers, or whatever. And, yes, it
takes some explaining to unravel.
*This* program, however, involves no such cleverness. Merely a few case
expressions. Aside from the unfamiliar syntax, there's really little
about it that's complex. No fancy tricks, no clever math, just a few
conditional tests and a couple of function calls.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|