1
Feature requests / Re: Conversion of all SFML classes from using private to protected
« on: December 06, 2015, 06:06:27 am »Inheriting your "pausable clock" (i.e. stopwatch") from an sf::Clock means that you are saying that your stopwatch is a "clock that only keeps track of time passed with an ability to restart", since that is what an sf::Clock is.
Except my 'stopwatch' isn't called 'stopwatch' (which is where your assumptions are going horribly wrong), but 'AdvancedClock' with stopwatch-esque capabilities. Chances are I will expand upon that - with the clock arithmetic noted above. Is clock arithmetic a stopwatch only functionality? I'm guessing the answer is 'no'.
Nexus mentioned this already:You make a common mistake: you violate the Liskov Substitution Principle by assuming that stopwatches are clocks and have every property of their base class. Currently, a class invariant of sf::Clock is to be always running and to count the time since the last reset() call.
LSP falls foul of the Circle-Ellipse problem. But what you've got to consider is that each person implements design of a particular feature differently. This isn't an argument of having a stopwatch in SFML... it's the ability to inherit from clock - regardless of what purpose it might be for. Stopwatch is just a 'tip of the tongue' example.
I don't see why it's so important to inherit from sf::Clock rather than to just use sf::Clock.
This isn't just about sf::Clock. It is but one example.
For me, if a class calls a duplicate function of another class (the stopwatch example you've given calls 'getElapsedTime' - which is a duplicate function of sf::Clock), I feel that's a signpost saying 'this class needs to be a subclass', especially if it shares variables and merely 'adds additional functions'.
If I pass my AdvancedClock (to you, a type of stopwatch) to a function, the function can still treat it as though a clock - because it still has those types of variables and functions in-place: getElapsedTime, restart etc.
If I put a clock internal to my AdvancedClock, I cannot use the same functions that could call a clock - despite there being plenty of overlap in accessibility and function usage!
It's quite possible to argue either way. I'm not asking you to accept nor use inheritance in your clock classes, nor anyone else: I'm asking for the ability for myself and others to be able to use inheritance in general.
[It'd allow people to readily expand upon SFML as well - even offering third party libraries that explicitly expand SFML classes. And even that's not your thing, you'd be making my life a lot easier, and probably many others as well.]
The ones that were changed from private to protected.
As soon as the function becomes protected it becomes callable by user code which means SFML can no longer freely change the implementation since that might break user code that calls it and depends on details of the previous implementation.
Ah, there, a valid response to the actual topic.
This is an invalid rebuttal, however, because SFML has often changed things that go on to break user's code - for example, shifting the naming convention from UpperCase style to lowerUpperCase style, the removal of rand etc. I think generally, as a rule, when one uses a codebase under development, they have to expect code breaking changes.
Changing how getSampleRate() works is no different if it was a private, public or protected function. Indeed, any changes to the original function would apply less in the case of a subclass - which often overloads the original function.
I think not wanting to change something because it might break code isn't legitimate here, because one could use that to argue for a stagnant SFML with no changes. I wouldn't mind if they changed something fundamentally - because with protected access, chances are I could easily add in a work around.
I've now got three classes out of SFML with dopplegangers due to the inability to inherit: Clock, HTTP and SoundBuffer.