![]() |
| ||||||||||||||||||
![]() |
| ||||||||||||||||||
|
Python introduced a very smart concept which is taken over by Yanaconda: instead of using explicit code block markers like braces
'{' and '}' in C/C++ or 'begin' and 'end' in Pascal, blocks of code that belong together are identified by their indentation level. Taking away the section about conditional execution below,
here is an example:
a = 2
b = 3
if a==3
Print "A equals 3!"
if b==3
Print "and B too!"
else
Print "but B does not"
else
Print "sorry, A does not equal 3"
if b==3
Print "but therefore B does!"
else
Print "and neither does B"
sorry, A does not equal 3
but therefore B does!
When compared to the language C, the benefits are enormous: you have to type less,
do not waste space with braces, and do not spend your time searching where you forgot a brace.
However, as soon as you want to use code written by someone else,
it is payback time. Python programmers know the nightmare: You receive a code-snippet by e-mail,
paste it into your editor, save, run and crash. Then you spend your time hunting down little indentation problems,
because the original code was written with a mixture of tabs and spaces, got additionally modified on its way through the various e-mail clients and is dead on arrival.
To keep these troubles away from Yanaconda users and promote the quick and easy exchange of macros,
Yanaconda insists that indentation is done with multiples of two spaces and no tabs are used
(which is the standard Python convention anyway). If you like to use the 'Tab' key,
just configure your editor to replace each tab with two spaces while typing. (Virtually any source code editor with syntax highlighting can do that.) If you are very unhappy about that and would prefer a different indentation style,
be assured that most of the time, you will not need any indentation at all, due to the simple nature of Yanaconda macros.
| ||||||||||||||||||