Re: Index format v5
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- May 15, 2012, 06:43 UTC
- Message-ID
- <4FB1FB11.70209@alum.mit.edu>
- In-Reply-To
- <87bolqtnva.fsf@thomas.inf.ethz.ch>
On 05/15/2012 12:10 AM, Thomas Rast wrote:
Show 10 quoted lines
> Michael Haggerty<mhagger@alum.mit.edu> writes: >> 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.
Show 16 quoted lines
>> 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: >> >>> 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/