I guess I am okay with python's one-line lambdas, since it's easy enough to write a normal function if the logic required doesn't fit - their properties are otherwise the same. Whether one loves or hates the use of indentation to denote blocks in python, it does make regular functions in python pretty concise already:
last=lambdax:x[len(x)-1:]# vs.deflast(x):returnx[len(x)-1:]# both versions are clear and short I think...
In general I am not a big fan of anonymous code blocks, so limiting them to short snippets of code seems acceptable to me.
It looks as though regular functions in ruby don't act as closures, so you need blocks, procs, or lambdas for that. In python, and javascript for that matter, normal functions will capture the enclosing scope, so I think that's probably why the aforementioned code blocks are so essential in ruby, but not really so significant in python. My gut feeling is that python's approach is more orthogonal, therefore better. I don't know what the considerations were in the design of ruby though.
I kind of dislike both python and ruby's lambdas a bit though, because they both require special syntax. I'm not enough of an expert to deeply understand the whole situation, but in principle, I do like the idea of using the same syntax to define functions everywhere. It works in javascript for example:
Sadly, in spite of this, javascript still has the problem of way too many ways to write functions! Regular functions, arrow functions, class methods, properties transform... sigh...
Fred is a software jack of all trades, having worked over the last 24 years at every stage of the SDLC and has authored [two books](https://www.amazon.co.uk/Fred-Heath/e/B08F3Q1H1M).
I didn't know that Python functions were also closures so thanks for that! And yes, Ruby functions (methods) are scope gates, the scope changes as soon as you enter them so they're not closures.
I suppose it comes down to different programming philosophy and approach between Ruby and Python. If you love well-structured, one-way-of-doing-it approaches then Python is for you. Ruby is more loose in that sense but that's why I (and many others) find it so attractive.
As for JavaScript, well, don't get me started :D
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I guess I am okay with python's one-line lambdas, since it's easy enough to write a normal function if the logic required doesn't fit - their properties are otherwise the same. Whether one loves or hates the use of indentation to denote blocks in python, it does make regular functions in python pretty concise already:
In general I am not a big fan of anonymous code blocks, so limiting them to short snippets of code seems acceptable to me.
It looks as though regular functions in ruby don't act as closures, so you need blocks, procs, or lambdas for that. In python, and javascript for that matter, normal functions will capture the enclosing scope, so I think that's probably why the aforementioned code blocks are so essential in ruby, but not really so significant in python. My gut feeling is that python's approach is more orthogonal, therefore better. I don't know what the considerations were in the design of ruby though.
I kind of dislike both python and ruby's lambdas a bit though, because they both require special syntax. I'm not enough of an expert to deeply understand the whole situation, but in principle, I do like the idea of using the same syntax to define functions everywhere. It works in javascript for example:
Sadly, in spite of this, javascript still has the problem of way too many ways to write functions! Regular functions, arrow functions, class methods, properties transform... sigh...
I didn't know that Python functions were also closures so thanks for that! And yes, Ruby functions (methods) are scope gates, the scope changes as soon as you enter them so they're not closures.
I suppose it comes down to different programming philosophy and approach between Ruby and Python. If you love well-structured, one-way-of-doing-it approaches then Python is for you. Ruby is more loose in that sense but that's why I (and many others) find it so attractive.
As for JavaScript, well, don't get me started :D