Live data from Hacker News

Lay Out Your Code Like You'd Lay Out Your House

frederikcreemers.be

11–20 of 47 posts

Re: Lay Out Your Code Like You'd Lay Out Your House

#11
post #6

I love this concept when you are dealing with a blog that has posts and comments, or a todo app. However..in my experiences thus far, this type of cohesion becomes increasingly complex and open to individual interpretation when you are dealing with more complex business domains. Say for example, several different types of customers engaging in several different types of transactions that have just enough differences…

In this situation the best thing to do might be to make a choice, go with it for a while, and see how well the subsequent changes cluster. If all the changes in patches implementing features tend to be in the same place, you got it right. If not, time to reshuffle.

Making a code layout like this is effectively making a prediction about what future changes are likely to entail. Predictions can be wrong, so we want to be able to change anyway.

Re: Lay Out Your Code Like You'd Lay Out Your House

#14
The main argument I’ve come across against this is that text editors commonly put great weight on file names—opening by file name, showing the file name without its containing directory structure or with it harshly abridged (e.g. /h/c/B/p/controllers.py). It would be nice for this to be addressed better in editors, but it is a bit of a tricky matter to handle across varying projects.

Of course, as presented, having lots of files named “posts.py” is also fairly terrible in text editors.

One solution is for the filename to include more, e.g. posts/posts-controllers.py. This helps some tools at the cost of others and greater verbosity.

Re: Lay Out Your Code Like You'd Lay Out Your House

#16
Or, alternately, lay your code out like you'd lay out your workshop.

In our houses we tend to use the same things in the same ways each day. There's just the one razor, keep it next to the shaving cream.

In a workshop, we need to cooperate with other people, and even for ourselves, it's important to be able to find a tool when we need it. All the X-acto blades go in the same drawer, next to the drill bits.

Which one is more like your codebase? If it's a blog, might be the house. I think more code is workshop-like, but YMMV.

Re: Lay Out Your Code Like You'd Lay Out Your House

#18

The main argument I’ve come across against this is that text editors commonly put great weight on file names—opening by file name, showing the file name without its containing directory structure or with it harshly abridged (e.g. /h/c/B/p/controllers.py). It would be nice for this to be addressed better in editors, but it is a bit of a tricky matter to handle across varying projects. Of course, as presented, having l…

This summarizes my struggle when getting my feet wet with custom Ansible playbooks. Having a bunch of `main.yml` files open in your editor and trying to figure out what exactly it is you're currently looking at greatly increases cognitive load and distracts from the actual task at hand.

Re: Lay Out Your Code Like You'd Lay Out Your House

#20
actually I recall a time when I made a mistake in code placement that would have been avoided if I had followed this principle.

I had made an api controller, but then we needed to expand what our api covered to cover everything the app did (should have gone api first but again, my mistake, also partially inherited code base)

So of course I should have put the parts of the api that handled users into the user controller and the parts that handled images into the image controller and so on and so forth, but instead I thought (and here I can point to overwork dulling ones thinking processes) 'I have an api controller, this stuff now needs to be moved over from these other controllers into api controller' and in the end it became a horrible mishmash with some duplicated functionality I needed to fix later.

Post reply on HN