Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python Newbie

Reply
Thread Tools

Python Newbie

 
 
Piterrr
Guest
Posts: n/a
 
      02-21-2013
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 asource 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? 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. 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. I think I will rather find another job than eat my nerves with Python.
Any comments on this before I quit my job?
 
Reply With Quote
 
 
 
 
Ian Kelly
Guest
Posts: n/a
 
      02-21-2013
On Thu, Feb 21, 2013 at 2:26 PM, Piterrr <> wrote:
> 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 factthat white space matters. How do you deal with this? For example, you opena 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 have never had this problem (although I don't use either of those
editors either). Are you sure you don't have any tabs in there?

> 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.


I don't understand what it is that you want to do but can't. Can you
give an example? The whole point of making indentation matter in
Python is to *force* the programmer to lay out their blocks in a
consistent and easily discernible manner.

> 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.


The former works because the if statement only takes one expression,
and the parentheses are interpreted as part of that expression, not
part of the syntax for the if. The for statement requires both a
variable name and an expression, distinguished by syntax, which again
includes no parentheses. You could surround just the expression part
in parentheses if you like -- "for i in (intAry):" -- but it looks
pretty weird if you ask me.

I don't know why you should expect to be able to add parentheses to
arbitrary syntax and have it just work. It strikes me as being like
trying to declare a variable as "int (x=3);" in C# (which I haven't
tested, but I doubt that is valid syntax).
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      02-21-2013
On 2013-02-21 21:26, 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? 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. 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. I think I will
> rather find another job than eat my nerves with Python. Any comments
> on this before I quit my job?
>

Python isn't C#. It has a different syntax.

Pascal isn't C# either.

Pascal would accept:

if (myVariable <> 0) then
...

and reject:

for (i := 0 to 9) do
...

As for the indentation, it shouldn't change if you're using only spaces
(not unless you're using a proportional font!).
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      02-21-2013
On Fri, Feb 22, 2013 at 8:26 AM, 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 factthat white space matters. How do you deal with this? For example, you opena 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? 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 wherethe if block starts and ends. Can't do that in Python. 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. I
> think I will rather find another job than eat my nerves with Python.
> Any comments on this before I quit my job?


The first comment I would make is this: Every language you learn MUST
teach you something new about programming, otherwise you haven't
really learned a new language (just a new dialect of an old one).
Embrace Python's differences, get to know how things work, then make
your decision as to what you like and what you don't

When there's a question of trust involving Windows Notepad, by default
trust the other option. Notepad *sucks* for pretty much everything.
Notepad++ is far more reliable. So is NoteTab, so is SciTE, so is
pretty much anything else on the market (though the Open Watcom editor
is designed exclusively for C, and may not be suitable for Python - it
has a habit of converting tabs to spaces, so you may run into
problems).

The issue of parentheses is one of syntax. Anything that's an
expression can have an extra set of parens around it; anything that's
not, can't. The same will happen in most languages; I daresay C# won't
let you put parentheses around the semicolon at the end of a
statement, for instance. In a for loop, the 'in' keyword separates two
expressions, so you can't have parens around it.

I'm not sure what you mean by "indenting a full 'if' statement block".
Do you mean this:

code
code
if (some condition) {
code
code
}
code
code

? Because that's a distinctly weird way to lay out code, and would be
against the style guides of many organizations (definitely against any
style guide that I write). Python forces you to use one of the more
common styles:

code
code
if (some condition) {
code
code
}
code
code

Since the braces are omitted in Python, the same Python code can
equally well represent the C standards of OTBS (as shown above),
Allman (with the opening brace on the next line, which is my
preference when writing C)... actually, every style in
http://en.wikipedia.org/wiki/Indent_style#Styles follows the pattern
of having 'if' not indented and the body indented, which is what
Python enforces. So this might be a change for you, but if you quit
your job, chances are you'll find an identical change as you conform
to some other workplace's style guide

Of course, Python does allow and encourage the use of blank lines to
help lay out your code. So if you're having trouble with the
readability of statements, try judiciously adding blanks before and/or
after, and see if that helps.

And if all that doesn't make you happy with Python, then do look for a
better job. Not every language is for everyone, and you'll produce
better code as a contented C# programmer than as a miffed Python
programmer But do consider learning multiple languages. Eric
Raymond states in one of his essays [1] that you would do well to
learn five basic languages: Python, C/C++, Java, Perl, and LISP.
They're distinctly different from each other, and will teach different
things about how to *code*, which is a skill separate from how to
*code C* or how to *code Perl*.

[1] http://www.catb.org/esr/faqs/hacker-howto.html

ChrisA
 
Reply With Quote
 
Peter Pearson
Guest
Posts: n/a
 
      02-21-2013
On Thu, 21 Feb 2013 13:26:41 -0800 (PST), Piterrr wrote:

> 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?

[snip]
> Any comments on this before I quit my job?


Nope. Quit immediately.

--
To email me, substitute nowhere->spamcop, invalid->net.
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      02-21-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
 
Reply With Quote
 
piterrr.dolinski@gmail.com
Guest
Posts: n/a
 
      02-21-2013
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 Pythonwithout 'i' being declared earlier. How do I know that I haven't used thisvariable 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 justused is limited in scope to the code within the { }. With Python, you haveto search the whole file.

Thanks to Chris, Ian and Dave for explaining the () issue around if and forstatement. 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 haverequired 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

What does this mean? Is it a test for myVar being equal to zero or a test for null, or else?

I want to learn a new language but Python's quirks are a bit of a shock to me at this point. I have been Pythoning only for about a week.

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

Peter
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      02-21-2013
On Fri, Feb 22, 2013 at 9:40 AM, <> 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
> }
>


