organizing large pieces of code
I was wondering what methods of code organization stackoverflow users use. I have a s开发者_运维百科poradic thought process and as a result my code can start to look messy and over whelming. Any tips ?
Keep methods short and give classes a single, clear responsibility.
It's not necessary, but TDD can help you acheive this
One file per class.
Folders for related classes.
Use modules/packages/assemblies/namespaces if your language supports them.
In general, keep many levels of abstraction, and try to keep them separate through whatever mechanism you can in your language/ide/platform of choice.
Read Domain Driven Design, which discusses these issues (design, documentation, organization and communication).
I would suggest looking at the principles of Large Scale C++ Software Design by John Lakos (ISBN-13: 978-0201633627) if not the book itself. They are summed up in these lecture notes. Another summary of ideas.
Here's a brief outline of the headings of the principles, which while written about in the C++ context, the geist of which are language agnostic.
- Internal and External Linkage
- Components and Dependency Relations
- Physical Hierarchy Reducing Link-Time
- Dependencies: Levelization Reducing
- Compile-Time Dependencies: Insulation
精彩评论