topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 6:20 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Python Language Annoyances  (Read 24015 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Python Language Annoyances
« on: January 22, 2010, 05:28 PM »
[EDIT: This discussion was originally on this thread]

first let me just say this, python uses implicit variable declaration (ie you dont have to declare a variable before it is used, you just use it).

to me, this is the single worst most harmful idea in the history of programming languages, and it completely baffles me that it can be found in a modern and popular language.  that single issue is reason enough that no one should be using this language.

this is actually a little related to why the issue of significant indentation is such a bad idea -- because it makes it so easy to introduce bugs that are nearly invisible to the naked eye (using a tab instead of a space, mispelling a variable name, etc.)

the syntax is a personal thing, but just feels wrong to me.. having to declare object functions with "self" as the first parameter (even though when you invoke it you dont pass that.  this optional class documentation string stuff, by just specifying a string after the def line.. it just feels kludgey and dirty.
« Last Edit: January 24, 2010, 07:54 PM by mouser »

kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #1 on: January 22, 2010, 09:21 PM »
mouser,

Please check out these articles if you have time. These are quite old but I think that they explain where Python is really practical and easy to use

http://www.ibm.com/d...library/l-pycon.html
http://www.ibm.com/d.../library/l-prog.html

tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #2 on: January 24, 2010, 02:37 PM »
Just very brief comments, since I know you will investigate deeper if you care to (and have the time).

It boils down to static typing versus dynamic typing; and the workflow that goes along with that.

And most Python programmers do TDD, so bugs are found via testing and there is no need to compile so you just run and debuging realtime based on stacktraces (which are integraded into the python tools that are worthwhile using).

tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #3 on: January 24, 2010, 02:40 PM »
Oh, and regardless of what tools you use, use IPython. Yes, it is that good. I always have an IPython window open regardless of what platform I am on or tool I am using. Think of it as a fulltime realtime debugger with built in macros.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #4 on: January 24, 2010, 07:39 PM »
First: this is about Python, not IDEs - I suggest a moderator separate this post, and the posts below, to a new thread:

It boils down to static typing versus dynamic typing; and the workflow that goes along with that.
No, it doesn't :) - you can do dynamic typing even if you have to predeclare variables (just declare them as "var" rather than a specific type). Even though I generally prefer static typing (catching bugs at compile-time = :-*), I do accept that dynamic typing can be useful (especially while prototyping stuff  - nice not having to bother with endless type conversions)... but not requiring variables to be predefined is a big mistake, IMHO.

And I also agree with mouser that it's also a big mistake depending on indentation for program structure... there's just too many ways this can screw you over, and it's not like it's a big hurdle to {enclose structural blocks}. These two things are items I find problematic (and downright stupid) in the core Python language.

Also, as mouser, I think the "__self__" for Python OOP looks kludgy, nasty and superfluous. This is more of an aesthetic issue though, and not something that bothers me majorly. Most importantly, it's not dangerous as the above two points.

Final gripe is probably the standard library, which feels... messy. Some stuff tries to look like POSIX C which is OK for a lot of stuff, while other parts look like WIN32 emulations. Of course one shouldn't re-invent the wheel all the time, but it would be nice with a somewhat more coherent standard library. There's also the issue of not everything being available everywhere, leading to perhaps having to do platform-specific code (probably less of a problem now than when I last bumped into it - and I can't remember the specifics anyway).

There's also been a fair amount of times where I've scratched my head pondering why a particular routine throws an exception instead of using a return code... IMHO exceptions should be for exceptional conditions, whereas return codes signal "failure" that can be "expected" (ie, a file-read that fails would be an exception, file-not-found would be return code) - but when to use exceptions (and when not to) is somewhat of a religious subject.

And most Python programmers do TDD, so bugs are found via testing and there is no need to compile so you just run and debuging realtime based on stacktraces (which are integraded into the python tools that are worthwhile using).
Even with that, I'm still a firm believe in my first two points... doing those properly costs you almost nothing, and will very likely end up saving you a lot more in the end.

But in spite of all the above, I still do like Python, and find that it's a pretty nice tool for a lot of things, where you'd spend too much time in C++ focusing on auxillary stuff rather than getting your job done.
- carpe noctem

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #5 on: January 24, 2010, 08:02 PM »
Sorry to be harsh, but here's another example of what i think is almost unbelievably shoddy language design, and is a huge warning sign for me that Python should be dumped in favor of a new language at the earliest possible time:

http://www.velocityr...rator-in-python.html

The use of ++variable and variable++ is a very common way of incrementing and decrementing variables, from the days of C and C++ and it can be found in Java and many other languages.

Now.. it's completely fine that Python not implement this -- I am all in favor of eliminating redundant ways to write expressions.  I have no complaint about python not supporting the increment operator.

However, what is totally insanely stupid is to design a modern language where the ++variable syntax is completely legal, and does nothing.

That is a decision absolutely guaranteed to cause problems and i'd be extremely surprised if there wasn't production code with such errors.

It just boggles my mind that someone could design a modern programming language and come up with such a poor design choice.

It's almost as if one of the goals of Python is to make it as easy as possible to write incorrect code that doesn't trigger any obvious errors.  This is not the way languages should be designed.

[In the interest of full disclosure, i should say that i am a native C/C++ coder, and C has it's own share of such things, for example in making this kind of conditional legal but misleading "if (a=5) ..", which was one of the great blunders of language design.  Haven't language designers learned not to do this by now?]
« Last Edit: January 24, 2010, 08:06 PM by mouser »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #6 on: January 24, 2010, 09:29 PM »
Disclaimer:
I get very mad at things and have been known to rant incoherently at every piece of software I have ever used.  I am actually now using Python in a new little project, and I can say for some things it's very nice..  And I use PHP quite a lot which has it's own set of problems.  Every language does.

So don't take my harsh words against Python as some indication that i think it's any worse than every other major programming language.

I'm just trying to lay the groundwork for making my own programming language in the coming years ;)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #7 on: January 25, 2010, 03:22 AM »
Just thought that I should add that, despite my complaints above, which i stand by, i've been coding in Python all weekend, and i do have to admit I'm having a lot of fun with it and getting a lot done.  Love the built in stack-trace printout when it hits an error, and nice module importing/compiling/etc.

parkint

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 119
  • It's bad luck to be superstitious
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #8 on: January 25, 2010, 08:43 AM »
In my experience (spanning 30+ years, with over a dozen different languages) EVERY language/OS/protocol has its own peculiar annoyances.
Of course, each has its strengths and I like calling upon a particular "solution" based on how well it will address the "problem" at hand.
I appreciate the variety from which to choose.

Remember, "The great thing about standards is that there are so many to choose from"

tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #9 on: January 25, 2010, 11:40 AM »
Just a word for "outsiders". I am considered one of the Python fanbois on this site. And I have been a regular here for years. I just wanted to let you know that mouser is being sincere here. He just doesn't have the time to list the many things he likes about the language, and we around here don't feel ashamed to just cut to the chase when discussing things. So please don't take his comments the wrong way.

With out boring you with details and requiring time I don't have to dedicate to this, let me just say that I believe much of this has to do with keeping things as simple as possible and python being more "metaprogramming" focused than other languages.

And a reminder to import this, as it will give you a better understanding of python.

mnemonic

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 177
    • View Profile
    • My website
    • Donate to Member
Re: Python Language Annoyances
« Reply #10 on: January 25, 2010, 03:33 PM »
For someone like myself, without any formal development background, Python is great as it is easy to learn and quick to develop in. I can't comment on any of the issues that mouser raises, as I don't know anything different.

I did start to learn C++, but barely enjoyed a moment of it due to the trickiness of some of the syntax.  As someone who only develops in spotty bits of spare time, having a simple language is a godsend.

Simple languages with easy syntaxes are great for allowing beginners to get into developing and that can only mean more people developing  :Thmbsup:

Plus, having implicit variable declaration quickly teaches you to write tests everywhere  ;D

urlwolf

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,837
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #11 on: January 25, 2010, 05:57 PM »
I'm on the same boat.
I don't like many things about python, ant this is why I'm looking at scala. Type inferencing is good.

kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #12 on: January 25, 2010, 06:23 PM »
What I like about Python is that there are applications out there that use Python as internal scripting engine which makes it more available. That way I do not need to learn every other scripting engine that applications might require.

For example Open Office, Gnumeric and Gnucash offer Python scripting
« Last Edit: January 25, 2010, 06:52 PM by kartal »

urlwolf

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,837
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #13 on: January 26, 2010, 03:35 AM »
Plus, having implicit variable declaration quickly teaches you to write tests everywhere 
Actually, I see very little python code out there with tests. Ruby, on the other hand... even pastie clips have tests!

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #14 on: January 26, 2010, 04:39 AM »
On a side note, if you want to see some (lots?) of tests for a piece of Python code, Mark Pilgrim's Universal Feed Parser might be something to take a look at.

kakarukeys

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 25
  • Save time play more
    • View Profile
    • Time-saving Guides, Windows and Office Tips to increase your productivity
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #15 on: January 28, 2010, 12:18 PM »
Now.. it's completely fine that Python not implement this -- I am all in favor of eliminating redundant ways to write expressions.  I have no complaint about python not supporting the increment operator.

However, what is totally insanely stupid is to design a modern language where the ++variable syntax is completely legal, and does nothing.

That is a decision absolutely guaranteed to cause problems and i'd be extremely surprised if there wasn't production code with such errors.

In mathematics, +x simply means x with a positive sign, and ++x = +x = x
Python simply conforms to what we learned in primary, secondary schools
Another example: 1 / 2 = 0.5 in Python, but 1 / 2 = 0 in C
And what's wrong to write x += 1, if you want to increase the value of x by 1?

this is actually a little related to why the issue of significant indentation is such a bad idea -- because it makes it so easy to introduce bugs that are nearly invisible to the naked eye (using a tab instead of a space, mispelling a variable name, etc.)

An IDE or a good text editor will help. Same could be said for programming languages that use braces, unmatched braces could give you trouble that isn't easily spotted by naked eyes.
life is short, play hard

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #16 on: January 28, 2010, 08:21 PM »
In mathematics, +x simply means x with a positive sign, and ++x = +x = x
Neat :Thmbsup:

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #17 on: January 28, 2010, 08:26 PM »
Let's get real here.. like all languages, context means everything.  In python, like many languages, the + character sometimes means positive (a=+7), or it means addition (a=b+3), or it means string concatenation (a="hello "+b).  Few languages are stupid enough to allow a ++ to mean nothing (or signifiy a positive number) and not throw an error.

TEST:
What does ++---+-+7 evaluate to in python? or is it an error?

If everyone who uses Python can't immediately, obviously, and confidently surmise the answer to this (and be in agreement), then you have to accept that this is a terrible flaw in the language.

Hell even if you can, it's just plain stupid.

It's like me introducing a language where + means division and * means addition.  It may be internally consistent, but it is spitting in the fact of decades of established syntax, for no good reason, and will lead to tons of undetected errors.

Again, it's fine to break with precedent, but you need to have a good reason and make an attempt to flag likely incompatibility problems.  Python has too many of these kinds of pointless problems.
« Last Edit: January 28, 2010, 08:37 PM by mouser »

kakarukeys

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 25
  • Save time play more
    • View Profile
    • Time-saving Guides, Windows and Office Tips to increase your productivity
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #18 on: January 28, 2010, 08:57 PM »
 8) well, remember 3 things:
(1) +/- in front of variable is a unary operator that changes the sign (as in maths)
(2) plus plus = plus, minus minus = plus, plus minus/minus plus = minus (as in maths)

To me these are rules that were established long before programming language, since the time of Greek. It's C which changed the rules, and that's why I and some had had a hard time learning C in school, Python is more natural to me.

(3) There is usually only one way to perform certain task (Pythonic principle)

It is not hard to understand Python's choice and figure out the answer to the TEST.
 :)
life is short, play hard
« Last Edit: January 28, 2010, 09:06 PM by kakarukeys »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #19 on: January 29, 2010, 10:33 PM »
Well, what I can say, is that I took a programmer with minimal knowledge and got him Hello World! (the book on manning.com for Christmas).  I had never used python up until now, but I've been going through the PDF that I received for free with the book so that I could answer questions for him.

The Pros:
1. He's gotten up to speed quite quickly- moreso than I would have expected.
2. It's very easy to pick up- much more than any other language that I have used- and get concrete and useful things done without all of the baggage of most languages

The Cons:
1. The errors that he's had to bring to me are because of the indentation and the lack of implicit variable declarations

I think it's a nice, lightweight language- especially for teaching (and learning).  I do expect him to move on fairly quickly, but this was a way to get him programming and into the problem solving mindset rather quickly before starting classes as a developer.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #20 on: January 30, 2010, 01:49 AM »
I'm curious (famous last words?), how many Python-using folks here use PyChecker or something like it?  I found it useful for the few things I used it for and IIRC it can point certain kinds of things out that the interpreter doesn't tell you about.

To drift a bit OT, FWIW:

For Perl, I tended to use -w and use strict, both of which helped.  (It appears there's now a Perl::Critic.)

For Javascript I used jslint.

May be there's a pattern here? ;)

tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #21 on: January 30, 2010, 03:09 PM »
I code with Eclipse/Aptana/Pydev and get all of the code checking that come with that.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Python Language Annoyances
« Reply #22 on: January 31, 2010, 11:59 AM »
1. The errors that he's had to bring to me are because of the indentation and the lack of implicit variable declarations
I suppose you mean explicit?

I'm still a firm believer that choosing indentation for blocks was a mistake - delegating checks to a 3rd-party tool instead of the language core doesn't really help. Same goes for not requiring explicit variable declaration (which, as mentioned previously, has nothing to do with static vs dynamic typing).
- carpe noctem

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #23 on: January 31, 2010, 09:31 PM »
Oops... yeah.  Explicit.  I found that really prone to causing errors on vb if you had the option for Explicit declarations off... and it's no different in Python.  And yes, considering that different editors indent in different manners- indentation sucks as a block method.

ajp

  • Participant
  • Joined in 2006
  • *
  • Posts: 22
    • View Profile
    • Donate to Member
Re: Python Language Annoyances
« Reply #24 on: February 09, 2010, 12:37 PM »
@Mouser:
Implicit variable declaration... I don't now. (Disclaimer: I am a Python fanboy of some sort but) I learned programming with Pascal and C, so I pretty much became used to the discipline of declaring variables. So, all my "relevant" variables get declared (well, initialized) in meaningful places. "Non-relevant" ones (i.e. counters that are used in a loop and don't get re-used later) I just use them as I go without taking much notice (which is sometimes convenient). Since I already have the mindset of "declarations go at the beggining of the block", it's simply natural and convenient at the same time. But I guess for someone who is using Python as a learning language, s/he must be taught of the importance of declaration for readability's sake.

As for indenting, if you and your teammates get to an agreement on tabs vs. spaces (I know, flame war's awaiting), it quickly becomes natural, and you won't miss typing { or } again in your life.

If I must rant about something, here it comes:
* "self". Yep, it's unelegant. It leaves the context clear and explicit, but it's ugly.
* unicode support. I guess in v3.0 it's better (haven't used it yet), but on v2.x, since I normally need "special" chars (I'm Mexican; accents are nothing sort of "special" in Spanish), it's a chore that simple read/write ops get polluted by unicode(x), x.encode('utf-8','replace') and so on.

Still, I love Python.