Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)MP
magic_lobster_party @ magic_lobster_party @fedia.io
Posts
0
Comments
419
Joined
12 mo. ago

Permanently Deleted

Jump
  • In your example, the declaration of ArrayList look like:

     
        
    public class ArrayList extends AbstractList implements List {
    }
    
      

    The dependence on AbstractList is public. Any public method in AbstractList is also accessible from the outside. It opens up for tricky dependencies that can be difficult to unravel.

    Compare it with my solution:

     
        
    public class ArrayList implements List {
        private AbstractList = new AbstractList();
    }
    
      

    Nothing about the internals of ArrayList is exposed. You’re free to change the internals however you want. There’s no chance any outside code will depend on this implementation detail.

  • Permanently Deleted

    Jump
  • If the lists have shared components then that can be solved with composition. It’s semantically the same as using abstract classes, but with the difference that this code dependency doesn’t need to be exposed to the outside. This makes the dependency more loosely coupled.

  • Permanently Deleted

    Jump
  • I usually break it out using composition if that’s ever needed. Either by wrapping around all the implementations, or as a separate component that is injected into each implementation.

  • Permanently Deleted

    Jump
  • Ask Bjarne to add interfaces enough many times until he gives in.

    On a more serious note, I’m not exactly sure what the best C++ practice is. I guess you just have to live with abstract classes if you really want interfaces.

  • Permanently Deleted

    Jump
  • In 99% of the cases, inheritance can easily be replaced with composition and/or interfaces. Abstract classes tend to cause hard dependencies that are tough to work with.

    I’m not sure why you would use abstract classes without data. Just use interfaces.

  • Permanently Deleted

    Jump
  • So things like abstract classes are mostly absent from my codebase.

    I believe the consensus nowadays is that abstract classes should be avoided like the plague even in languages like Java and C#.

  • It doesn't matter, why the present is garbage, it's garbage and we should address that.

    The problem is fixing it without inadvertently breaking for someone else. Changing the default behavior isn’t easy.

    There’s probably some critical systems that relies on old outdated practices because that’s the way it worked when it was written 20 years ago. Why should they go back and fix their code when it has worked perfectly fine for the past two decades?

  • I think the general rule of thumb is: Keep it Simple, Stupid.

    Don’t include fields “just in case”. If you don’t have a use for a field right now, then don’t include it. It’s often easier to add fields than removing.

    Avoid having fields that can be derived from other fields. Code “UNAUTHORIZED” can be derived from 403. Having both adds confusion. It adds the question whether the code field be something other than “UNAUTHORIZED” when the response is 403.

    Just 403 with empty body is fine. Add message in a JSON in case it’s useful for the user. If the user needs more fields in the future, then it’s easy to expand the JSON.

  • I haven’t asked that much on SO. Often I can find the answer myself. In other cases my question is so niche I don’t know how to formulate it into a good SO question.

    One of my questions got closed for being duplicate because it was tangentially related to a different question. I got the answer, but it left me a sour taste.