Re: Pre-PPC: class :abstract
[email protected] (Aristotle Pagaltzis via perl5-porters)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
* Ovid <[email protected]> [2025-12-20 16:24]: > On Sat, Dec 20, 2025 at 5:04 AM Darren Duncan <[email protected]> wrote: > > That problem is avoided easily enough by the abstract class having > > a default implementation, which in likely most cases would be > > reasonable. > > That is a very dangerous assumption. The following is a trivial example: > > use v5.40.0; > > class StorageHandler { > method connect() { > say "Connecting to generic backend..."; > } > > # If a subclass forgets to override this, the app thinks data > # is being deleted when it isn't. This violates the "fail-fast" principle. > method delete_all_logs($user_id) { > # Doing nothing here is dangerous. > return 1; > } > } > > class CloudStorage :isa(StorageHandler) { > method connect() { > say "Connecting to S3..."; > } > # Developer forgot to implement delete_all_logs! > } > > my $storage = CloudStorage->new; > $storage->connect; > > # The dev thinks they are clearing sensitive data: > $storage->delete_all_logs($user_id); > say "Cleanup complete!"; # Oops All I can see here is a straw man argument. What Darren said is “a reasonable default implementation” but what you chose as an illustration of your argument against it is a stub method, which is not the same thing anyway – and one which violates its own required properties at that. The problem with this example code is not even the provision of a stub but the use of `return 1` as its method body rather than `...` or a `die "Not implemented"` or some such (which would yield exactly the failure that, as per your comment, is required by the fact that the non-implementation of the method results in no data actually being deleted). I see no argument against the concept of a reasonable default implementation here.