I am working at a medium-size semi-govermental organization managing subcontractors for software projects. One of our contractors recently turned in the "source code" for the project they had contracted. I strongly suspect that the code is auto-generated. This bothers me for several reasons (some of which are also mentioned in: Is source code generation an anti-pattern?). E.g.:

  • I suspect that the code is a lot larger than it could have been, had it been written manually
  • maintaining this code will accordingly be a lot harder
  • since this is not really source code, there are no comments at all (or only token, useless comments) and no effort was apparently made to come up with a meaningful organization of the code base (e.g. in terms of libraries, etc) that would have made sense to a human maintainer
  • the contractor is using this as a way to circumvent their obligation to surrender their source code to us and also with a view to securing future maintenance contracts as well (or at least enjoy an advantage over other bidders who won't have access to the real sources).

The contractor has also done a clever job of injecting some artificial randomness in the generated sources so as to give the impression that this was written by hand.

I feel that my employer / the taxpayer is being cheated by an unscrupulous subcontractor willing to walk on a fuzzy red line, betting that they've done something clever that can't be conclusively proved.

Is there a way I can detect and prove that this was automatically generated by some other software?

  • 2
    I think you are talking about obfuscated code, not (any) auto-generated code. I mean, sure, it is spit out by software. However, it appears they had done the work correctly and then have a software mangle it up. Some obfuscation tools have telltales that may indentify them. Yet, that would be an arms race, you become clever detecting it, and they become more clever making it. Code readability is hard to measure, yet, you might want to look into that.
    – Theraot
    Commented Feb 3, 2020 at 14:49
  • @Theraot; no the code was spit out by a tool, there is no obfuscation. Some randomness was apparently added in aspects like indentation etc. to make it look less regular.
    – humblemike
    Commented Feb 3, 2020 at 15:00
  • what do you think nin the input to the tool was?
    – Ewan
    Commented Feb 3, 2020 at 15:01
  • @Ewan some kind of in-house developed DSL
    – humblemike
    Commented Feb 3, 2020 at 15:03
  • 3
    I removed the reference to preventing this. Language for contracts need to come from experts in law, especially around contracts and isn't well suited for software engineers. However, detection of some code seems to be a good question since it does impact the maintainability of the product going forward.
    – Thomas Owens
    Commented Feb 3, 2020 at 15:10

4 Answers 4


I hope your company was clever enough to make a contract which does not only include the source codes, but also some terms about getting the code explained in case you want to change it by yourself in the future.

That might give you an opportunity to ask your contractor for an audit, where someone of yours does some pair programming for a few hours or a day with them. Such a session should be pretty enlightning.

It could be also a good idea to have a clause in your contracts (at least, for future contracts) similar to the one in the GPL which describes what kind of source code one has to publish under that license. It defines it as the preferred form of the work for making modifications to it (see here).

So if the source given to you does not effectively enable you to maintain the system later, this could be seen as a contract violation.


Our team recently had something similar and our salvation was the contract that our enterprise was with the contractor. Usually in that contracts have a clause that is about the quality of the code with tools like SonarQube and it was ours salvation. The contract had a clause about the code quality and all the boilerplate generated produced to not pass the quality umbral. After that, the contractor needed to send the original code to us.


Is there a way I can detect and prove that this was automatically generated by some other software?

I'm assuming the code is pretty repetitive. This isn't a given for generated code, but it matches the way you describe it.

Let's say there are two possible ways of generating this sort of code:

  1. Write (or license or whatever) an in-house codegen tool, and the input to it. Slightly randomize and then deliver the generated code.
  2. Get a competent developer to write one or two initial cases, and then have a room full of interns implement sections of a spec, piecewise, by copying and pasting those starting cases.

I can't think of a reliable way to distinguish between the two just from the code, unless you can ask to audit the SCM history. I wouldn't really even want to speculate on which is more plausible, or cheaper for the contractor: some problems genuinely lend themselves to lazy copy-pasting.

I said just from the code above, because the alternative is to either find the codegen tool they licensed, or find a whistle-blower to tell you about it.

In any case - ie, even if you do somehow prove the code is generated - your business case is with its quality and not with how that level of quality was achieved.

PS. code generation is definitely not an antipattern, but delivering (or even committing) generated code instead of the actual source definitely is.


There are legitimate cases for code generation, but if you are getting the equivalent of word docs saved as HTML what you are really looking for is a code quality measurement of some kind.

In my experience there really is no ways of automating this. Anything you put in (such as the suggested SonarQube) can be worked around with automation simply filling in the criteria to the lowest possible level eg.

// this method Retrieve Foos
public List<Foo> RetrieveFoos()

You should work with the contractor, make sure you own the source control and are involved in code reviews from stage one. But this really begs the question of whether you want to farm this out or keep it in house at all.

You could hire contract programmers to work under you rather than sending the project out, presumably the external company feels it can achieve more faster using its code generation and this is reflected in the price.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.