There are plenty of comparison tools that allow multiple users to effectively manage, accept or reject their changes when collaborate over source code written in CSharp, Java, Python, Ruby and other programming languages. Most part of such tools are desktop applications that are free or paid, provide powerful set of features, have their pros and cons, but all of them assume you will compare files manually.
Let’s review some common use case when you need to review two versions of C# (CSharp) source code file edited by two different people and chose the proper variant for each edited code block. Please check source.cs and target.cs files that we are going to compare at the image below.
As we can see there are multiple differences between compared files:
class names are different - CropImage vs ImageCropTests;
Test1 method is not present in a target.cs file;
Bitmap image path was changed in Test2 - input.png vs original.png;
Start method was renamed to Launch and its content was also modified - Test1 method call removed;
some empty lines removed etc.
The image below demonstrates all mentioned changes detected by some of desktop comparison tools. It works just fine, all differences detected and highlighted in a user interface.
However sometimes you may need some features that existing comparison tools do not provide, or you want to implement comparison process in your own way. Then you will definitely need a possibility to compare documents programmatically and manage discovered changes via code. This is where GroupDocs.Comparsion features will come to the rescue, so lets see how to compare source code files with it.
Compare CSharp, Java, C++, JavaScript, Python and Ruby files using GroupDocs.Comparison
Using GroupDocs.Comparsion API you are able to compare two or more source code files, detect differences between them and then decide what to do with every detected change - accept or discard it before saving the resultant document, generate HTML report with comparison results etc.
In general you have to follow these steps to compare two source code files (please find other supported formats list here):
Instantiate Comparer object with source document path or stream;
Call add method and specify path target document path or stream;
At this stage you is able to save comparison report in HTML form and review it. If you need to programmatically obtain collection of detected changes for further processing you have to:
Call getChanges method and obtain detected changes list;
Along with full-featured Java library we provide simple, but powerful free Apps.
You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSGand other documents with free to use online GroupDocs Comparison App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.