DEV Community

loading...

Discussion on: Clean code exercises - part 1

Collapse
darkwiiplayer profile image
DarkWiiPlayer
const circleStrategy = (shape) => Math.PI * shape.radius * shape.radius

const squareStrategy = (shape) => shape.width * shape.width

const rectangleStrategy = (shape) => shape.width * shape.height
Enter fullscreen mode Exit fullscreen mode

Those functions are poorly named. Proper names would be areaCircle, areaSquare and areaRectangle respectively. You can turn the names around, but putting area first makes for easier sorting.

Collapse
ederchrono profile image
Eder Díaz Author

Yeah I wasn't too careful with the naming here since that wasn't the problem of the exercise. I think that calculateAreaCircle would be better though, since methods should have a present tense verb.

Collapse
darkwiiplayer profile image
DarkWiiPlayer

since methods should have a present tense verb

I don't see any methods in that code.