DEV Community

Discussion on: Go project layout

Collapse
 
andrewpillar profile image
Andrew Pillar

On the contrary I'd advocate for organising by responsibility [1]. Furthermore, I'd suggest that when programming you shouldn't focus on the layout of the source code files and more on the code you're writing. As your project grows the abstractions and patterns that you use will present themselves to you. Using this, you can easily begin refactoring your code into something more logical and manageable. I'd always suggest a new comer to Go to just start writing code, and to not spend their time designing the layout of the source code in their program. I view designing the layout of a program's code before writing it as no different than measuring your own coffin. Sure you may know how the program will operate at a high-level, but you don't know the intricacies yet, nor how the data will flow through your program. This should be the focus in my opinion, not the structure of directories or files.

[1] - rakyll.org/style-packages/#organiz...

Collapse
 
royal_bhati profile image
Royal Bhati

I know it looks a lot and I get your point but what bad it'll do if you take some time out to think about the layout before writing the code.

Collapse
 
andrewpillar profile image
Andrew Pillar

but what bad it'll do if you take some time out to think about the layout before writing the code.

You risk putting your code in places where it might not belong, and this makes refactoring your code harder. Write the obvious code first, and refactor from there. And again, you want to avoid making too many assumptions about what your program could do, as this diverts your attention away from what the program will do. You figure out what your program will do by writing it.

Thread Thread
 
royal_bhati profile image
Royal Bhati • Edited

putting your code in places where it might not belong

Not if you know what your layout is and what you are trying to achieve.

avoid making too many assumptions

again, if you know what you are doing than making assumptions is not bad