Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: Index format v5

From: Michael Haggerty <hidden>
Date: 2016-06-15 22:53:50

On 05/15/2012 12:10 AM, Thomas Rast wrote:
Michael Haggerty[off-list ref]  writes:
quoted
9. read_files() doesn't need to return "entries".  Since entries is an
array that is only mutated in place, the return value will always be
the same as the "entries" argument (albeit fuller).
(Ab)using an array in this fashion is somewhat iffy.  It seems
unavoidable in this case (while still retaining the runtime), but try
not to do it too often, and perhaps name the parameter something that
makes this clear (such as 'out').  Usually changing it to use a
generator function (with 'yield') helps.
If the goal were an ideal Python program, then by all means generators 
are the way to go.  But since the goal is a prototype for a C program, 
then a change to using generators would just have to be undone when 
converting to C.
quoted
11. It is good form to move the file-level code into a main()
function, then call that from the bottom of the file, something like
this:
quoted
def main(args):
     ....

main(sys.argv[1:])
It's customary to wrap it as

if __name__ == '__main__':
     main(sys.argv[1:])

That way your script becomes 'import'-able, which can be handy (if only
for testing).
+1

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help