Maybe it's because I am also something of a lisper (like Norvig), but I don't see anything wrong with inline ifs (after all, that is how if works in lisp, with returns for a conditional, like the ternary operator) or lambda functions. In fact, I find that improves readability dramatically because it more declaratively says what you are trying to accomplish in many cases.
To me this is perfectly clearly a simple function whose only purpose is to prepend forward slashes to unix-style paths. Is the following really so much more readable?
def absolute_path(path):
if not path.startswith('/'):
path = '/' + path
return path
To my eyes and mind, the second example is not any more readable at the expense of several lines of code.
For example:
To me this is perfectly clearly a simple function whose only purpose is to prepend forward slashes to unix-style paths. Is the following really so much more readable? To my eyes and mind, the second example is not any more readable at the expense of several lines of code.