[HN Gopher] Elements of Programming (2019)
       ___________________________________________________________________
        
       Elements of Programming (2019)
        
       Author : jabajabadu
       Score  : 112 points
       Date   : 2022-08-14 14:18 UTC (8 hours ago)
        
 (HTM) web link (elementsofprogramming.com)
 (TXT) w3m dump (elementsofprogramming.com)
        
       | florg wrote:
       | See also a previous discussion of the book:
       | https://news.ycombinator.com/item?id=20437347
        
       | keewee7 wrote:
       | This book proved that C++ code can be elegant and beautiful.
        
         | deltaonenine wrote:
        
         | thechao wrote:
         | It's probably best to understand it the other way around: Alex
         | had been designing generic programming libraries in assembly,
         | and tried to move to Ada -- but was stymied. Simplifying into a
         | just-so story: he approached Bjarne about adding a set of
         | features to C++ to allow Alex to directly express generic
         | programming in C++. That's what led to templates, etc.
        
       | _HMCB_ wrote:
       | Great find. Thanks.
        
       | sicp-enjoyer wrote:
       | This is a great book.
       | 
       | This wasn't mentioned in the past thread. Alex presents his ideas
       | in my forms. This one happens to be the most terse and
       | mathematical. That can be good, but I think "From Mathematics to
       | Generic Programming" is much more generally approachable.
       | 
       | One practical skill that's shown well in this book is writing
       | functions that solve the easiest or special cases, and then
       | layering those into general functions which ensure the
       | preconditions for applying one of those special cases are met. It
       | makes very readable code, and anytime a user of the code knows
       | they have a special case, they can assert it and use the special
       | one for some performance advantages.
        
         | Sirenos wrote:
         | I was a bit put off by the introductory chapter where he is
         | using a lot of nonstandard terms such as "abstract
         | species/genus" rather than the usual type theoretic treatment.
         | However, take that as the remark of an ignoramus.
        
           | sicp-enjoyer wrote:
           | Can you say more about why that put you off?
           | 
           | There are many different backgrounds from which to explore
           | these topics, and type theory is just one way. Also the
           | introduction isn't really trying to formalize computation
           | itself, but give mathematical tools for talking about
           | algorithms.
           | 
           | The abstract species/genus is probably inspired more by
           | Aristotle than CS topics.
        
         | agentwiggles wrote:
         | > writing functions that solve the easiest or special cases,
         | and then layering those into general functions
         | 
         | This is something I've been getting the hang of in my recent
         | playing around with Elixir. In Elixir, you can eliminate a lot
         | of conditional logic by utilizing pattern matching in function
         | signatures. Often, though not always, it's possible to write
         | each of your edge cases with a single function head. In
         | practice this usually looks like a few 1 or 2 line functions
         | for simple cases, and then one gnarly one that does whatever
         | checking you need to assure the right result.
         | 
         | It's also a great way to write recursive functions. You can
         | pattern match on the base case - say, an empty list - and then
         | put the recursive case or cases under separate function head.
         | 
         | It's a wonderfully fun and expressive language, although I have
         | been missing static types here and there, which
         | counterintuitively seem like they might eliminate a lot of
         | boilerplate from my code.
         | 
         | Highly recommended playground for the language geek.
        
         | jabajabadu wrote:
         | Thank you for recommending "From Mathematics to Generic
         | Programming"! I wasn't aware of this book.
        
       ___________________________________________________________________
       (page generated 2022-08-14 23:01 UTC)