![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#12 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Well, not nasty, but y'know... if it's a simple app, I wouldn't overcomplicate it like that.
|
|
|
|
|
|
#13 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#14 | ||
|
Programming Guru
![]() |
Quote:
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:
|
||
|
|
|
|
|
#15 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#16 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
For instance: def all(s):
for x in s:
if x: return False
return True# ensure all values are less than 5 assert all(i < 5 for i in my_list) def count(s): return sum(1 for x in s) def all(s): return count(1 for x in s if not x) == 0 |
|
|
|
|
|
|
#17 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#18 |
|
Programming Guru
![]() |
My time? Important? :eek:
Pfft. ![]() |
|
|
|
|
|
#19 | ||
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
def give_data(data, info):
for i in range(len(info)):
print "What %s: %s"%( info[i], data[i] )Quote:
![]() |
||
|
|
|
|
|
#20 |
|
Programming Guru
![]() |
Hahaha, sorry. That's what happens when I get too used to one language over another (Turing).
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|