Here’s a quick statistic for you: on average 28% of all Cobol lines written are comment lines. This number is based on the analysis performed by Anubex’ tools on millions and millions of Cobol application code lines from different customers coming from all over the globe.

That’s nearly 1/3rd of the entire application code base! Of course, this is a good thing, having well documented code is in general a good practice. Comments are used to document the program, remind programmers of what they did (or intended to do) and they help future generations of developers to understand and maintain the code. They often contain a revision history of the application and are undoubtfully the biggest asset when it comes to increasing readability, maintainability, and reducing development time.

Needless to say, when it comes to CodeTurn for Cobol to Java or C#, dealing with those comments in an intelligent manner is a key factor of the solution. While comments may seem like nothing more than a minor linguistic detail of a programming language they do create new and significant challenges when trying to convert them from one language to another.

In comparison converting a regular Cobol statement is fairly easy, it’s clear what the converted statement should do and it’s objectively described in the language specification. Comment lines on the other hand are of a more subjective nature. Their placement in the code, their contents and the context in which they are used are pretty much dependent on the individual style of the developer or the general guidelines within the company.

As a result, the conversion of comments begs for a different approach at conversion time. There isn’t always a 1-on-1 mapping and comments can be moved around or grouped together depending on where they make the most sense. Because we not only just want to preserve all the comment lines, but also want to place them as close as possible to the element they refer to, Anubex has developed a set of intelligent algorithms to ensure this valuable part of your program is still right there in the converted program when and where you need it.

Thanks to detailed analysis and these algorithms we can:

  • create relevant class header comments, including structured comment tag lines,
  • create standalone copybook class comments, or expand those comments at the correct position in the main class if needed,
  • map paragraph and section comments to their relevant target methods,
  • map all comments related to files (file description, select clause, …) to the target file class,
  • map all comments related to working storage, linkage and other sections to the target structures,
  • keep all statement, data item, declarative and specialname comments and map them to their correct target equivalents.

Please find below the following three relevant examples of how CodeTurn automatically converts the comments.

Original Cobol code:

Equivalent Java code:

Equivalent C# code:

Original Cobol code:

Equivalent Java code:

Original Cobol code:

Equivalent Java code:

As previously said, comments are very subjective, which is why CodeTurn also provides different configuration options to tweak the final result to your specific preferences. As such it could be possible to selectively ignore comment areas, or append them as continuation to previous comment lines. Or ignore certain comments which can be considered irrelevant (for example lines entirely consisting of *-characters). The possibilities there are endless.

Unfortunately, there is no rule that can be made that determines the correct association for every possible case, additionally there might not always be a good place in the target language syntax to place the comment (for example in case of dead code where the target method has been cleaned up in the generated code). Review of our current conversion projects, reveals that CodeTurn successfully associates 97% of all comments to relevant target elements in Java/C#. The remaining 3% is mostly limited to either plain separator lines or comments which no longer have a corresponding element on the target side. Of course, such unhandled comments are not simply discarded in the conversion. Instead, they are cleanly generated at the end of each source file in a dedicated overview which also contains the original source line number for future reference. This way they can still be reviewed and 100% of all comments are preserved after migration.

If you liked this article or wish to receive more information, just leave us a quick comment (pun intended).