On Mon, Sep 22, 2014 at 7:00 PM, <vek.m1...@gmail.com> wrote: > One thing I noticed with that code was the size of your function, and > excessive comments. It reminds me of my bubble_sort.c program in > school/college - everything plonked into 'main'. > > Try writing it like this:
I'd like to see justifications for some of the advice you're giving here. Quite a bit of it I disagree with :) > 1. #!/usr/bin/python or #!/usr/bin/env python > > The leading #! is read by the kernel when it has to start the interpreter > (exec), so don't stick your comment in there. Very much optional. Even on Unix systems, it's not necessary unless you want it to be executable. > 2. Try to align the imports so they look pretty You mean adding extra spaces? Not advised. Or something else? Definitely needs more explanation (maybe an example) and justification (why do it?). > 3. Don't use whacking big functions and then stick endless explanatory > comments > Use the function name as a comment instead - divide your program up into > little tasks. Try to make the stuff generic - def url_extract(content, > pattern): > > def extract_url > > def extract_title > > def tk_init > > Use > #------------------------------------------------------------------- > to demarcate sections, very common functions go into a utility-library, > not so common functions at the section at start of the file, and so on.. If functions are defined and then called from exactly one place, there's no need to put them anywhere else. Just inline them. It's not as if the indentation is getting out of hand here - getinfo() tops out at just three tabs in, which is nothing. I've gone to seven a number of times, and there's one particular piece of code I have that goes as far as nine - though that's not something I'd recommend! Different people will put the limit at different points, but three is never going to be excessive. (Cue someone pointing out to me a situation in which three really is excessive, but sure, that'll be a fun spin-off thread.) > 4. Don't skimp on the sys.exit() or def debug (which should be in your > utilities lib) More explanation needed, please. What are you trying to do here? What would be different? > 5. Don't do :x = foo('.................................') > instead: > var_name = '..........................' # make it global > x = foo(var_name) Uhhh, why??!? > 6. To build a string do: > > param1 = xyz1 + xyz2 > x = foo(param1) Ditto. Why?!? ChrisA -- https://mail.python.org/mailman/listinfo/python-list