2

Consider this:

int f(int x)  
{    
    return 2 * x * x;      
} 

and this

int squareAndDouble(int y)  
{    
    return 2*y*y;      
} 

If you found these in independent bodies of code, you might give the two programmers the benefit of the doubt and assume they came up with more-or-less the same function independently. But look at the whitespace at the end of each line of code. Same pattern in both. Surely evidence of copying. On a larger piece of code, correlation of random whitespace at line ends would be irrefutable evidence of a shared origin.

Now aside from the obvious weaknesses: e.g. visible or obvious in some editors, easily removed, I was wondering if it was worth deploying something like this in my open source project. My industry has a history of companies ripping off open source projects.

8
  • 8
    And what are you going to do, if you catch them?
    – pdr
    Dec 4, 2012 at 19:13
  • 27
    Don't all programmer set their IDES/editors/beautifiers to remove trailing whitespace?
    – user16764
    Dec 4, 2012 at 19:34
  • 1
    @user16764: Unfortunately they don't.
    – Giorgio
    Dec 4, 2012 at 19:46
  • 4
    There are more sophisticated and successful methods to determine source code similarity. Dec 4, 2012 at 20:39
  • 1
    @paperjam - If it's an open source project, though, you'd presumably need to let potential contributors know that you considered the number of spaces at the end of the line to be important information. Otherwise, most of the contributions will either strip off the white space or at least change the white space around making it difficult to reasonably claim a match. Or, I suppose, you could have an open source project where you don't allow anyone outside of your group to contribute but that seems counterproductive. Dec 4, 2012 at 22:40

5 Answers 5

20

Since "Trim Whitespace on save" is a feature of many IDEs, I don't think that this is good for anything.

18

First off, if someone rips off an open source project, presumably to create a closed source project, you are presumably not going to have access to the source of the closed source project without a lawsuit and enough evidence to get a court order to be able to examine the source code. That would tend to be a relatively high bar to clear before you can even get access to the source to compare the whitespace.

Assuming that you have the motivation to file suit and that you can gather enough evidence to suggest copying without using the source, though, it's not obvious to me how beneficial white space analysis would be. If this is a real open source project that is successful enough to steal, it's likely that the white space will change pretty regularly over time as people submit new versions of code so the "watermark" will change over time. If you're assuming that the company that is ripping off the code is going to the effort of changing variable names and the spacing of the meaningful source (which would make applying changes from the open source project very challenging), it seems likely that the company would quickly just add a step to remove trailing whitespace from their code.

Most companies (and developers) that steal code do so much more blatantly. They're just going to copy and paste the working code into their project and hit compile. They're not going to bother changing variable names or changing the name of a procedure or anything else that requires them to understand and test the changes. There will generally be much, much bigger smoking guns than the number of spaces at the end of the line.

6

No.

Whitespace is insufficient to demonstrate a watermark as you're suggesting.

Running the code through a style formatter that changes tabs to spaces or vice versa and part of your watermark has been changed. Additionally, based upon the style rules that are in place, trailing space could be truncated in order to comply with the style rule.

Presuming you could prove the "theft", what would you do? You've made the code open-source, so you're giving away the source code. And how would you gain access to their source code in the first place?

3
  • 2
    "You've made the code open-source, so you're giving away the source code.": Giving away the source code is only the first half of being open source. The second part is that it must remain so.
    – Giorgio
    Dec 4, 2012 at 19:49
  • 2
    @Giorgio - absolutely true. But the available mechanisms to enforce that are spotty at best. A degree of fatalism is required in a case like this.
    – user53019
    Dec 4, 2012 at 20:18
  • 1
    I think you are right. Maybe one solution could be to scatter a few back doors over your source code, so if someone does copy and paste without inspecting the code they are using you can hack into their software. :-)
    – Giorgio
    Dec 4, 2012 at 20:37
2

It could also be an indication of using the same crummy editor that doesn't clean up line endings.

I found a few thousand lines of un-commented assembly code in a project I was working on over a decade ago. I wondered at the time if that meant it was plagiarized code with the comments stripped out.

Ultimately, this is a legal question and the best answer is probably, "it depends on the jurisdiction." Copyright laws between the US and UK are similar, I don't know about other countries, and certainly there are additional difficulties if the copyright his held in one country and infringed in another.

Using patterns of spacing at the end of lines is an interesting idea though. Some editors (like IntelliJ and Emacs) will automatically truncate all trailing whitespace for you, so I don't know how effective it would be.

Here are Wikipedia's guidelines (not legal advice, just what works for them).

2

I don't believe it'll be of any good, if the platform/language uses an formatting system (like those formatters found in the Delphi/FreePascal ecosystem, the pretty-print feature of VB.NET, the C# formatter on VS, etc)...

So if the code had passed by those tools, and considering that the tool is on its default settings, all watermarking is gone.

Some editors even have features to remove whitespaces at the end of a line (I think that the expression is "trailing blanks" - english is not my first language).

If the platform/language developers does not make much use of IDEs with autoformatting features, the watermarking can - in theory - work.

But I would not put much faith on just that.

Your Answer

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

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