While reviewing the first draft I realized that these two tidyings could use an example or two. Send ‘em, please!
To review for the many of you who weren’t here when the chapters were published:
Reading Order says that you take an element with randomly sorted sub-elements (e.g. a file with functions or a class with methods) & place the sub-elements in the order you wish they had been when you read the code.
Cohesion Order changes the ordering criteria to make sure that coupled sub-elements (those that have to change at the same time) are adjacent.
Here’s what I need: before and after code where you applied one of these tidyings. I will likely abstract what you send me to make it easier to read/grasp.
Old:
write()
read()
process()
New:
read()
process()
write()
Something like that. Alternatively, the element could be a function & you re-ordered the statements for readability or cohesion.
Looking forward to your examples!
To make things more complicated, I know from experience that some developers (typically those trained in math) tend to to structure things like a proof, with "atoms" first, building up to larger entities.
While reading this, I realized I unknowingly followed a mixed pattern, where I would use cohesion and sorting both.
Like, first group the variables by related meaning, then sort these groups alphabetically.
Much like
```
filters,
setFilters,
result,
setResult,
title,
setTitle,
```