Python Newbie

Dave Angel davea at davea.name
Thu Feb 21 23:22:25 CET 2013


On 02/21/2013 04:26 PM, Piterrr wrote:
> Hi folks.
> I am a long time C sharp dev, just learning Python now due to job requirements. My initial impression is that Python has got to be the most ambiguous and vague language I have seen to date. I have major issues with the fact that white space matters. How do you deal with this? For example, you open a source file in different editors and the indentation levels change even though i only have spaces, no tabs (compare Windows Notepad and Notepad++). Which editor do you trust?


I'll take a chance and assume you're not just trolling.

Spend a while with it, you'll learn to like it.  It's about the 35th 
language I've used on the job, and is certainly my favorite.  And the 
fact that indentation has to match the meaning is a key advantage over 
languages that encourage you to write code that reads differently to the 
human than to the compiler.  Many times I've spotted code written by 
others that either had an extra semicolon, or had a dangling else that 
was lined up with a different if than the compiler would use.  There are 
plenty of defensive techniques in the C-family, like requiring braces 
for every clause even if a single statement.  But I find the lack of 
braces to make it easier to see a whole function in one view.

I did spend some time working in C#, but it didn't have a name yet. 
They called it C++ IJW, and I had to practically sign in blood to get a 
copy.  A number of the introspection features of dot-net were a result 
of my requests.  I had software in Microsoft's booth at the announcement 
of dot-net.  I haven't touched dot-net since.

I decided over 30 years ago (in a spec I wrote for one of my developers) 
that tabs in source code were a huge mistake, because of the varied way 
that different editors, printers, etc. handled them.  Consequently, I 
only use editors that have a way to always expand tabs to spaces.  I 
consider the tab key just a way to position myself on the screen, and 
would use a different method if I ever wanted a 09h code point in the file.

Contrary to your experience, I've never seen different text editors 
interpret the columns differently in the absence of tabs.  Are you by 
any chance using a proportional font????  Text files must be used with 
fixed-width fonts.  In any case, avoid Notepad.  It can't even handle 
text files with Unix line-endings.  I use emacs, but I also use Komodo, 
gedit, and in the past have used Kedit, Codewright, and many others.


 > In addition, code is difficult to read because you cannot lay it out
 > in easily discernable blocks. For example, I always tend to indent a
 > full 'if' statement block so that it is easier to see where the
 > if block starts and ends. Can't do that in Python.

The line immediately preceding an indented section is the dependent 
clause, be it if, or else, or def, or class, or ...  The section is 
complete when indentation returns to the earlier level.  Simple, 
consistent, easy to spot.  Unless you use two-column indentation, or 
have 6 levels of indentation in a single function.

 > What is even more frustrating is that Python is inconsistent with
 > its syntax. For example, when I write "if (myVariable != 0):"
 > then this is OK but "for (i in intAry):" results in syntax error.
 > Apparently Python has problems with my use of parentheses.
 > How retarded.

The if statement takes a single expression, so you can use redundant 
parentheses to your heart's content.  The for statement is defined as:

for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]

where in is a keyword, not part of some expression.  So of course the 
parenthesis you tried is illegal.

To see the rest of the grammar, see
    http://docs.python.org/2/reference/grammar.html
or http://docs.python.org/3.3/reference/grammar.html

 > I think I will rather find another job than eat my nerves with Python.
 > Any comments on this before I quit my job?
 >

Finding a new job can be a good thing, if your old company forces you to 
use the same language, and to do the same work over and over again.  My 
career has been full of variety, and I've turned down jobs that were 
offered merely because I already knew the tools.

However, if you give Python a chance, I think it'll grow on you.

-- 
DaveA



More information about the Python-list mailing list