[Tutor] clock program critique

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 23 Mar 2001 13:44:48 -0800 (PST)


On Wed, 21 Mar 2001, Charles Gruschow, Jr. wrote:

> I think I got a final version of a clock program, it is in this post.

Hiya Charles,

I'll take a look at your program this weekend; from an initial glance, I
think there are a few things you can do to make it a lot shorter.  For
example, there's a lot of fragments that repeat other parts:

>         if self.time3==60:
>             self.time3=0
>             self.time2=self.time2+1
>         if self.time2==60:
>             self.time2=0
>             self.time1=self.time1+1
>         if self.time1==24:
>             self.time1=0

It's true that it works, but there's probably an easier way to write it.
For example, if you write a function to do this trickling-time
calculation, you'll only need to write this functionality once, instead of
have rewritten throughout your program.

Also, there's a lot of classes that you've written that take care of
displaying different times.  I think that it's possible to write one class
that unifies all of them into one general case, but I'll have to look at
your program in detail to see where generalization will work.

In the meantime, take a look at your program and see if there are places
where you can make things shorter.  Talk to you later!