Hey y'all,

I was just curious about which idiom you prefer or use very often.. and why?

Please vote on the poll! I understand that there are a lot of choices but you can vote for multiples, but try to pick only the ones you think are the best, or most useful, or most elegant to use, i.e., the ones you value most and/or recommend the most.

- Resource Allocation Is Initialization
- Non-copyable
- Factory Functions
- PImpl (Cheshire Cat)
- Singleton
- Lazy construction or evaluation
- Type Traits
- Smart Pointers
- Curiously Recurring Template Pattern
- The Visitor Pattern
- .....

You can also post comments on why you feel a particular idiom is more important than another. And suggest any other idioms that you like if I didn't include them in the list.

I don't want this thread to turn into a huge debate on which idiom is _the_ best one (which doesn't make much sense because they all serve different purposes). But I rather would like people to share what they value most in terms of design objectives and how certain idioms or design patterns serve those objectives better than others. I understand also that I have included both OOP idioms and generic programming idioms, feel free to discuss both.

I hope people will participate.

To get the ball rolling, I should first say that it is incredibly hard for me to find the best in my opinion from the list. Also, some of them I have never used before and some I use all the time.

The PImpl idiom and Factory functions are for me very useful because I have found them to be the ultimate duo for cross-module programming and Application Binary Interfaces (ABI). The former is the well-known compilation firewall and the latter is very useful to control how and where objects get created. But I wouldn't rank either as number one because they don't pertain to all applications and don't necessarily bring much added value in terms of object-oriented programming.

Non-copyable is simple and very useful, and I find that it does add value to an OO design. But still, I would say not significant enough to make it to the top.

It is very hard to choose between Smart Pointers and RAII. They both are an invaluable part of "memory management made easy". But I would have to go with RAII just for the shear elegance of the resulting code. I think it pulled us away from the awful C-style programs filled with HANDLEs and void*.

What is your opinion?

Edited 6 Years Ago by mike_2000_17: n/a

Ho, I didn't expect anyone not to know what a programming idiom is, let alone a veteran poster. Ok, so let me just quote wikipedia's definition, just for the record:

"A programming idiom is a means of expressing a recurring construct in one or more programming languages. Generally speaking, a programming idiom is an expression of a simple task or algorithm that is not a built-in feature in the programming language being used, or, conversely, the use of an unusual or notable feature that is built in to a programming language. The term can be used more broadly, however, to refer to complex algorithms or programming design patterns.

Knowing the idioms associated with a programming language and how to use them is an important part of gaining fluency in that language." -wikipedia.org

I always find myself using the template pattern. The decorator pattern is pretty elegant.

Just some thought, visitor pattern is rarely used, at least for me. And usually, unless its the rare case, using Singleton Pattern is not the answer. Factory patterns are ok. They're nothing unusual. But for the most part, I just code, and find myself using patterns without thinking about them. As for my number one idiom, I don't have one. I haven't got enough experience to claim a favorite.

This article has been dead for over six months. Start a new discussion instead.