Talk:Convention over Code
| This article is rated Stub-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||
| |||||||||||
Remove or rewrite the controversial example?
The example of the "public" qualifier in Java and C# was written 17 years ago, and since then has received no support or citation. Even the editor who added it calls it a "matter of opinion". I suggest removing or rewriting.
The reason I am not rewriting it myself is that (1) my opinion is also just an opinion, although based on decades of professional experience, and (2) the example mentions Java and C# as having the same issue, and while I strongly disagree about Java, I don't know enough about C# to express an opinion. (Maybe the situation is superficially similar but fundamentally different in these languages?)
As a senior Java developer I find the example in the article not only wrong, but ironically the very opposite of true. The default package-private access in Java is in fact a very good example of the "convention over code" approach -- it is a reasonable choice for most methods:[1] keeps them simultaneously protected from other packages (other people's code) and accessible from unit tests (which are typically in a different class in the same package).
If it is true that in practice most methods use the "public" qualifier, that is simply because many programmers do not think much about security (and blindly adding "public" to everything allows them to get the work done), or are unfamiliar with the "convention over code" approach (do not realize that not using an explicit access qualifier is a valid choice, and often the right one). Also, in 2008, when the article was written, most Java developers were coming from C/C++ background, where the concept of packages (and thereby package-privacy) did not exist; but protection of code access on the package level was already supported since Java 1.2 by sealed packages, and since Java 9 by modules. ~2026-34635-33 (talk) 07:59, 12 June 2026 (UTC)
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.