Black Friday is here! Get up to 30% off on Devart products!
ends in   {{days}}
Days
{{timeFormat.hours}}
:
{{timeFormat.minutes}}
:
{{timeFormat.seconds}}

Deep Text and Code Comparison

Overview

Code Compare provides a convenient and easy way to compare differences in text files side by side. Even in its default mode, it will accomodate for most of your basic text comparison needs. However, when you're working with code, some additional features are often needed to properly check for differences in lines of code due to the nature of the process. For the most efficient way to compare code files, you can utilize Code Compare's Lexical Comparison mode. It is specifically geared towards working with code files and recognizes most popular languages. Let's look at Lexical Comparison and its functionality in more detail.

Lexical Comparison

Lexical Comparison is primarily based on an algorithm that allows for better file comparison, sync and merge by detecting lexemes from major programming languages — namely C#, C++, JavaScript, Java, and Visual Basic — and comparing them with each other as single-pieces as opposed to detecting individual different symbols in lines. The Lexical Comparison algorithm chooses the programming language automatically based on the file extension. However, you can change this setting in the Language Combo Box on the toolbar. In this case, the chosen language wil be applied immediately. If you choose the Text option, the Lexical Comparison algorithm will be turned off altogether until you enable it again.

Language Combo Box

Below, we'll see examples of how Lexical Comparison is different from the default Text Comparison mode and how it can prove useful when you're working with code.

Lexical Comparison vs. Text Comparison

  • The Text Comparison mode in Code Compare can be inconvenient for source code comparison as it doesn't recognize language elements and looks for similar symbols in totally different lexemes.

    Text comparison algorithm

    With Lexical Comparison enabled, different lexeme types are never compared with each other.

    Lexical comparison - different lexeme types
  • With Lexical comparison enabled, Code Compare wiil always recognize and compare numbers wholly. You can see an example of this on the follwoing screenshot:

    Comparing numbers with Lexical Comparison Mode

    If you choose Text Comparison mode, the numbers will be compared digit-by-digit, which is very inconvenient in the context of source code comparison.

    Comparing numbers with text Comparison Mode

Additional Options

  • If you need Code Compare to ignore comments, you can turn this feature on in the Comparison options menu.

    Code Compare - Ignoring comments

    When this is enabled, the comparison tool will disregard any source code comments and highlight comment blocks as unchanged.

    Comments ignored

Editing Compared Texts

When you compare two files or diff text in Code Compare, you can also utilize the provided text editor functionality with syntax highlighting and various other features.

  • Selecting Text and Code: You can select both continuous segments of code with SHIFT+arrows/mouse or rectangular sections with ALT+mouse
  • Manipulating Text and Code: Code Compare has the basic text manipulation capabilities such as an overstrike mode accessible with the INSERT key
  • Navigating Text and Code: In addition to the usual mouse-and-keys navigation method, you can create bookmarks, use incremental search and utilize Go To Line commands
  • Indenting text and code: You can adjust code indenting by using the Decrease Line Indent or Increase Line Indent options
  • Searching and replacing text: Code Compare allows to search and replace text both in the current file and in multiple files at once

For more details on the major feature set of our file diff and merge tool, feel free to refer to the main Code Compare page.