Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you organise your code library?

I am interested to know how people organise their code libraries, particularly with respect to reusable components. I am talking in OO terms below but I am interested in how your organise libraries for other types of language also.

For example:

  • Are you a stickler for class library projects for everything or do you prefer to keep everything in a single project?
  • Do you reuse your prebuilt DLLs or do you include individual classes from previous projects in your current work? If individual classes, do you share them between the projects to ensure all are kept up to date or do you permit branching?
  • How large are your reusable elements? How focussed are they? How are they focussed?
  • What level of reuse do you attain through your preferred practices?

etc.

EDIT

I am not looking for specific guidance here, I am just interested in people's thoughts and practices. I am particularly interested in the reuse of code between disparate projects, rather than within a single project. (Unfortunately the use of 'project' here is misleading - I mean reuse between real-world projects undertaken for customers, not projects in a Visual Studio sense.)

like image 901
BlackWasp Avatar asked May 10 '09 19:05

BlackWasp


People also ask

Why is it important to organize your code?

First and most useful reason to organize your code is better ability to search. When your code follows specific order, it is much easier for you or anyone else to find particular line or property to change it. Organized code is also better to debug and enhance.


2 Answers

It generally can be guide by deployment considerations:

How will you deploy (i.e. what will you copy on your production machine) ?

If what you are deploying are packaged components (i.e. dll, jar, war, ...), it is wise to organize the "code library" as a collection of packaged set of files.
That way, you will develop directly with the -- dll, jar, war, ... -- which will be deployed on the production platform.
The idea being: if it works with those packaged files, it may still work in production.


the reuse of code between disparate projects, rather than within a single project.

I maintain that kind of reuse is easier in a "component" approach (like the one discussed in the question "Vendor Branches in GIT")

Over more than 40 current projects, we achieved:

  • technical reuse by systematically isolating any pure technical aspect into independent framework (typically, log framework, exception framework, KPI - Key Performance Indicator - framework, and so on).
    Those technical components are reused into every other projects.
  • functional reuse by setting a clear applicative architecture in order to divide any functional domain (given the business and functional specifications) into well-defined applications. That would typically involve, for instance, a bus layer which is also a great candidate for exposing services reused by any other projects.

Summary:
For large functional domain, a single project being not manageable, a good applicative architecture will lead to natural code reuse.

like image 95
VonC Avatar answered Oct 05 '22 22:10

VonC


We follow these principles:

  • The Release-Reuse Equivalency Principle: The granule of reuse is the granule of release.
  • The Common Closure Principle: The classes in a package should be closed together against the same kinds of changes.
  • The Common Reuse Principle: The classes in a package are reused together.
  • The Acyclic Dependencies Principle: Allow no cycles in the package dependency graph.
  • The Stable Dependency Principle: Depend in the direction of stability.
  • The Stable Abstraction Principle: A package should be as abstract as it is stable.

You can find out more over here and over here.

like image 34
Sir Rippov the Maple Avatar answered Oct 05 '22 23:10

Sir Rippov the Maple