Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old December 20th, 2003, 06:23 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #17  
Old December 20th, 2003, 06:25 AM
sissy sissy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 29 sissy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 25 sec
Reputation Power: 0
id say that i would have to agree with netytan

Reply With Quote
  #18  
Old December 20th, 2003, 08:08 AM
lazy_yogi lazy_yogi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 325 lazy_yogi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #19  
Old December 20th, 2003, 12:50 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #20  
Old December 20th, 2003, 04:39 PM
lazy_yogi lazy_yogi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 325 lazy_yogi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #21  
Old December 20th, 2003, 06:41 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.
Attached Files
File Type: pl yogi.pl (693 Bytes, 440 views)

Reply With Quote
  #22  
Old December 20th, 2003, 09:46 PM
lazy_yogi lazy_yogi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 325 lazy_yogi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
Lightbulb

Quote:
Originally posted by lazy_yogi
Sure, if you just do
&nbsp;&nbsp;i++
then its fine. The problem is when doing something like
&nbsp;&nbsp;j = k++ + ++i
&nbsp;&nbsp;i += ++k
&nbsp;&nbsp;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

Reply With Quote
  #23  
Old December 21st, 2003, 09:15 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #24  
Old December 21st, 2003, 12:54 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #25  
Old December 21st, 2003, 10:33 PM
theperfectsoup theperfectsoup is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 35 theperfectsoup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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:

Code:
del x


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

Reply With Quote
  #26  
Old December 22nd, 2003, 01:24 PM
ragabash ragabash is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Yuma,AZ
Posts: 11 ragabash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to ragabash Send a message via Yahoo to ragabash
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]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > discussion - possible improvements in python

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap