views:

369

answers:

7

What are common reasons to split a development project (e.g. ASP.NET MVC application) into multiple projects? Code organization can be done via folders just as well. Multiple projects tend to generate circular reference conflicts and increase complexity by having to manage/resolve those.

So, why?

+1  A: 

One possibility is to have a system that a given group (or single developer) can work on independently of the rest of the code. Another is to factor out common utility code that the rest of the system needs -- things like error handling, logging, and common utilities come to mind.

Of course, just when thinking about what goes in a particular function / class / file, where the boundaries are is a matter of art, not science.

John Lockwood
A: 

Ownership for one thing. If you have developers responsible for different parts of the code base then splitting the project up is the natural thing to do. One would also split projects by functionality. This reduces conflicts and complexity. If it increases, that just means a lack of communication and you are just doing it wrong.

Clutch
This makes code ownership more exclusive, which I think is a bad thing. Exclusive code ownership requires more communication (as you noted) and communication is always difficult to get. It also requires more cooperation (if I need your code changed, it's now much harder to do it myself) which is also difficult to get. In this scenario, one bad team player can fuck things up for everyone.
Imagist
A: 

One example I can think of is that you might find in developing one project that you end up developing a library which may be of more general use and which deserves to be its own project. For instance maybe you're working on a video game, and you end up writing an audio library that's in no way tied specifically to the game project.

smcameron
+1  A: 

Some reasons are

Encapsulation - By packaging a set of routines into another library, either as a static library or a set of dlls, it becomes a black box. For it to be a good black box, all you need to do is to make sure you give the right inputs and get the right outputs. It helps when you re-use that library. It also enforces certain rules and prevent programming by hacks ('hmm...I'll just make that member function public for now')

Reduces compile time - the library is already complied; you don't have to rebuild it at compile time, just link to it (assuming you are doing C++).

Decoupling - By encasing your classes into a standalone libraries, you can reduce coupling and allows you to reuse the library for other purpose. Likewise, as long as the interface of the library does not change, you can make changes to the library all you like, and others who link to it or refer to it does not need to change their code at all. DLLs are useful in this aspect that no re-compilation is required, but can be tricky to work with if many applications install different versions of the same DLLs. You can update libraries without impacting the client's code. While you can do the same with just folders, there is no explicit mechanism to force this behaviour.

Also, by practicing this discipline of having different libraries, you can also make sure what you have written is generic and decoupled from implementation.

Licensing/Commercialization - Well, I think this is quite obvious.

Extrakun
A: 
  1. Code reuse. Let's say you have project A and you start a new project B which has many of the same functions as project A. It makes sense to pull out the shared parts of A and make them into a library which can be used by both A and B. This allows you to have the code in both without having to maintain the same code in two places.

  2. Code reuse, inverted. Let's say you have a project which works on one platform. Now you want it to work on two platforms. If you can separate out the platform-dependent code, you can start different projects for each platform-dependent library and then compile your central codebase with different libraries for different platforms.

Imagist
Why the downvotes?
Imagist
A: 

Instead of questioning the value of code in multiple assemblies, question the value of clumping all of your code in one place.

Would you put everything in your kitchen in a single cabinet?

Circular references are circular references, whether they happen between assemblies or within them. The design of the offending components is most likely sub-optimal; eschewing organization via assemblies ironically prevents the compiler from detecting the situation for you.

I don't understand the statement that you can organize code just as well with folders as with projects. If that were true, our operating systems wouldn't have the concept of separate drives; they would just have one giant folder structure. Higher-order organizational patterns express a different kind of intent than simple folders.

Projects say "These concepts are closely related, and only peripherally related to other concepts."

Bryan Watts
You are right; I'm just encountering lots of circular references (described in this question: http://stackoverflow.com/questions/1320561/resolving-circular-references-c) which seem to make separation of projects extremely tedious, or I am making some huge design mistakes which I'm not aware of (and would like to learn from).
Alex
Added an answer to the linked question.
Bryan Watts
A: 

There are some good answers here so I'll try not to repeat.

One benefit of splitting code out to it's own project is to reuse the assembly across multiple applications.

I liked the functional approach mentioned as well (e.g. Inventory, Shipping, etc. could all get their own projects). Another idea is to consider the deployment model. Code shared between layers, tiers, or servers should probably be in it's own common project (or set of projects if finer control is desired). Code earmarked for a certain tier may be in it's own project. e.g. if you had a separate web server and application server then you wouldn't want to deploy the UI code on the application server.

Another reason to split may be to allow small incremental deploys once the application is in production. Let's say you get an emergency production bug that needs to be fixed. If the small change requires a rebuild of the entire (one project) application you might have a hard time justifying a small test cycle to QA. You might have an easier sell if you were deploying only one assembly with a smaller set of functionality.

Tuzo