Hacker News new | past | comments | ask | show | jobs | submit login

> "If something is wrong, throw an exception."

> That is sometimes just not an option performance wise yet.

Why? I haven't heard about performance issues of exceptions since 90-ties and C++ problems.

And if you consider that you can throw exceptions instead of error codes (which null is an example of) why would a list of numbers be ever null?

It should be an empty list, not null.

Generally you don't add Optionals to Collections/Iterables/Maps because they already have a notion of empty.

So your example becomes:

    List<Integer> nums = getNumbers();

    for (Integer i : nums)
        System.out.println(i);
And if getNumbers has an error, it should throw an exeption.



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: