DEV Community

Discussion on: 1 small tip to improve your code readability

Collapse
winstonpuckett profile image
Winston Puckett

I think there are certain cases where this is really useful though. For instance, writing a publicly used library or public API. If a developer doesn't know the internals of your project, they shouldn't be expected to call it correctly the first time, right?

Collapse
glsolaria profile image
G.L Solaria

If the API code simply does nothing when a user of the API does not satisfy preconditions, how can the API user figure out they are not using it correctly? Wouldn't an exception be more appropriate?

Thread Thread
winstonpuckett profile image
Winston Puckett

Totally, but all too often I see things like,
If (acceptable)
{
// Lots of code
}
Else
{
Throw exception
}

Vs what the article talks about of

If (!acceptable)
Throw exception