-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Open
Description
Bad:
function combine(val1, val2) {
if (
(typeof val1 === "number" && typeof val2 === "number") ||
(typeof val1 === "string" && typeof val2 === "string")
) {
return val1 + val2;
}
throw new Error("Must be of type String or Number");
}
Good:
function combine(val1, val2) {
return val1 + val2;
}
The example does promote clean code. However, this example has discarded the important runtime type checking and necessary validations and seems incomplete. I agree that we should have "combine" function to do just the "combine", but if other team members get overly confident that the combine function would perform validation/data type checking as well, wouldn't this promote confusion/bugs instead? Appreciate your insight on this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels