Else is never necessary – Really?

I had an interesting experience with Codacy today.  I got this error.

When doing my IT Degree (many moons ago) I was taught 2 things (amongst others you understand):

  1. An If statement always has an else. You should always handle a possible situation even if it should never happen.
  2. There should only ever be one exit point from a function, loop etc.

Perhaps these mantras stemmed from a safety critical standpoint (I was using Ada).

However, it seems the ‘modern way’ doesn’t agree. Well tough, I still think I am right and any other way is just building in problems.

Facebooktwitterby feather
This entry was posted in Coding and Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

*