Pop is a new code search tool for Mac aimed at students and other coders who are learning a new programming language or API.<p>In the marketing we're trying to walk a narrow line between encouraging people to look at existing code and learn from it, without encouraging plagiarism. (http://etia.co.uk/pop/about/)<p>Say I want to calculate the interval in seconds between two timestamps, and I'm getting an error on my line of python code:<p><pre><code> start_time = datetime.now()
</code></pre>
If I search for uses of datetime in some open source code
and find this:<p><pre><code> start_time = datetime.datetime.now()
</code></pre>
I might learn that the now method is in a subpackage of datetime, itself called datetime. This fixes my problem, and I think that's ok because I've learned where the now() function is in the package namespace, rather than copied anything.<p>On the other hand if I see code like this<p><pre><code> (datetime.datetime.now()-start_time).total_seconds()
</code></pre>
I've learned that I can subtract results of datetime's now method and that whatever kind of object I get back has a total_seconds method. But I'm a bit less comfortable. Any code I write is reusing the algorithm even if my code ends up with different variable names and splits this logic over additional lines. On the other hand algorithms aren't patentable, so maybe it's ok to use the algorithm.<p>We don't seem to talk much about this. I'm convinced we can learn a lot from looking at other peoples' code; architects don't avoid looking at other architects buildings, and authors don't avoid reading other authors books. It's surely a good way to learn best practice.<p>Do HN'ers look at other people's code? Where do you draw the line?
I think you confuse software development with I don't know what.<p>All the time we look at other peoples code. See Stackoverflow. If it is only a couple of lines that is also not plagiarism, that is code reuse which in software is encouraged (see DRY principle).
If you can take some code (as is) and just change some params that is just using a library or a framework. And libs are usually free to use if they are publicly available. If you just copy the library and say its your work that is plagiarism.<p>In Software we don't just look at code we take snippets and reuse them (ALL THE TIME), like an architect snipping a windows design out of someone else's plans and reusing them. A couple of lines of well written clean code should be reused. Don't write your own interpretation. Either you have a better cleaner version or not.
Knuth has an interesting take on this, as he learned by reading programs. He claims if the programs he first saw were too good, he wouldn't have bothered with programming:
<a href="https://github.com/kragen/knuth-interview-2006/blob/master/README.md" rel="nofollow">https://github.com/kragen/knuth-interview-2006/blob/master/R...</a><p>"I read the manuals that came from IBM, and it had; the manuals had example programs in there, and I thought of better ways to write those programs. I thought of, you know, well, okay, this program works, but if you did it this way, it would be even better. And so that’s given me some confidence that maybe I had a talent for programming. Now, if the manual hadn’t had these bad examples in it, I probably would not have gotten interested in programming, because I wouldn’t have this confidence, and I would have been scared and say, oh, I would never think of this.But the fact is, the manuals were pretty stupid, and that’s what gave me the confidence that I should think a little more about programming, because I might be, you know, I might be good at it."
This is an extremely grey area that honestly comes down to the patent laws of your country, the uniqueness of the code you're reusing or porting, and your intended use for that code.<p>This is where it becomes important to use open licenses on public projects, as it lets people know "It's okay to use this code" instead of simply putting the source out there and leaving it's intellectual ownership as an ambiguous question.<p>In my opinion, there is nothing wrong with using code from others' projects or works as long as you're educating yourself or, if used commercially, your use of said code is solving a different problem than the project you took it from. This is just an opinion with no real consideration given towards legal implications.
For personal projects, anything is fair game. Once you're actually distributing your program/library to users, I think attribution for any non-trivial/non-standard snippets or algorithms is a good look (just in the form of in-line comments, possibly in the header comment block). As long as the licensing works out (for example, GPLv3 snippet in GPLv3 project, or CC/MIT in a permissive open project), I see no problems there. Obviously, for closed source or otherwise restrictive software projects (especially when working for an employer), things get more complicated. While you won't likely get caught or called out for lifting a chunk of code off Stack Overflow (which I believe defaults to the MIT license), it's worth reconsidering.<p>But as far as looking for inspiration in other people's FOSS code? Morally that feels like very fair game. Again, attribution would be nice for an actual algorithm.
Reading code is essential to growth as a programmer. I do it all the time, often for pleasure. But reading snippets without context, like you're suggesting, is a common source of bugs in my experience.<p>So often when working on a legacy codebase, I'll track down a bug to some bit of code that makes no sense, and then search for that code and find it on Stack Overflow or similar. Even examples from documentation can be dangerous taken out of context; I can think of numerous times I encountered this with snippets that had been copied directly from MSDN without understanding.<p>Given that poorly-understood code reuse was implicated in many of our industry's greatest disasters, maybe the legality isn't what our concern should be here.
If you are going to be looking at code a lot more than you are going to be writing it. In most cases you will be looking at code in attempt to ascertain a larger pattern that is being used in a code base so you can follow suite. Looking at code to see how a library is actually used will be the least (very least) of your worries and will become super second nature.
i generally avoid looking at other peoples code unless 1) it's written for teaching purposes and aims to teach a concept I want to learn or 2) I have to because i'm having integration problem<p>I think looking at well-written code is a great way to learn best practices, but I think it's quite hard to do that in practice and probably not the best way.<p>there's a lot of garbage code out there and even if the code is good, often times you find that it's super out of date (using an old ass version of a language) or the logic is pretty obfuscated by unessential (to you) backwards-compatability / cross-platform compatability checks.<p>there's also a great deal of context around the intent of blocks of code that you don't have when looking at open source code in isolation in the example you gave. Some lines might seem like nonsense until you read the PR and understand the tradeoffs made at that point in time.
Generalizing, but I draw the line between<p>> "Oh, I didn't think of doing it that way but it makes perfect sense!"<p>and<p>> "Uh... Does this do what I want? Guess I'll just copy/paste and see if it works"<p>In other words, if you see something and understand what it does and how it does it, then I don't consider it plagiarism.
I believe code should be freely shared, and in general (although there must be some upper-limit), the concept of "code plagiarism" is a non-starter for me.<p>With that said, I would hope that in general people would not copy and paste code. Follow along, write the code, and understand how it works.