If all methods are public unless they are explicitly defined as something else, is it ever necessary to define a method as public?
Asked
Active
Viewed 190 times
3
wattostudios
- 8,576
- 13
- 42
- 57
Emanuil Rusev
- 33,269
- 52
- 129
- 197
3 Answers
11
Well, you answered the question already by naming the default: no, it is not necessary.
Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.
However, I consider it good practise to always do so.
Gordon
- 305,248
- 71
- 524
- 547
1
There are two style tendencies in php - the "javaesque" majority considers visibility modifiers very important and uses them actively, in the pythonesque minority (i personally belong to) we think that all that public-private-interface-abstract stuff is nothing more but a waste of RAM.
user187291
- 52,425
- 19
- 93
- 127
-
2I'd be interested to hear why! – sunwukung Sep 16 '10 at 09:05
-
@stereofrog: Neither of your responses answer sunwukung's question; they're actually rather cargo cult in nature. "If python doesn't use it, it must not be worthwhile" isn't an answer. – EricBoersma Sep 16 '10 at 14:17
-
@stereofrog: Neither of those come close to answering sunwukung's question. Asking a question with a desired answer, and deliberately stating that you're going to ignore people who disagree with you isn't valuable at all. Like sunwukung, I would be fascinated to read about why the python community considers access modifiers unnecessary, but neither of your answers have come close to providing that information. – EricBoersma Sep 16 '10 at 15:16