The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Page 2 -
discussion - possible improvements in python
Page 2 - Discuss discussion - possible improvements in python in the Python Programming forum on Dev Shed. discussion - possible improvements in python Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 20th, 2003, 06:23 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
On the contrary i dont see the problem with increment decrement operators (++ --). Most other languages have both i.e. C/C++, Java, Perl, Ruby and PHP to name a few!
And I myself definatly wouldnt say that this is bad design principles!!!
Anyway i've asked friends about this one and the general feeling is that num++ is considerably cleaner and is defiantly a valid shortcut for num+=1
Mark.
__________________
programming language development: www.netytan.com – Hula
|

December 20th, 2003, 06:25 AM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 29
Time spent in forums: 2 h 48 m 25 sec
Reputation Power: 0
|
|
|
id say that i would have to agree with netytan
|

December 20th, 2003, 08:08 AM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
|
ah well, each to their own I guess
I don't see i++ to be cleaner coding to i += 1. I think it's much the same.
The main point i was trying to get through is that accessing and modifying a variable in the same statment makes for unclear code. Maybe not if doing it once, but after a few times in the same method, it becomes difficult to follow the algorithm.
Sure, if you just do
i++
then its fine. The problem is when doing something like
j = k++ + ++i
i += ++k
j = --k + i++
A few more statements like this beomes a real pain in the arse to be clear on how the variables end up.
|

December 20th, 2003, 12:50 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
indeed  , not very clear at all... but Ele, why would you ever ever do anything like that unless you had to lol.
obviously there is a place for increment and decrement operators i.e. while loops. How does showing where you could but SHOULDN'T use them make your point more valid
i'm sure any of us could write really ugly lookin code without much effort  , all be it harder in python.
this version may be slightly longer but its a hell of alot clearer
i = 1
k = 1
j = k + i + 1
++k
i += k + 1
j = k - 1 + i
++i
add that to the how often do you see maths like this in programs factor and i cant see how increment and decrement operators can be such a bad thing!
P.S. like-wise on the bitch thing Ele; i'm just trying to get a point across, not fight with you
Mark.
|

December 20th, 2003, 04:39 PM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
yea I know u wouldn't say something to intentionally offend.  <== dun know why I used this emoticon, but he looks cool neway
yea I have mixed feelings on this.
I do prefer the the modifying and accessing together in the while statement - probably cuz it's a shortcut convention from other languages that I learnt first and got used to (and uses one less line of code). But on the other hand I still think keeping getting and setting of a variable seperate is important.
heh .. and just to show that ++ is complicted when used outside the while loop convention, you didn't do a correct convert over when you seperated out the accessing and the modifying
it should have come out as :
i += 1
j = k + i
k += 1
k += 1
i += k
k -= 1
j = k + i
i += 1
But yea, it does seem more elegant in a while loop.
Tho, alot of times where you would use this while loop situation (ie when iterating), you can use a for loop (ie 'for i in blah'), which is the 'python way'
Eli
|

December 20th, 2003, 06:41 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Actually we were both wrong  , neither my example or yours worked the same as the first example
Check it.. this (attached) is writen in perl simply because perl supports all the operators needed, doesn't need to be compiled, and i know you've used perl
Glad your comming around to the idea Yogi
Mark.
|

December 20th, 2003, 09:46 PM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
Quote: Originally posted by lazy_yogi
Sure, if you just do
i++
then its fine. The problem is when doing something like
j = k++ + ++i
i += ++k
j = --k + i++
|
ahh .. I was right actually .. I just didn't include the i++ from the 'simple' version in above
Those dollar signs make it damn hard to read after you're used to nice python syntax ...
Eli
|

December 21st, 2003, 09:15 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
naw, i beg 2 differ  .. the final result may be the same but the several of the step are out of wack even with the i++ so its not really a true conversion
I totally agree, $var is not well messed up!!! So glad i don't have to touch to much perl anymore.
Mark.
|

December 21st, 2003, 12:54 PM
|
 |
Wacky hack
|
|
Join Date: Apr 2001
Location: London, England
Posts: 513
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
|
|
The thing I really want is for Python to get a really decent extended library like CPAN for Perl. Parnassus and PYPI exist, but they're very small and feature a lot of modules that do fairly similar things and nor particularly well. In particular, I'd like to see far more well implemented Python bindings to various technologies, and in particular wrappers to programs and libraries that would mean we could stop having to use nasty hand-rolled system calls quite so much.
Of course, we can do a lot towards this by just making handy modules distutil modules and submitting them, but still :roll:
Compiled bytecode would be lovely 
|

December 21st, 2003, 10:33 PM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 35
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
The two items on my Python wishlist...
1) If you run the following code:
Code:
for i in xrange(1, 10000000):
x.append(i)
... you use up quite a bit of memory. But if you then do:
... you don't get it all back. In fact, for larger arrays, you only get a very small fraction. But if I use class array, dubbed "Efficient arrays of numeric values," when I run the above code for larger integer arrays, I get all my memory back. (I'm sure this is because class array is based on an underlying C module, and in C you can always depend on getting back all the memory you claim.) You might argue this renders my above gripe as a moot point, but class array does not support bignums, or arbitrary-precision long integers, like native Python does. My only option: stick with Python and use gobs of memory, or do the underlying code in C and link it from Python. I took the latter route.
2) I'd like nested assignments in while loop headers. Let me paraphrase with some pseudocode. In C/C++ you can do stuff like:
Code:
fd = open("xyz.txt")
while ((buffer = fd.read(256)) != NULL)
process(buffer)
In Python you do:
Code:
fd = open("xyz.txt")
buffer = fd.read(256)
while (buffer != NULL):
process(buffer)
buffer = fd.read(256)
I know it's just aesthetics, really, but I wonder why it can't be done.
- theperfectsoup
|

December 22nd, 2003, 01:24 PM
|
|
Junior Member
|
|
Join Date: Aug 2003
Location: Yuma,AZ
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
According to the python manual:
Quote:
Note that in Python, unlike C, assignment cannot occur inside expressions. C programmers may grumble about this, but it avoids a common class of problems encountered in C programs: typing = in an expression when == was intended. |
It trips me up everytime I come back to python.
-rag
Quote: Originally posted by theperfectsoup
The two items on my Python wishlist...
2) I'd like nested assignments in while loop headers. Let me paraphrase with some pseudocode. In C/C++ you can do stuff like:
Code:
fd = open("xyz.txt")
while ((buffer = fd.read(256)) != NULL)
process(buffer)
In Python you do:
Code:
fd = open("xyz.txt")
buffer = fd.read(256)
while (buffer != NULL):
process(buffer)
buffer = fd.read(256)
I know it's just aesthetics, really, but I wonder why it can't be done.
- theperfectsoup |
[/QUOTE]
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|