On 10/24/2026 9:30 PM, Dan Cross wrote:
> In article <11bj…@dont-email.me>, > Arne Vajhøj <ar…@vajhoej.dk> wrote:
>> On 10/24/2026 9:14 PM, Dan Cross wrote:
>>> In article <11bj…@dont-email.me>, >>> Arne Vajhøj <ar…@vajhoej.dk> wrote:
>>>> On 10/24/2026 1:22 PM, Dan Cross wrote:
>>>>> I assume you've seen this? I think I may have posted it a >>>>> couple of days ago. >>>>> >>>>> https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
>>>> You have posted it before. >>>> >>>> I am not sure whether to laugh or cry. >>>> >>>> Stuff like: >>>> >>>> <quote> >>>> Subclasses cannot override private methods. Subclass overrides of public >>>> methods can’t even see, let alone call, the superclass’s private >>>> methods. Problematic for, say, test mocks. >>>> </quote>
>>> >>> This point was listed as a weakness in the critique. It begs >>> the question, however, what does that sentence mean to you?
>> >> It tells that the author is pretty clueless about OOP.
> > Are you sure? Is there a single, universal, definition of the > semantics of `private` in Object-Oriented languages?
At least the principles behind OO are pretty well established. But let us take a step back first. One of the biggest problems in software development is the code base scalability problem. As a code base grow bigger then it becomes increasingly difficult to make changes without breaking something somewhere else. The general solution to the problem is to isolate the different parts of the code base from each other. A given part of the code base has some exported API that is made available to the world and an internal implementation. As long as the exported API is kept then the internal implementation can be changed without breaking things everywhere in the larger code base. This applies everywhere not just in OO context. But it is central in OO context. It is often called encapsulation or information hiding. Two features in OO are responsible for providing this: * polymorphism meaning that code operates on more abstract super types (including interfaces or classes with only pure virtual methods) without even knowing the actual implementing type * members are divided in private and non-private where non-private members become the exported API that must be kept and private becomes implementation that can be changed This is probably the main reason behind the success of OO in software development for large code bases the last 40 years. The OO way is not the only way, but experience has proven it to be a very effective way. Implementations differs a little. I would say that the normal or expected is: private = visible only within class protected = visible within class and its subclasses public = visible to everyone If it is like that then nobody should be surprised. But variations exist. Many languages have additional visibilities. Some languages slightly change the meaning. Notable Java protected makes it visible to both sub classes and classes in same package. But it is all within the the general idea of private stuff that can be changed without impacting anything else and non-private stuff where changes can break anything. The non-private just exist in many flavors. Expecting access to private stuff outside class is against all OO principles and all general software development principles. So yes - the quoted is bad. (often it is possible to gain access to private stuff using reflection, but general view is that those playing with that deserve the problems they get themselves into)
> (Hint: > have you ever used Ruby? Smalltalk?)
I am not that familiar with Ruby. But I have read about it. Ruby define private as not allowing an explicit receiver. What that really means is that Ruby sees private as related to the object not related to the class. That may make sense from a philosophical perspective. Hiding an objects information from itself sounds unnatural. But it is a disaster from a practical code perspective. Encapsulation is totally broken. A few examples. Using JRuby as I don't have MRI on VMS. $ jruby --version jruby 9.4.3.0 (3.1.4) 2023-06-07 3086960792 OpenJDK 64-Bit Server VM 25.502-b07 on 1.8.0_502-b07 +jit [x86_64-OpenVMS] 3.1 is not latest and greatest but not super old either. Example 1 - simple value holder $ type lib1.rb class P attr_reader :v def initialize() @v = 0 end def add1() addn(1) end def add2() addn(2) end private def addn(n) @v += n end end $ type test1.rb require_relative 'lib1' class C < P def add3() addn(3) end end o = C.new o.add3 printf "v=#{o.v}\n" $ jruby test1.rb v=3 Library maintainer decide to do a little refactoring of the implementation but maintaining the external API. $ type lib1.rb class P attr_reader :v def initialize() @v = 0 end def add1() add() end def add2() add(2) end private def add(n = 1) @v += n end end $ jruby test1.rb NoMethodError: undefined method `addn' for #<C:0xe8ea697 @v=0> add3 at test1.rb:5 <main> at test1.rb:10 This is not really a problem. Library user get an error and can fix the code. Example 2 - simple value holder with a modification counter $ type lib2.rb class P attr_reader :v attr_reader :mods def initialize() @v = 0 @mods = 0 end def add1() addn(1) incmods() end def add2() addn(2) incmods() end private def addn(n) @v += n end def incmods() @mods += 1 end end $ type test2.rb require_relative 'lib2' class C < P def add3() addn(3) incmods() end end o = C.new o.add3 printf "v=#{o.v} mods=#{o.mods}\n" $ jruby test2.rb v=3 mods=1 Library maintainer decide to do a little refactoring of the implementation but maintaining the external API. $ type lib2.rb class P attr_reader :v attr_reader :mods def initialize() @v = 0 @mods = 0 end def add1() addn(1) end def add2() addn(2) end private def addn(n) @v += n incmods() end def incmods() @mods += 1 end end $ jruby test2.rb v=3 mods=2 The change in the library's private parts silently changed behavior of the library user. Example 3 - same just with the library user doing the modification counter $ type lib3.rb class P attr_reader :v def initialize() @v = 0 end def add1() addn(1) end def add2() addn(2) end private def addn(n) @v += n end end $ type test3.rb require_relative 'lib3' class C < P attr_reader :mods def initialize() super @mods = 0 end private def addn(n) super @mods += 1 end end o = C.new o.add1 o.add2 printf "v=#{o.v} mods=#{o.mods}\n" $ jruby test3.rb v=3 mods=2 Library maintainer decide to do a little refactoring of the implementation but maintaining the external API. $ type lib3.rb class P attr_reader :v def initialize() @v = 0 end def add1() @v += 1 end def add2() addn(2) end private def addn(n) @v += n end end $ jruby test3.rb v=3 mods=1 The change in the library's private parts silently changed behavior of the library user. Ruby private does not enforce encapsulation. Changes to a libraries private stuff may change behavior of programs using the libraries. That is against everything we should be striving for. The typical justification from Ruby people are: 1) the private keyword show intent and they trust developers and do not want to police them 2) there are several other constructs in Ruby that would make it very easy to circumvent a real private visibility anyway Examples of the latter: $ type lib6.rb class X def initialize() @v = 0 end def read() @v = @v + 1 @v end private def reset() @v = 0 end end $ type test6.rb require_relative 'lib6' o = X.new printf "v=#{o.read()}\n" printf "v=#{o.read()}\n" printf "v=#{o.read()}\n" o.reset() printf "v=#{o.read()}\n" $ jruby test6.rb v=1 v=2 v=3 NoMethodError: private method `reset' called for #<X:0x11b455e5 @v=3> <main> at test6.rb:7 Ruby allows library users to extend classes. So even if private restricted to class, then it is easy to circumvent. $ type test6hack.rb require_relative 'lib6' class X def myreset() reset() end end o = X.new printf "v=#{o.read()}\n" printf "v=#{o.read()}\n" printf "v=#{o.read()}\n" o.myreset() printf "v=#{o.read()}\n" $ jruby test6hack.rb v=1 v=2 v=3 v=1 Ruby calling methods via send does not check at all. $ type test6hackd.rb require_relative 'lib6' o = X.new printf "v=#{o.read()}\n" printf "v=#{o.read()}\n" printf "v=#{o.read()}\n" o.send(:reset) printf "v=#{o.read()}\n" $ jruby test6hackd.rb v=1 v=2 v=3 v=1 I do not consider those justifications good OO or good software engineering. I prefer the compiler to actually enforce the rules.
> Can you think of another explanation they may be driving at? > For instance, mabye they are questioning why a dynamic language > like PHP has a definition of `private` that is as rigid as > C++'s, while not also providing a `friend`-like abstraction.
That is different discussion. A discussion that come up occasionally. Most dynamic languages chose to implement visibility in some form. When PHP redesigned their OO in version 5.0 they decided to do it Java'ish. And the benefits of encapsulation applies to both static and dynamic languages. Arne