How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?

Chris Angelico rosuav at gmail.com
Mon Aug 10 16:14:52 EDT 2020


On Tue, Aug 11, 2020 at 5:48 AM Roel Schroeven <roel at roelschroeven.net> wrote:
> I'm not saying there is nothing useful in functional programming and the
> use of recursion; there most certainly is. But the way many texts
> introduce it IMO doesn't help at all to understand the elegance that can
> be achieved.

Indeed. When I'm talking to students about recursion, often the
question "why bother" comes up... but when they finally 'get it', it's
usually because of an example far more elegant than Fibonacci numbers.
One of my favourites is: Given a binary tree, calculate its height.

def height(tree):
    if not tree: return 0
    return max(height(tree.left), height(tree.right)) + 1

THIS is the sort of thing that shows off the beauty of recursion.
Convoluted code with accumulator parameters just shows off that you
can write bad code in any style.

(Though the accumulator parameter form does have its place. Ever
written callback-based asynchronous code that needs to iterate over
something? Such fun.)

ChrisA


More information about the Python-list mailing list