I understand you have the freedom to do that in most languages, but
that's simply a restriction of Python: you have to use a more
conventional indentation system. Personally, I don't see the 'if' as
being special here, and the body of it (which IS special, as it may or
may not be executed) is already standing out.

> 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 variabledeclaration) 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.


That's a fair point. The elision of variable declarations is a design
decision that Python is unlikely to reverse, and it happens to be one
I disagree with. But it's there, so when I code Python, I accept it
There are other languages similar to Python that have strict variable
declarations, and with them the awesomeness that is infinitely nested
scopes; Python just has global (module) scope and function scope, plus
'nonlocal' which can solve some problems (but I've yet to find it do
so without damaging code clarity).

> 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
>
> What does this mean? Is it a test for myVar being equal to zero or a testfor null, or else?


Python has a state called "truthiness". Generally speaking, something
with content is true, and something without content is false. The None
singleton, empty lists, empty tuples, the integer 0, and a regular
expression result that didn't match, all evaluate as False in a
boolean context; most other things evaluate as True. If you
specifically care if it's not zero, you ask if it's not zero; if you
want to know if it's falsy, you check "not X". The facilities are
there to do whatever you want.

ChrisA
 
Reply With Quote
 
Oscar Benjamin
Guest
Posts: n/a
 
      02-21-2013
On 21 February 2013 22:40, <> 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


So you already indent blocks in an "if" construct? This is good
practise in some languages and is enforced in Python. Once I got used
to it I found that the compulsory whitespace made it easier to read
conditional code blocks.

>
> 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.


Do you mean that you literally insert a line of '#' characters before
and after in "if" block? There's no need to do that. Just allow
yourself to acclimatise to the significant whitespace and you'll find
that it's easy to see where the block begins and ends.

>
> 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 variabledeclaration) 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.


No, you only have to search the whole function which for me is rarely
more than 20 lines. The statement "i=0" when inside a function will
not overwrite anything outside the function (unless you use the
global/nonlocal statements). I rarely use global variables or module
level variables and if I do then I usually have a special place in a
module/script for defining them. I also tend to name them in ALLCAPS
just like C-preprocessor macros that need to be carefully maintained
in a separate "namespace".

>
> 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.


You'll get used to using the colon in the same way.

>
> 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
>
> What does this mean? Is it a test for myVar being equal to zero or a testfor null, or else?


All of those things. It executes "do something" if myVar is
1) zero (whether int/float/complex etc.)
2) False
3) None
4) an empty collection (list/set/tuple etc.)
5) an empty string
6) and more...

If the context doesn't make it clear what you are testing for then use
a more specific test (myVar!=0 works just as well).

> I want to learn a new language but Python's quirks are a bit of a shock to me at this point. I have been Pythoning only for about a week.
>
> In the mean time, thanks to most of you for encouraging me to give Pythona chance. I will do my best to like it, w/o prejudice.


Many of the things that have confused/concerned you are things that I
actually like about Python. Given time you may do as well.


Oscar
 
Reply With Quote
 
piterrr.dolinski@gmail.com
Guest
Posts: n/a
 
      02-21-2013
Hi Chris,

Thanks for this. Regarding ambiguity, you will never find me write ambiguous code. I don't sabotage my own work. But the reality is that in addition to writing my own code, I have to maintain existing. I find it incredibly confusing then I see a statement along the lines of "if not something" - haveto study the code in detail to see what it is testing.

I could show more examples of what I find confusing in existing code, but Idon't intent to troll. I'm just trying to understand the language as it is.. I will see how it goes.

Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Python newbie) Using XP-SP2/MSVC6: No Python24_d.lib, winzip barfs on Python-2.4.1.tar, cannot download bzip2 Bill Davy Python 12 04-22-2005 12:19 PM
Re: (Python newbie) Using XP-SP2/MSVC6: No Python24_d.lib,winzip barfs on Python-2.4.1.tar, cannot download bzip2 Jaime Wyant Python 0 04-21-2005 12:49 PM
RE: (Python newbie) Using XP-SP2/MSVC6: No Python24_d.lib,winzip barfs on Python-2.4.1.tar, cannot download bzip2 Bill Davy Python 0 04-19-2005 09:27 AM
Python Newbie. Python on PPC, please assist. pythonnewbie Python 5 10-12-2004 05:51 PM
Creating an OLE server document in Python (MFC/OLE/COM/Python newbie) Drew Pihera Python 0 02-04-2004 07:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57