46

Overall I'm in programming for about 8 years now and it seems to me that I'm relying more and more on open source libraries and snippets (damn you GitHub!) to "get the job done". I know that in time I could write me own implementation but I like to focus on the overall design.

Is this normal (non corporate environment)? What could go wrong if my "programming" is nothing more than gluing different libraries together?

I know about "don't reinvent the wheel" but what happens when you don't invent a single wheel anymore?

durron597
  • 7,590
  • 9
  • 37
  • 67
Henrik P. Hessel
  • 885
  • 1
  • 8
  • 13
  • 3
    Did you mean "non *corporate* environment", or an environment where people don't *cooperate*? – Bryan Oakley Jul 18 '11 at 19:29
  • I thought the reason we write in interfaces and abstract classes is so our libraries are more universal, less dependent, more flexible ... – IAbstract Jul 18 '11 at 20:03
  • 1
    So bad, as a matter of fact, that Father's belt is coming off. – Thomas Eding Mar 27 '13 at 18:48
  • Just remember to pay homage and give credit where credit is due. If you ever claimed that code as yours, then *The Belt* definitly – hanzolo Mar 27 '13 at 19:03
  • Heavy library and code snippets (from great programmers) usage makes scopes to be great programmer. Because by usage, we can learn from them practically. – Md Mahbubur Rahman Mar 28 '13 at 12:17
  • 3
    No, it doesn't make you bad programmer, but it doesn't make you a better programmer either. –  Mar 28 '13 at 13:03
  • 1
    I've been feeling this lately - I remember writing sorting algorithms in C++ using GCC, and feeling really satisfied when I echoed a sorted array to the console. Although I'm still programming, that feeling of "man, I just built something awesome from the ground up" isn't quite there anymore. –  Jul 02 '13 at 16:30
  • see also: [Does software reuse preclude process repeatability](http://programmers.stackexchange.com/q/204807/31260) – gnat Jul 17 '13 at 12:44

16 Answers16

89

Using libraries instead of reinventing the wheel: Great! That's how everybody should do it. You don't get paid to do what's already done.

Using snippets: As long as you understand what you copy-paste, and as long as you invest the time to make it all consistent (instead of a patchwork of different styles and approaches), there is nothing wrong with it.

user281377
  • 28,352
  • 5
  • 75
  • 130
  • That's what I thought. Maybe I should start an open source project to get rid of this feeling :) – Henrik P. Hessel Jan 06 '11 at 08:49
  • 26
    +1 from me. People should never use code that they don't understand. That goes for snippets and libraries. – Tim Post Jan 06 '11 at 08:52
  • 6
    As far as snippets go I always rewrite the code myself just so that I'm confident that I know how it works. Libraries, I never rewrite unless it doesn't work for me for whatever reason. – Rei Miyasaka Jan 06 '11 at 12:29
  • 13
    Tim: Regarding libraries, I don't have to understand *how* it does something, as long as I know *what* it does. For example, many of us use crypto libs; I don't know how AES works, but I know what it does and when to use it. – user281377 Jan 06 '11 at 13:38
  • @Rei Miyasaka It seems that Snippets are often of less quality than a standalone library. I, myself, got to refactor several part of snippets I used. – Henrik P. Hessel Jan 06 '11 at 14:34
  • @ammoQ - No, you don't have to be able to understand those kinds of algorithms, but you need to know what the operands they are using actually do :) – Tim Post Jan 06 '11 at 17:15
  • Snippets should be used internally to a team to convey a common set of guidelines and best practices. It is far better to create a common modus-operandi in the team than having everybody running on his own direction! So, let's use snippets! And while using them, the developer can LEARN how to properly do a certain kind of task, so that his knowledge is enriched without pying the cost of try and error. – Cristiano Ghersi May 16 '14 at 06:24
  • @user281377 it's not possible to understand what something does without first understanding how it is done. To think so is delusional. For example, the creator might have lied in the documentation, or there might be indocumented bugs or edge cases you never read about. Knowing the code is the only way to know what it does. – Juan Perez Jun 02 '23 at 15:22
  • @JuanPerez In many cases, it's not problem to understand what the code does. For example, if I have to make a java program that listens on a TCP port, but can't remember how exactly it's done, the snippets I find on Stackoverflow or elsewhere will show me how to use a ServerSocket to archive that. Nothing about that is so cryptic that I don't understand how it works. – user281377 Jun 03 '23 at 12:08
  • @user281377 yes, if you already understand how it works its fine. The problem is using code that you don't understand. Maybe it does what its creator claims, maybe it will destroy your app and kill your dog. – Juan Perez Jun 25 '23 at 23:28
26

Coding is the lowest level of programming in fact. The higher level of abstraction you can get to, the better programmer you are. Choosing right libraries (not necessarily open-source ones), properly connecting them together and maintaining the construct is much harder yet more efficient and time- and cost-saving, than writing everything yourself.

  • From this point of view, a person that hires a programmer is a better programmer than him. He handles the highest level of abstraction: the goal. – Juan Perez Jun 02 '23 at 19:45
25

good programmers write good code; great programmers steal great code.

dan_waterworth
  • 7,287
  • 2
  • 34
  • 45
13

I love to write my own libraries. I also love to get my projects done on time. I think over time, most good programmers build up a collection of useful and re-usable bits. I don't know about you, but I get a great feeling every time I use a library that I wrote five years ago.

There is absolutely nothing wrong with using library code that has been tested and loved over time. You know how it works, you can count on its complexity and you can implement it quickly.

That being said, I'm assuming that you understand the code in the library. I'm assuming that, if given sufficient time, you could implement something of similar quality.

I know some really good C programmers who could implement the standard C library, a few of them that have simply as a learning / sharpening exercise. Some of the most fun I've had during hobby time was working on the C library in HelenOS.

So, there's nothing wrong with using library code, as long as you continue to be curious and learn. It goes without saying that you should not use code that you don't understand, unless your use of it is an effort to understand how it works.

Tim Post
  • 18,757
  • 2
  • 57
  • 101
  • You pretty much described my aversion against jQuery, +1. – aaaaaaaaaaaa Jan 07 '11 at 01:52
  • Does someone else get to maintain your code? My college is reinventing the wheel with absolutely everything. Poorly tested, undocumented crap. – wobbily_col Nov 25 '20 at 16:56
  • @wobbily_col Yes. Nothing where I've worked gets checked into main until it's, well, rather well-tested AND ships with tests. I wouldn't go writing my own XML parser (as an example) though, or work on solving any other major problem that was already neatly solved to what I needed. The whole "get done on time" really does narrow the space you have to play with. It sounds like you're working with folks that are doing it specifically for learning and experience, and I'd expect poor testing / documentation subsequently if that's the case. – Tim Post Nov 25 '20 at 20:09
7

I'll go one better than some others in this question: I don't even think the "client" developer of a library needs to "understand" the code in that library.

I'm a (compared to some) relatively new iPhone developer. There are LOTS of libraries that I use every day that I could never have generated on my own, and the code of which is way over my head. Doesn't matter in the slightest PROVIDED:

1) I fully understand the interface to those libraries (I'm an ASIHTTPRequest ninja!)
2) I'm picking libraries that are in general, broad use, so I can be sure they've been well gone over and explored for problems (eg: ASIHTTP, Stig Brautaset's JSON library, Facebook's obj-c library, etc.)
3) Failing #2, it's simple enough that I could pick my way through it and find/fix/customize anything that needs finding/fixing/customizing.

That #2 is going to be the contentious part of this, I'm betting. The fact is, I am relying on the open source community, a community of developers that is certainly more experienced and quite likely smarter than I am. But that's the whole point of open source. So, there you go.

Dan Ray
  • 9,106
  • 3
  • 37
  • 49
4

I'd like to throw in a warning for using libraries. As a frequent user of scientific libraries in Perl an R (and some in Java), I often had to hack into a library to avoid hideous overhead cost. Using libraries is great, but more and more libraries are themselves dependent on other libraries, which calls a third library that uses the standard library to do a rather common task. And each step in the process requires some checks of input and output. Quite a lot of those checks are completely redundant, but they weigh on the application nonetheless. And when used in a loop, then can start to weigh quite heavily.

Next to that, you can't be sure that libraries always keep back-compatibility, or do not contain bugs. In fact, all libraries contain a few bugs, that's the nature of code. Hence, the more dependent you are on libraries, the more potential bugs you enter in your code. And those bugs you can't solve yourself that easily without hacking into the libraries again.

Using libraries is a very smart decision, but if and only if you know the libraries and their behaviour pretty well.

I know, thinking hurts and computers are cheap, but still. Not thinking can hurt more.

Joris Meys
  • 1,933
  • 14
  • 20
3

Code reuse is a very good idea. It reduces redundancy and promotes maintainability.

The title suggests you are using the code as a library, but the text of your question implies you might be copying the source code into a new project. I'd stick to using other developers' code as a library as much as possible.

There is a problem if the code is bad or somehow broken or based on a model that doesn't fit your application very well. In that case it might be simpler to scrap some or all of the code and start from scratch than trying to understand why it was written in a given way. Keep the other code around for reference, though; you may come across an issue that you aren't sure how to solve. Chances are the other developer probably came across the same issue, and it's worthwhile to see how they solved it.

dckrooney
  • 227
  • 1
  • 7
p.s.w.g
  • 4,135
  • 4
  • 28
  • 40
  • You got me there. I also refer to copying many lines of codes of other's work (not libraries), since it is legal in my case. What do you think? – Arman Mar 27 '13 at 18:40
  • 1
    @Arman It's still a good idea. From a maintenance perspective, it's not as good because when the original developer fixes a bug in his/her code, it's still there in yours. It's still better than nothing because at least the code is fairly similar across both projects and you could apply the bug fix separately without having to do as much. – p.s.w.g Mar 27 '13 at 18:44
  • :One last question: So as what Mason said, if for example I found that the 2500 lines of code (again I'm stressing not libraries) of yours is somewhat useful in starting my work, and you let me to copy it, do you think it's good for me? Is is ethical? – Arman Mar 27 '13 at 18:58
  • @Arman If it's legal, it's probably ethical too.If it's written by a developer under the same organization, then generally the organization owns the code and you have every right to use it (in accordance with organization policies). If was written under a different organization, you need to permission from that organization. Generally if the code is not covered by any license, the original developer doesn't really care how you use it, but I will always attribute the original developer in prominent code comments (with a link if possible). – p.s.w.g Mar 27 '13 at 19:06
  • 4
    Ideally, you should also understand _how_ the copied code works. – Mike Partridge Mar 27 '13 at 19:32
3

Usually, copying large amounts of source code is poor practice. If the code was developed for another application at your company, then you should reuse the code by extracting it into a library to be used by both applications. You should not copy the code. Copying the code will force you to maintain two copies instead of one common copy.

kevin cline
  • 33,608
  • 3
  • 71
  • 142
2

That's generally a good idea, so long no legal issues exist.

However, make sure you take the time to understand what the library does and how it does it. Using a "magic" library to take care of things you don't understand is a good way to have some part of it blow up on you because you used it wrong, and then you have no idea how to fix it.

Mason Wheeler
  • 82,151
  • 24
  • 234
  • 309
  • 1
    I wonder if "copying and pasting" a hundred lines of code made by my generous fellow programmer is still ethical. – Arman Mar 27 '13 at 18:32
  • 2
    @Arman: Try asking him. – Mason Wheeler Mar 27 '13 at 18:32
  • 1
    If the licence allows it, why would it not be ethical? If you are trying to get a job done, and one wheel has already been invented and made available to you for free, it would wrong (i.e. unethical) for you to waste a minute of your time re-inventing it. If you need to learn how to reinvent a wheel, that's completely different. – Darius X. Mar 27 '13 at 19:13
1

Legally reusing code has almost no downsides and two huge upsides:

  1. It gets the job done. This is the more important one for professional development. Ultimately, you have a well-paying job because you know how to make things happen that would stump most non-programmers; reuse allows you reach that goal faster, so you become more valuable in your job.
  2. You learn stuff. This is the more important reason for self-improvement. There is no better way to improve coding than to read good code written by others. Even bad code written by others usually teaches you something! And there is no better way to understand how a library, API, language, or domain works than reading and improving solutions already written by others. Both things usually happen when you reuse existing code, because no pre-existing solution will ever do quite what you need - and the ensuing tinkering with the source is where the knowledge boost comes from.
Kilian Foth
  • 107,706
  • 45
  • 295
  • 310
  • That's really my goal, to learn. For now, it worth more than finishing my project. That's why I feel bad when trying to have someone's work with just little effort (not just referring to libraries). – Arman Mar 27 '13 at 18:48
1

Does heavy library and code snippet usage make you a bad programmer?

If you use libraries and code snippets in appropriate places, then 'No', it does not mean you're a bad programmer. It means that you're a smart programmer who can apply the wisdom of others in appropriate places.

However...

It takes time to find libraries and code snippets, so if you can't write code on your own, and you need to spend hours to find libraries and code snippets to implement trivial tasks, then 'Yes', you are a bad programmer.

Jim G.
  • 8,006
  • 3
  • 35
  • 66
1

For completion purposes, allow a counter argument: http://web.archive.org/web/20150326134617/https://michaelochurch.wordpress.com/2015/03/25/never-invent-here-the-even-worse-sibling-of-not-invented-here/

a mentality that I call "Never Invent Here" (NeIH). With that mentality, external assets are overvalued and often implicitly trusted, leaving engineers to spend more time adapting to the quirks of off-the-shelf assets, and less time building assets of their own.

There is always a balance.

glauxosdever
  • 103
  • 5
Dimitrios Mistriotis
  • 2,220
  • 1
  • 16
  • 26
0

In addition to the reasons in the other answers, not using the code (as long as it's a good fit for your problem) can be considered unethical because:

  1. You might be intentionally wasting your employers time OR
  2. You might be intentionally delivering a lesser product

Keep in mind, both of those are hard to determine beforehand.

Also, look at Not Invented Here, which commonly referred to as an anit-pattern.

Zachary Yates
  • 1,776
  • 13
  • 16
0

No. Programmers should use libraries which are already out there. No re-inventing the wheel. If you have a better method, you can go for it, else what does it really do in writing the same code. The only thing is you should know what the code is (and only if it matters).

-1

I am for not using libraries unless absolutely necessary. Dependencies limit portability and lifespan. I have 34 years in software development and would like to have at least 1 of my programs last longer than 3 years without being destroyed by erosion (change).

COM (Component Object Model), the answer 17 years ago, in theory great, in practice questionable, reusable components not really, I will only use the very basic components and only if I have to.

APIs and SDKs not much use. If I break down the number of lines of code that I actual use out of a library, the time I spend getting them to work vs. writing them, I think it’s a wash. I quit using SDKs completely the overhead is extreme.

Frameworks: Zend, Silverlight, WCF, .NET, the layered systems, yes they can speed initial development, but when I hit their limits, the time I spend fixing the cracks, just isn’t worth the effort. How old are they and are they impervious to erosion?

I have gone to JavaScript and HTML with only my libraries. I have stripped JavaScript down by using only the most common statement types. I hope in 10 years I can write something that will last.

  • part of this problem isn't so much the libraries, but the continual technology churn of languages and programming tools that means you have to go and find new libraries in the new tech to do the same old thing. – gbjbaanb Mar 28 '13 at 23:34
-2

It all depends. If you are coding a game then it makes since to use a library (ex. Allegro) but you can't really be considered a programmer if you're copying/stealing/borrowing (whatever) other people's code. I say no reinventing the wheel but to a reasonable point. Don't make your entire program of snippets that other people wrote. Sit at you computer and do it yourself...stop stealing code. People have gotten too lazy these days and just copy and paste.

Jadzia
  • 13
  • 1