Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Compare source code

Reply
Thread Tools

Compare source code

 
 
jf
Guest
Posts: n/a
 
      10-31-2010
Hi,

I've a project with tabs and spaces mixed (yes I know it's bad).

I edit each file to remove tabs, but it's so easy to make a mistake.
Do you know a tools to compare the initial file with the cleaned one to
know if the algorithms are the same ?
By comparing pyc files for example.

Thanks.
 
Reply With Quote
 
 
 
 
Martin v. Loewis
Guest
Posts: n/a
 
      10-31-2010
> I've a project with tabs and spaces mixed (yes I know it's bad).
>
> I edit each file to remove tabs, but it's so easy to make a mistake.
> Do you know a tools to compare the initial file with the cleaned one to
> know if the algorithms are the same ?
> By comparing pyc files for example.


Tools/scripts/reindent.py of the standard Python distribution normalizes
white space in source code. It is used to maintain normalized
indentation in the Python library itself, but you can certainly use it
also for your own files

Regards,
Martin
 
Reply With Quote
 
 
 
 
jf
Guest
Posts: n/a
 
      10-31-2010
Le 31/10/2010 13:10, Martin v. Loewis a écrit :
>> I've a project with tabs and spaces mixed (yes I know it's bad).
>>
>> I edit each file to remove tabs, but it's so easy to make a mistake.
>> Do you know a tools to compare the initial file with the cleaned one to
>> know if the algorithms are the same ?

>
> Tools/scripts/reindent.py of the standard Python distribution normalizes
> white space in source code.


So great, you save my time !
Should I be worry about this comment in reindent.py "So long as the
input files get a clean bill of health from tabnanny.py, reindent should
do a good job." ?

Thanks
 
Reply With Quote
 
Martin v. Loewis
Guest
Posts: n/a
 
      10-31-2010
> Should I be worry about this comment in reindent.py "So long as the
> input files get a clean bill of health from tabnanny.py, reindent should
> do a good job." ?


I don't think so: IIUC, this is about comments that are not reasonably
aligned with preceding or following code lines, most likely, you don't
have such comments in your files.

Regards,
Martin
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      10-31-2010
In message <4ccd5ad9$0$19151$>, jf wrote:

> I edit each file to remove tabs ...


expand -i <oldfile >newfile

> Do you know a tools to compare the initial file with the cleaned one to
> know if the algorithms are the same ?


diff -b oldfile newfile

 
Reply With Quote
 
Bob Martin
Guest
Posts: n/a
 
      11-01-2010
in 645437 20101031 230912 Lawrence D'Oliveiro <_zealand> wrote:
>In message <4ccd5ad9$0$19151$>, jf wrote:
>
>> I edit each file to remove tabs ...

>
>expand -i <oldfile >newfile
>
>> Do you know a tools to compare the initial file with the cleaned one to
>> know if the algorithms are the same ?

>
>diff -b oldfile newfile


meld
 
Reply With Quote
 
Peter Pearson
Guest
Posts: n/a
 
      11-01-2010
On Mon, 01 Nov 2010 12:09:12 +1300, Lawrence D'Oliveiro wrote:
> In message <4ccd5ad9$0$19151$>, jf wrote:
>
>> I edit each file to remove tabs ...

>
> expand -i <oldfile >newfile
>
>> Do you know a tools to compare the initial file with the cleaned one to
>> know if the algorithms are the same ?

>
> diff -b oldfile newfile


Warning: "diff -b" won't detect changes in indentation. Changes in
indentation can change a Python program.

--
To email me, substitute nowhere->spamcop, invalid->net.
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-01-2010
In message <>, Peter Pearson wrote:

> On Mon, 01 Nov 2010 12:09:12 +1300, Lawrence D'Oliveiro wrote:
>
>> In message <4ccd5ad9$0$19151$>, jf wrote:
>>
>>> I edit each file to remove tabs ...

>>
>> expand -i <oldfile >newfile
>>
>>> Do you know a tools to compare the initial file with the cleaned one to
>>> know if the algorithms are the same ?

>>
>> diff -b oldfile newfile

>
> Warning: "diff -b" won't detect changes in indentation. Changes in
> indentation can change a Python program.


I’m getting less and less keen on that particular feature of Python...
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      11-01-2010
On 2010-11-01, Lawrence D'Oliveiro <_zealand> wrote:
> In message <>, Peter Pearson wrote:
>>
>>> diff -b oldfile newfile

>>
>> Warning: "diff -b" won't detect changes in indentation. Changes in
>> indentation can change a Python program.

>
> I'm getting less and less keen on that particular feature of Python...


Why?

Other languages have similar problems if you remove salient bits of
syntax before comparing two source files files.

For exmaple, if you remove all of the curly-braces from two C source
files before comparing them, you don't get useful results.

--
Grant Edwards grant.b.edwards Yow! I'm continually AMAZED
at at th'breathtaking effects
gmail.com of WIND EROSION!!
 
Reply With Quote
 
Peter Pearson
Guest
Posts: n/a
 
      11-01-2010
On Mon, 1 Nov 2010 22:24:03 +0000 (UTC), Grant Edwards wrote:
> On 2010-11-01, Lawrence D'Oliveiro <_zealand> wrote:
>> In message <>, Peter Pearson wrote:
>>>
>>>> diff -b oldfile newfile
>>>
>>> Warning: "diff -b" won't detect changes in indentation. Changes in
>>> indentation can change a Python program.

>>
>> I'm getting less and less keen on that particular feature of Python...

>
> Why?
>
> Other languages have similar problems if you remove salient bits of
> syntax before comparing two source files files.
>
> For exmaple, if you remove all of the curly-braces from two C source
> files before comparing them, you don't get useful results.


True, but diff doesn't come with an "ignore curly braces" option.
I'm not personally repelled by Python's use of significant indentation,
but I must concede that some awkwardness results from assigning
significance to something (whitespace) that many tools are inclined
to treat as insignificant.

--
To email me, substitute nowhere->spamcop, invalid->net.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Compare source code Rustom Mody Python 7 11-07-2010 04:28 AM
Hot to compare source code with different multiling formatting? bad.skipper@gmail.com C Programming 3 02-04-2009 10:33 PM
Open source project on C++ to compare XML as ExamXML. alapick C Programming 1 09-23-2007 09:23 PM
Data Recovery SOURCE CODE ( SOURCE CODES of Professional Data Recovery Software ) Author Tarun Tyagi Cisco 0 12-29-2004 05:03 PM
need a tool to compare java source files alan jeeves Java 10 03-05-2004 02:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57