[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] replace tabs with spaces of Python code
On 5/19/05, Ian Pratt <m+Ian.Pratt@xxxxxxxxxxxx> wrote: > > > > there are many Python codes in tools/ that mix tab and space > > for indentation, which might introduce some silly and hidden > > bugs. this is a serious problem and must be avoid at all cost. > > > > here is a patch (against cset 1.1452) to replace all tabs with spaces. > > all the changes are pretty trivial, and i double checked everything. > > please take a look to see if all the modifies are OK. > > > > Signed-off-by: Nguyen Anh Quynh <aquynh@xxxxxxxxx> > > Are you sure python interprets a tab as a 4 spaces? I thought it > interpretted it as 8? i investigated all the related code (not quite many), and they all use 4 spaces to indent. and in the above message, i didnt say that i convert tab to 4 spaces, either. see below why. > > Hmm, there are a whole bunch of outstanding xend patches this this is > going to create merge hell for, so I'm not sure we want to apply this > straight away. > not many Python files mixed with tabs, and we can check to fix them all. this should be cosidered bug, so no matter how hard it is, we must fix it finally. we cannot avoid this. mixing tabs and spaces is a *very* serious problem, if you care. when i reviewed code in my editor (vim in this case), almost all lines which have tabs dont look right to me. some even mislead me, and only when i turn on the hidden chars (":set list" in vim), i realized that there were tabs inside. ouch! > Could you just post the script you used, or did you just do the obvious > sed invocation? > actually, i did this job manually, with little help from one small script. the reasons are: - as you said, it is very dangeurous to do this kind of thing automatically, so it is best to do it by hand - the number of related files are not that many (21 files with nearly 150 related lines of code) - some files use tab as 8 spaces, some use tab as 4 spaces, some even mixed 4 and 8 spaces (checking by seeing the code structure). so it is another reason not to do it automatically by a script. Ian, it is a mistake if you dont get this patch. besides, the patch is rather small, and you can check to see if it is OK. below is a trivial script i used to indentify all tabs, so i dont miss any thing. i post here, incase it is helpful for somebody. regards, aq #### #! /usr/bin/env python import sys, os def main(): for filename in sys.argv[1:]: if os.path.isdir(filename): continue data = open(filename, "rb").read() if '\0' in data: continue if data.find("\t") != -1: lines = data.split('\n') print filename n = 0 for l in lines: n += 1 if l.find('\t') != -1: print '\t', n, '\t', l if __name__ == '__main__': main() _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |