tags:

views:

93

answers:

3

If all methods are public unless they are explicitly defined as something else, is it ever necessary to define a method as public?

+10  A: 

Well, you answered the question already by naming the default: no, it is not necessary.

To quote the manual:

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
+1  A: 

Because public is the default it isn't necessary to define it.

fabrik
+1  A: 

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.

stereofrog
I'd be interested to hear why!
sunwukung
@sunwukung: if "public" is so good, why doesn't python use it?
stereofrog
@sunwukung: http://stackoverflow.com/questions/3725539/reasons-to-avoid-access-modifiers-in-php
stereofrog
@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
@EricBoersma, read the link i posted, especially @mario and @troelskn comments.
stereofrog
@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
@EricBoersma, that's simple. http://xkcd.com/353/
stereofrog