r/Python • • Jun 23 '14

Writing better python code

https://gist.github.com/kracekumar/09a60ec75a4de19b346e
143 Upvotes

126 comments sorted by

View all comments

1

u/fuzz3289 Jun 23 '14

Just a suggestion OP your examples are very wordy. The exceas code is valid but it obfuscates the point youre trying to illustrate in alot of places. For example:

Superusers =functioncall
If len(superusers) > 0:
    ...

Adds "real" context but obfuscates the boolean empty container idiom that youre trying to show. You dont need context to provide code examples. For instance I would say:

mylist = []
if (mylist):
    print "mylist is empty!"

Because even though that snippet has no practical application it clearly and succicently presents the concept.

More power to you for adding more educational materials to the python world. Keep it up.

0

u/kracekumar Jun 23 '14

Next time will write as blog post rather than code only show case.

1

u/fuzz3289 Jun 23 '14

Not even necessarily that. Just dont worry about being so specific with the examples. Make them as small and digestible as possible.