Python Newbie

rusi rustompmody at gmail.com
Fri Feb 22 01:57:58 EST 2013


On Feb 22, 3:40 am, piterrr.dolin... at gmail.com wrote:
> Thanks to all for quick relies.
>
> Chris, you are (almost) spot on with the if blocks indentation. This is what I do, and it has served me well for 15 years.
>
> code
> code
>
>    if (some condition)
>    {
>       code
>       code
>    }
>
> code
> code
>
> This is what I call code clarity. With Python, I am having to do this
>
> code
> code
>
> ##############################
>
> if (some condition):
>   code
>   code
>
> ##############################
>
> code
> code
>
> It does the job, but is not ideal.
>
> I am nervous about using variables "out of the blue", without having to declare them. For example, when I write "i = 0" it is perfectly OK to Python without 'i' being declared earlier. How do I know that I haven't used this variable earlier and I am unintentionally overwriting the value? I find I constantly have to use the search facility in the editor, which is not fun.
>
> You see, Javascript, for one, behaves the same way as Python (no variable declaration) but JS has curly braces and you know the variable you have just used is limited in scope to the code within the { }. With Python, you have to search the whole file.
>
> Thanks to Chris, Ian and Dave for explaining the () issue around if and for statement. I don't agree with this, but I understand your points. The reason why I like parentheses is because they help with code clarity. I am obsessed with this. :-) After all, there is a reason why so many languages have required them for several decades.
>
> What about Python's ambiguity?
> For example, in C you would write
>
> if (myVar != 0)
>   do something
>
> in Python, this is legal
>
> if (not myVar):
>   do something

I have seen any amount of C code where:
if (x != 0) { ...

is shortened to

if (x) { ...

Python is similar (and many of us dont like this feature).
Just know it as a feature and get on with it.  Python has less
features/gotchas/bugs than most other languages.

As for indentation: This is more a philosophy than a technology
question.  Its called DRY (Dont Repeat Yourself)  In most languages
(other than python and haskell) you use {} or some such for the
compiler and indentation for the human reader.  Saying something
exactly once is not just a space/time saver. Its also a error saver.

> In the mean time, thanks to most of you for encouraging me to give Python a chance. I will do
> my best to like it, w/o prejudice.

The mathematician Paul Halmos was once told by a bewildered student:
"I just dont understand mathematics!"
Halmos replied: My boy you dont understand mathematics. You just get
used to it.



More information about the Python-list mailing list