magic_lobster_party

joined 1 month ago
[–] [email protected] 40 points 3 days ago

Drawing hands is hard

[–] [email protected] 59 points 1 week ago

I liked when they said “it’s concording time” and concorded all over the place.

[–] [email protected] 2 points 2 weeks ago

Turn on a lamp

[–] [email protected] 2 points 2 weeks ago (2 children)

The only problem is to ensure the entire team agrees to only use it like an interface and nothing else. But I guess that’s the only proper way to do it in C++, for now.

[–] [email protected] 0 points 2 weeks ago (1 children)

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.

[–] [email protected] 1 points 2 weeks ago (3 children)

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.

[–] [email protected] 2 points 2 weeks ago

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.

[–] [email protected] 3 points 2 weeks ago (4 children)

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.

[–] [email protected] 5 points 2 weeks ago (20 children)

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.

[–] [email protected] 0 points 2 weeks ago (22 children)

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#.

[–] [email protected] 0 points 2 weeks ago (3 children)

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?

[–] [email protected] 63 points 2 weeks ago (6 children)

Well someone must pull that switch and push that cart. Only a highly trained professional from MIT can do it.

view more: next ›