Ad
  • Custom User Avatar

    Sounds good. In general, I agree with your opinion. One should write code in a safety way, i.e. check each input and don't make any assumptions. Double-checking is better than getting an exception (or much worse: Having a security issue).

  • Custom User Avatar

    I'm afraid I have to disagree. The reason is very simple: What is a "best practise"? Answer: It the best solution which solve the requirement / the problem.

    According to the task discription, the array has only numbers and at least one element. Why should we write boilerplate code? Why should we write any checks for situations that never occur?
    The consequence of your idea would be that you get code which is not good readable and maintainable.