#Learning Design Patterns

25 messages · Page 1 of 1 (latest)

shell wyvern
#

Hi, I'm currently learning design patterns in C++. I'll be reading through some books on the topic, but I know that writing programs with design patterns yourself is the best way to learn, so I have some questions about them, before I start getting my feet wet:

What design patterns are essential to know?

What design patterns do you come across the most in the wild?

What kind of programs should I try to write so I can learn and practise design patterns?

Any other tips or advice?

marsh knollBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

midnight zealot
#

make something you are interested in or you think will be fun first and foremost

rare cosmos
#

Those mentioned by the Gang of four are worth knowing and most commonly cited, although the singleton pattern has since been considered a bad one.

shell wyvern
rare cosmos
#

Some are less applicable than others, but you should be aware of them.

shell wyvern
# midnight zealot make something you are interested in or you think will be fun first and foremost

I am curious about compilers and parser combinators, but that heads into the direction of functional programming. Though you can use the visitor design pattern to process an abstract syntax tree.

I want something simple. Something that I can write to gain some experience in writing design patterns. Something that should pop in my mind later when I get stuck writing some bigger project that could use the same design pattern.

clever sluice
gusty heron
#

Try to keep in mind that design patterns are just patterns that happened to have organically developed in different programs independently. In my opinion, design patterns should not be learned, practiced or followed. At most you can look at them as a curiosity and compare implementations in the hopes that someone did something better than you that applies to your own code.

#

Even with zero exposure to design patterns you will reinvent them all by yourself and understand the need and use through that.

#

There are techniques that arguably somewhat overlap with design patterns that are worth looking through once to be faster at independently reinventing them.

#

Things like type erasure, SFINAE, RAII, rule of 0/5 and CRTP belong to what I'd call techniques.

#

Singletons on the other hand are an example of something so trivial that any beginner will reinvent it.

#

Same for visitors.

shell wyvern
# gusty heron Try to keep in mind that design patterns are just patterns that happened to have...

Yeah, the material and sources I've come across say the same thing. They also mention that design patterns are not only organically developed, but they are also used as technical vocabulary to describe something, and that newcomers to software development lack this vocabulary despite whether or not they have unintentionally programmed any of those design patterns before.

I'm just looking to expand my repertoire of tools. I'm not looking to replace everything with named design patterns. Design patterns, like every other software design tool, can be remixed together into some kind of amoeba.

shell wyvern
# gusty heron Things like type erasure, SFINAE, RAII, rule of 0/5 and CRTP belong to what I'd ...

Hmm, I'm careful with terms like RAII, since they fall into the class of idioms. These are not so transferrable between programming languages. For instance, Java has a GC, so it never needs such an idiom. I'm not sure what the others you mentioned are, but techniques and idioms specific to a programming language are not what I'm quite after. Although, I will ultimately come across and learn them as I continue with C++.

gusty heron
#

I've heard the communication argument, but never experienced it. At least not knowingly. Even if it's true, you can just look up the pattern when someone mentions it.

shell wyvern
gusty heron
#

I'd be very careful with cross-language patterns. What is best practices in one language sometimes is an anti-pattern in another.

shell wyvern
#

That's why I'm broadening my knowledge from CPU registers to parser combinators and other high-level abstractions. These best practices are part of why we don't have a game engine written in, say, Haskell, but, on the other hand, C++ might be a headache when you want to do parsing (at least without libraries).

#

Anyway, I'll have to come up with my own ideas to expand my knowledge.

#

!solved

marsh knollBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

rare cosmos
#

A point worth mentioning though is how frequently job postings mention "Knowledge of design patterns". I'm just a fresh graduate so would love to hear from someone whether that's BS.