tags:

views:

274

answers:

8

In most cases, it seems that instead of writing their own code, programmers copy code from any available website and use them in their application.

Is it good for a developer?

I believe this habit dumps the developers.

Is it wise to follow this habit?

+2  A: 

Do you mean code from a code sample or code taken from another site (E.g., with "view source")?

The latter can easily create a copyright issue so you have to be careful about it.

The former is acceptable. However, the code you copy may be:

1) Incomplete and buggy, and you'll miss on future maintenance

2) Not fully adapted to what you need

3) Not sufficiently secure.

And of course, you may not understand everything about the code, especially if you don't understand the underlying API.

Uri
+12  A: 

It depends with what the developer does with it.

If a developer copies and pastes the code, then studies it, picks it apart, and tests it for flaws, it's actually a good study technique.

Even as I'm a senior software developer, whenever I need to code for a part of the framework that I haven't touched before, I mostly rely on code that I see online, read it up and write tests for it.

But if a developer just dumps it in his codebase and then leaves it (much like, fire-and-forget missiles in combat) it becomes very dangerous.

A good programmer will always try to recognize the context in which code is written: the purpose of the original code author would most likely be different from your purposes, even slightly. Unstudied code is almost like cancer, where all sorts of bugs will come from without you understanding why.

Jon Limjap
I like this technique... this is what I do sometimes. Very useful to test it in parts than as a whole to understand what it does. "Divide and conquer". +1
jasonco
+8  A: 

It's OK to copy code so long as:

  1. You have the rights to do so ie you're not infringing on the license, copyright, etc of the code owner; and
  2. You understand what the code does, hwo it works and its limitations.

If you copy code you don't understand you're just asking for trouble. Unfortunately there is a lot of this going on.

cletus
A: 

The legal, ethical and technical implications are far too great to be undermined. It is okay to use code which is in public domain and for which the author has explicitly granted permission. If however, the author has a license, you ought to respect it and add attribution and follow the licensing rules. Also, check out with your comapny's legal department with what you can and what you cannot use.

As a programmer, it adds value to imbibe the sense than go by the letters. You'd then be better prepared to handle bugs in that particular piece of code. Reading others code is always a good idea -- using them is a totally different issue.

dirkgently
A: 

I wont consider legal issues here.

What differentiates most sample code from production code is adequate error handling. Also, make sure any assumptions made in the sample apply to your environment too.

sandesh247
+3  A: 

Sometimes effective! but not so self-satisfying as the self-coding could be.

Sepehr Lajevardi
A: 

I think that it is okay to copy code from the web if

  • it saves you some time because you do not have to reinvent the wheel once again
  • the code is free
  • the code has been proven and tested
  • you have understood the code
koschi
A: 

Everything that you find online is copyrighted by default, unless explicitly stated otherwise. You may not copy anything, neither content, nor design, including all imagery, pages markup and css.

You may however read code samples to understand how to do the tricks and then integrate it into your application. By integration I mean not copy/pasting but using the technique. Since most techniques are defined by a respective technology, its implied ways of use and its limitations, it is hardly possible to copyright them.

For example you can't copyright "your way of creating a 1px black solid border for a div container" since css with all its bells and whistles is offered to everyone. The same likely goes for more complicated techniques since they're just application of various css features.

From the technical point, you should definitely understand how a certain code piece works. If you do not, you're likely not be able to adapt it to your project. If it is coincidentally workable without any changes it is a matter of luck.

I know there are some people who really copy and insert things into a project because they're incapable of understanding or learning even quite simple things (even IT graduates with diplomas), but I do not believe such an occasional person would survive for long in the development branch (if it manages in at all).

User