Re:Want cleaner code? Use the rule of six
by longrod on Saturday September 24, 2022 @02:29PM
(#32965372)
If you are going for human readability then making your code expressive is the only way. Abstract away the code parts under a layer of very simply named functions/classes and boom! even a child will be able to understand what's going on.
Obviously, that isn't always possible. I find this approach especially useful in writing e2e browser tests. You write an abstraction over the testing framework's (playwright, puppeteer etc) interaction and then use that in your tests.
So instead of writing:
await page.click(".play-button");
You do:
await app.play();
This also has the benefit of extreme reusability. Doesn't work for everything though.
Obviously, that isn't always possible. I find this approach especially useful in writing e2e browser tests. You write an abstraction over the testing framework's (playwright, puppeteer etc) interaction and then use that in your tests.
So instead of writing:
You do: This also has the benefit of extreme reusability. Doesn't work for everything though.