Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why explicitly write "private"?

As fields are implicitly private, why there is often explicit declaraion used in the books, articles etc.?

like image 942
Loj Avatar asked Nov 06 '10 15:11

Loj


2 Answers

Because default access levels vary across languages, and many people program in more than one language. It's easy to become confused, either as the author or as someone reading the code later, thus explicit is nicer to deal with than implicit.

like image 147
Donnie Avatar answered Sep 28 '22 00:09

Donnie


The problem with implicit declarations is that the reader cannot tell if whoever wrote the code wanted the implicit declaration or simply forgot to write anything. By being explicit there's no doubt about the intentions.

like image 28
Brian Rasmussen Avatar answered Sep 28 '22 02:09

Brian Rasmussen