function area(shape)
switch shape.type
case "square": return shape.side ** 2
case "circle": return 2 * PI * shape.radius
case "triangle": return ...
case "segment": return 0
case "polygon": return ...
...
case "oval": return ...
You can have a lot of cases, some of them requiring non trivial code...
Eventually you write a function for each case and it's more work than adding a method for each shape because you still need to write the switch... function intersection(shapeA, shapeB)
if(shapeA.type == "circle" AND shapeB.type == "circle")...
if(shapeA.type == "circle" AND shapeB.type == "square")...
if(shapeA.type == "square" AND shapeB.type == "circle")...
...//uh oh you have nShapes**2 cases to handle
But java classes or not better: where do you define Circle-Square intersection? In Circle? In Square? if(cond1){
myVar = 1;
}
else if(cond2 && cond3){
myVar = 10;
}
else if(cond2 && !cond3){
myVar = 100;
}
else {
myVar = 4;
}
But when I encounter this kind of situations I have other problems than code formatting anyway:
Researchers work a lot on their own time, so the millions mentionned in the article don't directly impact the institutions employing them. They are alone in this fight.
The petition (https://www.change.org/p/simplify-manuscript-submissions-in-...) linked in the article barely received 100 signatures in a month.