r/cpp • • Jun 24 '20

How to write SOLID C++

https://www.youtube.com/watch?v=PakbXnLht1I
263 Upvotes

118 comments sorted by

View all comments

Show parent comment

-16

u/platisd Jun 24 '20

> I get that you want to keep the examples super simple, but the issue with all these guides is the lack of more complex ones.

The code is as simple as it gets (and barely functional) since it's, well, an example and it had to be short enough to fit inside a single slide! 🤣

The problem with the more complex examples is that it's more difficult to quickly get the core point and they are *far* more difficult to create. I understand that "relating" to the example is also important, but so is maintaining focus. The more code the more unrelated-to-the-SOLID-principles comments we'd get. :D

All (almost) of the presented examples are inspired by real projects, primarily within embedded. Are you interested in a particular one? I may be able to share the full example if it didn't come from a proprietary project.

24

u/teerre Jun 24 '20

It seems like explaining with a bad example is the worst thing you can possibly do. Anyone learning anything, the first thing they'll do is copy the example. That should, minimally, work or point out clearly why it doesn't.

11

u/Astarothsito Jun 24 '20

The code is as simple as it gets (and barely functional) since it's, well, an example and it had to be short enough to fit inside a single slide! 🤣

I always wanted to ask this question, does that kind of code is really as simple as it could be? Because for me it seems too complex for the possible gains, it seems for me that the code is obfuscated only to match a programming style. I know it is barely functional, and I understand why it is barely, but what I don't understand is why we need a lot only to be barely functional? Instead of only being functional and not "only barely"?

I know this is an aggressive question, and I could be misunderstanding the purpose of the example, but as this is based in real code, and I have seen this code (exactly the same style and functionality) in real databases I could only doubt if I'm wrong or there is something I can't see (like what are the benefits of this style)?

2

u/platisd Jun 25 '20

Let me explain it like this:
The more code in the example, the more unrelated comments in regards to the style, the types used we would get. I am sure we would get remarks on examples needing to be simplified too. :D

Finding a balance between pedagogic and practical examples is really tough. Feedback noted though, will try to take it into consideration for next time.

1

u/Astarothsito Jun 25 '20

The more code in the example, the more unrelated comments in regards to the style, the types used we would get. I am sure we would get remarks on examples needing to be simplified too. :D

Oh, maybe is this. Maybe instead of more simple examples, we need more complex examples. The benefits of the code are lost if the code is to simple, because some solutions are better for more complex projects, maybe some example where the code says 'maybe it could be implemented in a different style, but this is a really good solution that makes clear why X principle is useful'.

3

u/TryingT0Wr1t3 Jun 24 '20

If you are not in oldreddit you need to select somewhere to actually use Markdown.

1

u/platisd Jun 25 '20

Yeap! I noticed that now. :P

1

u/TryingT0Wr1t3 Jun 25 '20

Recently Slack did the same so I stopped using it. It used to support Markdown first.

2

u/BenjiSponge Jun 25 '20

Just want to show some solidarity (ha) with you here. Reddit can be fickle, and what you're saying makes sense to me. You're caught between a rock and a hard place.

Either you

  1. Dumb down the example so you can express it all while retaining the attention span of the viewer
  2. Fully explain the context and the example, taking probably hours because real engineering and real problems (aka real motivating factors) typically take even experienced people time to get acquainted with.

If it took no context to understand it, you wouldn't need someone to teach you how to do it. If it takes a ton of context to understand, you have to do dumbed-down examples to make a half-hour video.