Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between library and application code?

This question sprung from a web application, although it should be valid for other types of applications too. I am using MVC.

I have both application code (modeles, views, controllers, forms, helpers, etc.) and library code (external libraries and an internal library with self-written database mappers, json converters etc.).

I wonder where you usually draw the line between application and library code (when both is internally written)?

Some of the library code gets rather project specific, but is still a bit abstracted.

like image 489
sandstrom Avatar asked Aug 13 '09 08:08

sandstrom


People also ask

What is the difference between library and application?

Typically libraries stay static within the development of an application, at least besides occasional upgrades: application code utilises the functionality provided by the modules to create a specific behaviour for the logical interaction between users and a domain of data in a generally tighter-defined environment.

What is application code?

Application code is a series of SQL statements that process input and produce output. These SQL statements operate on in-application streams and reference tables.

What is the difference between a library and a framework required?

The technical difference between a framework and library lies in a term called inversion of control. When you use a library, you are in charge of the flow of the application. You are choosing when and where to call the library. When you use a framework, the framework is in charge of the flow.

What is library code?

Library code is organized in such a way that it can be used by multiple programs that have no connection to each other, while code that is part of a program is organized to be used only within that one program.


3 Answers

Library's code is intended to be reusable, application's code usually not. Keep code in a library when it is not tied specifically to the application.

When in doubt try to answer this question:

If I write another application, will this code remain?

like image 84
dfa Avatar answered Oct 22 '22 01:10

dfa


My general rule of thumb is: Anything that might ever get used in another project, and can be made to easily not depend on any application-specific code (and there are all kinds of techniques to do that) should go into a library. So if it is potentially reusable it goes into a library.

like image 36
Adam Batkin Avatar answered Oct 22 '22 03:10

Adam Batkin


When faced with these kind of categorisation questions I want to know one thing: the consequences of miscategorisation.

This code is "library", that code is "application" ... for whose benefit is this distinction being made? What would happen if we put some code in the wrong category?

One possible answer:

It affects the reuse of the code. Lets suppose that we have a policy: library code is available in a DLL with the required headers etc. Application code is just deployed in a .EXE.

Put a nice routine for doing a difficult calculation in the App, not the library, then it can't readily be reused.

Perhaps further things follow from that line of thinking ... questions of versioning apply. Do we need to produce better documentation? [Even with a single developer we might take more care?] Do we need to externalise configuration information, mak doubly sure not to hard code anything?

like image 36
djna Avatar answered Oct 22 '22 03:10

djna