DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Visual Patterns in Source Code Arrangement

Francois Zaninotto user avatar by
Francois Zaninotto
·
Mar. 06, 13 · Interview
Like (0)
Save
Tweet
Share
5.53K Views

Join the DZone community and get the full member experience.

Join For Free
source code arrangement is a matter of debate. what would you consider a good practice for the number of lines of code per file, the number of files per directory, the total number of files in a project? to help answer these questions, one must see the big picture: how does a project code look from a bird's eye view? codeflowers are a way to look at code layouts in a graphical way. using it on various projects, you quickly see some visual patterns emerge.

the mistletoe

one very large file (greater than 500 lines of code) among a tree structure of normal size files. this files doesn't look at its place, i call it the mistletoe . whether it's a css or a list of utility methods, dealing with large files is often a developer's nightmare. it's a good start for a refactoring session: split the mistletoe into several files, it will disappear.

the mistletoe

the dandelion

a directory with a lot (more than 30) very small files. it's so familiar that you want to blow on it to scatter the seeds: i call it the dandelion . you often find dandelions in internationalized projects, where translation files are numerous and lie in the same directory. they may not be problematic, until the number of files becomes really too big, and developers find it hard to find the one they're looking for.

the dandelion

twigs

several thin branches, not many leafs: meet the twigs . this is a deep directory structure that requires a lot of clicks to browse, where the number of files per directory (one or two) is suboptimal. i see this pattern a lot in psr-0 projects, because the class naming rule imposes a deep directory structure. try to regroup leafs on a single branch to make your fellow developers happier.

twigs

twin branches

two branches that look the same: this is often caused by a test class layout following the library layout - and it's a good practice. don't panic if you see twin branches , they make the tester's life easier.

twin branches

grapes

many very large files attached to the same branch: that's the grapes . the files are so big and so numerous that the leafs overlap on the visualization. it makes it difficult to tell one file from the other. it's equally difficult for developers to work with such code layouts. this is often representative of aging libraries, where not enough time was spent on refactoring. but if you see only grapes in a codeflower, it may also be because you're looking at a program which uses a very verbose language.

grapes

the sunflower

a very large flower with regular petals, and several directory levels, is a pattern i call the sunflower . you may find it in projects where a library is declined several times, or where several sets of data using the same layout are required. it's not a problem as long as the directories composing it are properly named.

sunflower

did you see other patterns?

if you spot other patterns, feel free to share them here. code layout is a matter of taste of course, but there are common practices that are interesting to discuss.

Directory

Published at DZone with permission of Francois Zaninotto. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Microservices Discovery With Eureka
  • How To Check Docker Images for Vulnerabilities
  • API Design Patterns Review
  • How Observability Is Redefining Developer Roles

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: