Live data from Hacker News

Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

info.ucl.ac.be

51–60 of 167 posts

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#51

Earlier quoted context omitted.

> exceptions > simplifying Erm, no. Some consequences: non-obvious control flow, RAII, constructors, move semantics, exception safety, efficiency, stack unwinding... A better way to deal with the "problem" of unchecked error codes is to have the compiler check that something happens to the result value. This is what Chandler Carruth suggests. An even better (but orthogonal) way is to structure the code so it does onl…

compared to error codes, exceptions are simpler IMO. Many issues with exceptions come from using them in non-exceptional circumstances, i.e. for control flow.

Case in point: Python’s StopIteration exception, which is raised to indicate iterator exhaustion. A lot of efficiency can be gained by not invoking Python’s heavy exception handling machinery for this.

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#52
> We end our discussion of inheritance with a cautionary tale. In the 1980s, a very large multinational company initiated an ambitious project based on object-oriented programming. Despite a budget of several billion dollars, the project failed miserably. One of the principal reasons for this failure was a wrong use of inheritance.

Who did that, exactly?

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#53

> We end our discussion of inheritance with a cautionary tale. In the 1980s, a very large multinational company initiated an ambitious project based on object-oriented programming. Despite a budget of several billion dollars, the project failed miserably. One of the principal reasons for this failure was a wrong use of inheritance. Who did that, exactly?

I would have guessed Plan 9 just from the timing, but I'm not sure the failure there was due to the wrong use of inheritance.

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#54
post #46

Earlier quoted context omitted.

What is relevant is that lambda calculus can be expressed. Everything else are just variations on "What is FP" and sugar coating.

> What is relevant is that lambda calculus can be expressed. That's a criterion that's so broad as to be almost meaningless, though. The lambda calculus can be expressed in any Turing-complete language. I wouldn't personally consider a language to support a paradigm unless programming in that paradigm feels natural in that language. Java supports using a few functional techniques. The experience of trying to write in…

Thing is, what does actually "The experience of trying to write in a truly functional style" mean in practice.

FP Lisp/Scheme, FP ML, FP Haskell/Miranda, FP Idris, FP Scala, FP Kotlin, FP OCaml, FP ATS, FP .... ?

All of them express different views of what Functional Programming is supposed to be like.

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#55
post #26

Earlier quoted context omitted.

> Exceptions imply a temporal coupling from error occurrence to error handling. Could you expand on this? I understood your statement as "Exceptions sort-of force you to handle an error the moment it occurs", but I'm having trouble seeing why this would be specific to exceptions and not the case with other error handling solutions. (I don't mean to sound like a big exception-defender – I prefer ML/Rust-style Result t…

A rather odd example with Result type systems: Say you have a function that returns the results of three other functions together in a tuple and the first one errors. The other two can still run and their result can be returned in the tuple along with an Error for the first function.

Ah, so using Result types you can return

  `(Optional, Optional, Optional)`
– each can fail or succeed independently. But you can't do that if you're using exceptions to signal errors – it's like returning

  `Optional`
, you get either all the results or nothing. Good example, thanks!

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#56
post #53

> We end our discussion of inheritance with a cautionary tale. In the 1980s, a very large multinational company initiated an ambitious project based on object-oriented programming. Despite a budget of several billion dollars, the project failed miserably. One of the principal reasons for this failure was a wrong use of inheritance. Who did that, exactly?

I would have guessed Plan 9 just from the timing, but I'm not sure the failure there was due to the wrong use of inheritance.

That most certainly wasn't the case. The source for Plan9 is pretty plainly not hierarchical OOP.

Plus, the failure of Plan 9 was more an early 90s thing.

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#57
I have read CTM, the author's book. He did in fact dislike the word "paradigm" and prefered "computation model" instead.

A model is a set of concepts. A concept is an orthogonal language feature, like closures, concurrency, explicit state (which he now calls named state), exceptions, etc.

His approach is not so much that you should select one language that supports a paradigm that seems the most suitable for a given project. Rather, what he advocates is that you should use a language that supports multiple cleanly separated concepts (close to what is called multiparadigm), and then you select the simplest set of concepts for each program component.

This is the principle of least expresiveness, you should choose the simplest model (simple meaning that it is easy to reason about and to get right) that keeps the code natural (meaning there is little code unrelated to the problem at hand, little plumbing).

Each model has an associated set of programming techniques, like accumulators for FP or transactions for stateful concurrency.

It is possible to mix and match components that are written in different models by using impedance matching, which consists of creating an abstraction in the more expressive model that wraps the other component. An example would be a serializer, which allows you to plug a non concurrent component in concurrent program.

Basically, you should use FP as much as you can, but you can't if your program needs, say, visible non-determinism, like a server in a client-server application. But then you can add just one concept, ports, to the declarative concurrent model, and you have a new model that allows a whole constellation of new programming techniques, the concurrent message passing model, Erlang-like. The non-determinism in this model is restricted to the ports, the only place where it's required, the rest of the program can still be functional.

Other situations where FP might get stretched are when modularity or performance are a priority.

This book helped me realize the whole FP vs OO debate is sterile, the ideal is to have a language that allows you to use FP in a natural way, and switch to, say, OO, in a natural way in some cases.

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#58

> We end our discussion of inheritance with a cautionary tale. In the 1980s, a very large multinational company initiated an ambitious project based on object-oriented programming. Despite a budget of several billion dollars, the project failed miserably. One of the principal reasons for this failure was a wrong use of inheritance. Who did that, exactly?

"Two main errors were committed:

"• Violating the substitution principle. A procedure that worked with objects of a class no longer worked with objects of a subclass. As a result, many almost-identical procedures needed to be written.

"• Using subclasses to mask bugs. Instead of correcting bugs, subclasses were created to mask bugs, i.e., to test for and handle those cases where the bugs occurred. As a result, the class hierarchy was very deep, complicated, slow, and filled with bugs."

That's a good question. I can think of several candidates, but none that match the specific problems.

Re: Programming Paradigms for Dummies: What Every Programmer Should Know (2009) [pdf]

#59
post #53

Earlier quoted context omitted.

I would have guessed Plan 9 just from the timing, but I'm not sure the failure there was due to the wrong use of inheritance.

That most certainly wasn't the case. The source for Plan9 is pretty plainly not hierarchical OOP. Plus, the failure of Plan 9 was more an early 90s thing.

And I suspect the budget never got near billions of dollars. Plan 9 was a research project.
Post reply on HN