[Python-ideas] Python reviewed

Steven D'Aprano steve at pearwood.info
Tue Jan 10 05:42:18 EST 2017


On Tue, Jan 10, 2017 at 09:44:31AM +0800, Simon Lovell wrote:
> Also in Python you can use:
> 
> for x in range (1,j+1):
> 
> to loop j times. Although it does read as though it is looping j+1 times 
> to those not familiar.

*shrug*

To those "not familiar", most language features are mysterious and it is 
easy to guess wrong.

What's the difference between foo[x+1] and foo(x+1)? 

In Python, the first is a key or index lookup and the second is a 
function call; but in Mathematica, the first is a function call and the 
second is foo multiplied by x+1.

Python prides itself in having a much easier learning curve than many 
languages, with syntax that is close to "executable pseudo-code", but 
that doesn't mean that there is *nothing* to learn.

 
> One more comment I wanted to make about end blocks,
[...]


If I never have to see code like:

                    end
                end
            end
        end
    end
end

again, it will be too soon.

 
> I still struggle to see why it should be 
> mandatory though? For those who prefer to have the block closing 
> delimiters this way, is the need for a keyword (could be a command line 
> option) really the objection?

It's not mandatory -- there are dozens of other languages you can use 
that will satisfy your urge for a redundant "end" block marker.

But for *Python*, it is mandatory because it is Guido's language, not 
yours. When you design your own language, you can design it to be as 
complicated or simple, as baroque or plain as you like.

Think about what you are asking for: a command-line option that controls 
whether or not the interpreter requires "end" after each block. Now 
every single library module needs to be written twice, once with "end", 
once without. Otherwise, it won't even compile for half the users.

If all you care about is something physically at the end of the block, 
without the compiler enforcing it, then Python already supports this, 
using your choice of keyword:

with open(filename) as f:
    for line in f:
        if condition:
            while something:
                spam(line)
            #end
        #finish
    #done
#conclusion

Problem solved.



-- 
Steve


More information about the Python-ideas mailing list