Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 17th, 2005, 3:36 PM   #11
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Sane I looked over your code, thats the sort of way I need to be thinking about my code, such as the get_data() function
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Nov 17th, 2005, 5:08 PM   #12
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Well, not nasty, but y'know... if it's a simple app, I wouldn't overcomplicate it like that.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 17th, 2005, 5:46 PM   #13
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Bear in mind that functions should generally do one thing and do it well. The fact that get_data collects data but also writes and reads to the console makes it seem a little sloppy, plus the fact that the methods are ~two lines long implies that they shouldn't be methods. Seems a little like you've taken a simple program without functions and just sliced it up to use them.
Also, why do you pass `info` to `main` when `info` is already a global?
Cerulean is offline   Reply With Quote
Old Nov 17th, 2005, 6:57 PM   #14
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Quote:
Originally Posted by Cerulean
Seems a little like you've taken a simple program without functions and just sliced it up to use them.
I did that to organize ideas.

It's a good idea to get in that habit for when you really need it.

But the main function is needed to make it cleanly recursive.

Also, I keep in mind I've seen professional code with one line functions, just for the sake of organization in a giant class.

Quote:
Originally Posted by Cerulean
Also, why do you pass `info` to `main` when `info` is already a global?
It's a coding habit I guess.
Sane is offline   Reply With Quote
Old Nov 18th, 2005, 10:58 AM   #15
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

You are on the way to Python Nebula!

Just a hint, since you don't do any calculations with your numeric input, keep 'em all strings and use only raw_input().

The input() function has a nasty habit, it actually uses raw_input() and then converts the value to a number with the eval() function. This function is much too general, since some nasty person could tell it to erase your hard drive and it would do it!!!!!! It's much saver to use raw_input() and then process the string to a number in your code with one of the less general functions available.

Let's not forget, Python was developed to be readable, at least compared to Perl code!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 18th, 2005, 2:04 PM   #16
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Cerulean
plus the fact that the methods are ~two lines long implies that they shouldn't be methods.
Not if these those methods prevent you repeating yourself, or make the code clearer.

For instance:
def all(s):
   for x in s:
      if x: return False
   return True
This is a small function, but terribly useful, as you can use it to check whether any object fails a condition in a sequence:
# ensure all values are less than 5
assert all(i < 5 for i in my_list)
Indeed, one could go further and just use one-liners:
def count(s):
   return sum(1 for x in s)

def all(s):
   return count(1 for x in s if not x) == 0
Arevos is offline   Reply With Quote
Old Nov 18th, 2005, 4:24 PM   #17
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Of course, and there are obvious merits in boosting readability, but is it really necessary in something like this? I think it qualifies as a waste of important time.
Cerulean is offline   Reply With Quote
Old Nov 18th, 2005, 8:02 PM   #18
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
My time? Important? :eek:

Pfft.
Sane is offline   Reply With Quote
Old Nov 19th, 2005, 3:09 AM   #19
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Sane
def give_data(data, info):
    i = 0
    for i in range(len(info)):
        print "What %s: %s"%( info[i], data[i] )
        i += 1
Shouldn't this be:
def give_data(data, info):
    for i in range(len(info)):
        print "What %s: %s"%( info[i], data[i] )
...?

Quote:
Originally Posted by Cerulean
Of course, and there are obvious merits in boosting readability, but is it really necessary in something like this? I think it qualifies as a waste of important time.
Well, it teaches good programming structure, which is always useful
Arevos is offline   Reply With Quote
Old Nov 19th, 2005, 9:31 AM   #20
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Hahaha, sorry. That's what happens when I get too used to one language over another (Turing).
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:26 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC