Hacker News new | past | comments | ask | show | jobs | submit login
Stop Exposing Collections Already (davybrion.com)
6 points by pavel on Oct 28, 2009 | hide | past | favorite | 3 comments



For what it's worth, I disagree with this idea, or any idea that basically requires a lot of glue code without adding any real value.

This requires BOTH the API maintainer AND the caller to add code, all in the name of avoiding some theoretical violation of encapsulation. The extra code risks bugs, is harder to maintain, harder to read, harder to understand, and may accidentally limit the usefulness of the return value in some critical way (which would make the API temporarily unusable while some bug is opened to have the API expanded).

There's a lot of things they could try first, including simply adding documentation to tell the caller what must not happen to the collection that is returned.


I second that. If you are using Java, simply return Collections.unmodifiableList(listObject);


Thanks for that. I was going to comment that the article carries a very complaining tone without giving any real solutions.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: