Python Newbie

2013-02-21 Thread Piterrr
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?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-26 Thread Piterrr
"Jean-Michel Pichavant"  wrote in message 
news:mailman.2567.1361905815.2939.python-l...@python.org...


- Original Message -

Hi guys,

Question. Have this code

intX = 32  # decl + init int var
intX_asString = None   # decl + init with NULL string var

intX_asString = intX.__str__ ()# convert int to string

What are these ugly underscores for?
_str___

Peter
--
http://mail.python.org/mailman/listinfo/python-list


I can't wait for the

intX_asString_asBool = intX_asString.__bool__()

if (intX_asString_asBool == True):
 # do something

;-)

JM


As serious a character as I am, I had good laughs at this. Don't you all 
like my questions for all the exitainment they offer?


The "__str__" issue was a genuine question. I'm glad to find there is also a 
__bool_ () method, shall I need it. :-) Please note, this is not how I write 
my code. I'm not that bad a programmer, it's just Python which is so 
different that I am doing what I need to help clarify things and help me 
out.


I don't find this post offensive, even though JM is deliberately making fun 
of me. But to his credit, it is funny indeed. Let's laugh 2gether!


This reminds me, when I first started working with databases and saw an 
error msg which said that my query had "ambiguous columns" I laughed for 1/2 
hr. I found it incredibly exitaining that a 100% deterministic piece of 
hardware could have the word "ambiguous" in its internal dictionary.


:-))

Peter 


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-21 Thread piterrr . dolinski
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

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 a 
chance. I will do my best to like it, w/o prejudice.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-21 Thread piterrr . dolinski
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" - have 
to 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 I 
don't intent to troll. I'm just trying to understand the language as it is. I 
will see how it goes.

Pete
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-22 Thread piterrr . dolinski
Thanks to everyone for all the posts, some friendly some not. I read all of 
them with genuine interest.

So I am continuing to learn Python, here are my new observations for your 
consideration.

There seems to be a "heated" argument about Python's apparently intentional 
ambiguity in conditional statements. Specifically, the issue is, is it more 
appropriate to write (as an example)

if (some statement):# short form

rather than

if (some statement == true):# long form

Some 50(?) years ago, C was designed so that everything other than 0 evaluated 
to true and was false otherwise. Fast forward to recent memory, when C# was 
designed, Microsoft claims they reviewed all the features of C, C++ and Java, 
pulled the best features from each of these languages and designed a new 
language that would help minimize the potential for planting bugs. Say what you 
want about MS inventions, but my experience is that to require the long form 
notation was a good decision. For me the fact that the short notation is legal 
in Python is a stepback in language design. Python inventors, when creating 
what is after all considered a contemporary language, should have known better. 
Call me psychopath if you will (have seen this in one post), but I shall 
continue to use the aforementioned long form as I always have, and no Python is 
going to change that.


Today I learned the hard way that all function parameters in Python are passed 
by reference (meaning whatever happens to them inside a function, new values 
are always passed to caller). Not good. I got caught up on this. To combat the 
mostly unwanted behavior, inside a function I have to reassign variables 
intended to be local to new variables. A pain. Can anyone offer ONE reason why 
Python was designed that way?

Out of curiosity, does anyone have any idea why function declarations are 
preceded by the keyword "def" rather than something more intuitive like 
"function" or at least "func", perhaps?

Does anyone know what the benefit of writing the cryptic "elif" to mean "else 
if" is? Curiously, the default statement in an if/else chain is preceded by 
"else" and not "el".

Someone said I am too narrow-sited appreciating C# and not open to alternate 
approaches to language design. Well if that someone says "def" is better than 
"function" and "elif" is better than "else if", then dare I say, you are 
obsessed with Python!

So far I am getting the impression that Python is a toy language of some kind 
(similar to Basic of the early 80's), not really suitable for serious work. The 
only difference between these languages (admittedly, a serious one) is the 
existence of extensive libraries. Otherwise there would be no good reason for 
Python to exist. Nevertheless, it does exist and I have to learn it. As long as 
someone is paying for my time, that's OK with me.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-22 Thread piterrr . dolinski
Hi Ian,

Thanks for typing all this for me. Really useful. I did some googling of my own 
and I found that there was no concept of boolean in older versions of Python 
like you said. (BTW, how does this omission go well with proper language 
design, as Oscar seems to have hinted?) I think this obvious shortcomming is 
the main reason that, for example, when x holds the value of 5, x is considered 
to be "true". You see, I have to maintain Python files (ubuntu server scripts) 
which are 2000 lines long, all sequential code, no functions. While the person 
who wrote them should be shot :), the fact that there is inherent ambiguity 
with value, none, null 0, you name it, in conditional statements is not helping 
me understand the code, and this adds to my frustration.


I messed up my

if (some statement):# short form

in the example I gave, but you figured exactly what I mean. Of course if the 
condition (some statement) is boolean there is no point adding "== true" or 
similar. But if (some statement) represents a value this is where I have 
trouble and again the origins of this date back to when Python had no boolean 
type. So now at least I understand it.

Btw, there are still languages with no boolean type today, MySQL for one. This 
creates big efficiency problems when fetching data from the database into a C# 
program - what should be a bool is fetched as an 8-byte integer! But that's a 
different story. I shut up now.

As I said I am new to Python, learning it, I have to get more experience with 
passing parameter values to functions, as I do with mostly everything else.

Cheers.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-23 Thread piterrr . dolinski
Hi all,

(Ethan, I like your "resident troll" statement. Highly exit-aining!)

Thanks for all the input. I did not expect to get so much constructive 
feedback, the more so that my initial attitude towards Python has been less 
than positive, diplomatically speaking.

Yes, it's true that I am trying to write C# code in Python. It is not going to 
change any time soon, if at all - I have done too much C#ing, C++ing before 
that and C-ing earlier still. What surprises me a bit is that no one has said 
one word against C#, as a form of retaliation against me not being in love with 
Python. And C# does have its share of concerns, like any language. So far I 
like the community a lot better than Python.

I am trying to learn some Python on my own (besides faffing with it on the job, 
to use a britishizm). I have discovered today there is no do...while type loop. 
[Sigh]

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-24 Thread piterrr . dolinski
Hi guys,

Question. Have this code

intX = 32  # decl + init int var
intX_asString = None   # decl + init with NULL string var

intX_asString = intX.__str__ ()# convert int to string

What are these ugly underscores for? _str___

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-24 Thread piterrr . dolinski
> To demonstrate that the person who wrote this code was not a good Python 
> 
> programmer. I hope it wasn't you :-) This person obviously had a very 
> 
> basic, and confused, understanding of Python.
> 
> 
> 
> And, quite frankly, was probably not a very good programmer of *any* 
> 
> language:
> 
> 
> 
> - poor use of Hungarian notation for variable names;
> 
> - pointless pre-declaration of values;
> 
> - redundant comments that don't explain anything.
> 
> 
> 
> If that code came from the code-base you are maintaining, no wonder you 
> 
> don't think much of Python! That looks like something I would expect to 
> 
> see at the DailyWTF.

Hi. Steve, I don't know where you have been over the past couple of days but it 
is widely known (if the thread title is any indication) that I am indeed very 
new to Python, but not new to programming in general.

To give a bit of background where I found __str__, I am using a Python IDE 
called PyScripter. Its Intellisense is full of methods starting and ending with 
"__", hence the question.

Regarding Hungarian notation, I don't use it in any other language but Python 
and JS. Call it poor, but it helps me to remember what type a variable is. The 
redundant comments serve the same purpose. As for "pointless predeclaration", 
it helps me know where in the code I first started using the variable, so I 
know there are no references to it before then.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-24 Thread piterrr . dolinski
> > if (some statement):# short form
> >
> > rather than
> >
> > if (some statement == true):# long form
> 
> 
> What all those ugly brackets are for?
> 

Mark,

Back in the day when C was king, or take many newer long established languages 
(C#, Java), the use of () has been widespread and mandated by the compilers. I 
have never heard anyone moan about the requirement to use parentheses. Now come 
Python in which parens are optional, and all of a sudden they are considered 
bad and apparently widely abandoned. Do you really not see that code with 
parens is much more pleasing visually? I could understand someone's reluctance 
to use parens if they are very new to programming and Pythons is their first 
language. But my impression here is that most group contributors are long-time 
programmers and have long used () where they are required. Again, I'm really 
surprised the community as a whole ignores the programming "heritage" and dumps 
the parens in a heartbeat.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-24 Thread piterrr . dolinski
Josh,

Not thank you for your malicious post.
I think you are missing the point here.

My source code was just a dummy to offer context for the question I wanted to 
ask. Further down the line, if I ever feel I don't need to pseudo-declare 
variables I will stop doing it. But for the moment I am trying to imitate 
familiar ground.

My code as written has no syntax errors, so what's the problem? It is highly 
unlikely you will ever read any of my Python code - no need to get excited over 
a few of my lines.

And you don't need to answer questions which were not posed, thank you.

I wanted Python to register what type of variable I'm after. So I init my vars 
accordingly, int might be 0, float 0.0 and string with null, err... None.

In practice, I wouldn't define an intX_asString var, I would do "str (num)" 
every time a string representation is needed, provided it isn't a loop, as in 
that context the expression would probably negatively impact performance in an 
interpreted language.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-24 Thread piterrr . dolinski

>> intX = 32  # decl + init int var
> How is it not obvious that "intX" is an integer *without* the comment?

Indeed the assignment is enough to deduce "intX" is an int. The comment is 
there to let me know it is unlikely intX appears earlier in the code. Please, 
let me do things my way until I find reasons to the contrary.

Regarding my use of None to mean NULL, point taken to use "" instead.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-24 Thread piterrr . dolinski
> For example (I believe it's already been mentioned) "declaring" intX with 
> some integer value does *nothing* to maintain 
> 
> X as an integer:
> 
> --> intX = 32
> 
> --> intX = intX / 3.0
> 
> --> intX
> 
> 10.66
> 

Yes I did see that it is possible to redefine the type of a variable. But I 
don't think I would ever do this intentionally; need to be really careful with 
Python.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list