Thread: Classes
View Single Post
Old Apr 29th, 2005, 8:36 AM   #8
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
Quote:
Originally Posted by Sane
Adding and removing digits from the right would take just as much multiplication/division with strings as from the left.

Adding digit:
self.txt = int(str(self.txt) + str(random.randrange(0,10)))

Removing digit:
self.txt = int(str(self.txt)[0:len(self.txt)-2])
Erm... no - if you go from the right you don't need strings - a huge difference in beauty/brevity:
    def kill_digit(self):
        self.val //= 10

    def add_digit(self):
        self.val *= 10
        self.randomize()
Quote:
And why should it matter anyways, if the program really has no point, and digits are generally added and removed from the left. o_O??
Because good habits matter when your programs do have a point, and pretty code is generally easier to maintain/improve.

--OH.
hydroxide is offline   Reply With Quote