Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smalltalk public methods vs private/protected methods [closed]

I noticed that the Smalltalk language has no concept of private/protected methods. All methods are public. Coming from a Java/C++ background, I've thought of this as a fundamental weakness in the language as any application created in Smalltalk would be completely open to manipulation. I guess you could rely on naming conventions to document the public API and prefix methods to indicate them as private (I believe Squeak does this), but it's still completely open.

Are there any benefits to this approach over having explicit access modifiers to control access to method invocations?

like image 344
Desolate Planet Avatar asked Sep 13 '11 09:09

Desolate Planet


2 Answers

Indeed, the Smalltalk way is to put private methods in the 'private' category. This indicates that you shouldn't use these methods, but of course doesn't enforce this.

This is by design - it's a feature, not a bug. Smalltalk was designed from the beginning precisely to be an open system.

Some advantages:

  • If I simply have to - maybe the library designer didn't foresee a need to expose some particular thing I simply have to have - I can still call those private methods. Obviously, this isn't something one does lightly: rather, judiciously, cautiously, knowing that it's a tactical solution.
  • Language simplicity.
  • (As per Alexandre Jasmin's comment) Smalltalk makes no distinction between what you, the programmer, can do and what the language/environment can do. That means that Smalltalk-the-image exposes all the things needed for you to build your own inspectors/debuggers/whatever without having to supply special tools using we-can-do-this-but-you-can't techniques.
like image 186
Frank Shearar Avatar answered Oct 23 '22 08:10

Frank Shearar


Private and protected methods are in fact a significant weakness of languages like c++, java and c#. They basically say to their users: I don't want to learn and evolve. The consequence of that (and a lot more early binding) is that those languages require much more BDUF and are thus far less usable for a modern (agile) development process.

like image 6
Stephan Eggermont Avatar answered Oct 23 '22 09:10

Stephan Eggermont