1. 15
  1.  

  2. 4

    Related: it’s always sort of irritated me that Java’s visibility rules conflate things in weird ways.

    Take the three properties:

    1. Callable by subclasses
    2. Callable by code in the same package
    3. Overridable

    These are separate concerns, but you can’t express all combinations. In particular, you can’t express a method that can be overridden by a subclass, but can’t be called by that subclass. You also can’t avoid letting other classes in the same package call an overrideable method.

    To be honest, I’m not sure I need to do that (though I mostly own the projects I work on without arbitrary users extending them, so visibility is just a code-structuring tool between “adults”, as Python puts it), but I’m still annoyed.

    1. 5

      In particular, you can’t express a method that can be overridden by a subclass, but can’t be called by that subclass.

      …why would you want this?

      1. 3

        Lifecycle hooks?

    2. 2

      I find it a bit interesting this mentions lisp, but does not touch on before and after methods at all, which provide a partial resolution to the problem.

      1. 1

        So at first I was like what the heck no I wanna extend all the time (as in I thought of a thousand times where I’ve enjoyed super/call-next-method) but then I remembered the template method pattern from Smalltalk/Java, for Lispers probably better known as

        (define (frobnicate-skele proc foo bar)
          …
          (… bar (proc foo) …)
          …)
        
        (define (frobnicate-horse horse stable)
          (frobnicate-skele (lambda (horse) …) horse stable)
        

        The proc in the skele is the equivalent of BETA’s inner.

        Fair enough, sometimes you want one and sometimes the other 🤷🏻‍♀️

        1. 1

          I suggest adding the date (2012) to the title.

          Stories with similar links:

          1. Calling down with `inner()` instead of calling up with `super()` (2012) via Sietsebb 5 years ago | 1 point | no comments