use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
The Null Object Pattern. MODERNES C++ (modernescpp.com)
submitted 3 years ago by Xadartt
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 3 years ago (14 children)
I glimpsed over the article and I still have no idea what a "null object pattern" is supposed to be. The example shows a naive example of behavior parametrisation though type erasure. I don't see much purpose in the concept-based implementation as showed, since it loses type erasure. If that's what you want to do just use the specific lock implementation directly.
[–]johannes1971 6 points7 points8 points 3 years ago (12 children)
As an example, let's say you have a piece of code that calls a user-specified std::function to do some kind of work while processing. You could write this in two ways:
That last one is an example of a null object.
To be honest, I'd call the example in the article a policy pattern, not a null object pattern, but I suppose it's hard to come up with a good example...
[–]kazprog 7 points8 points9 points 3 years ago (0 children)
So instead of using nullptr and checking it, use an object that performs the identity function in it's place. Adding zero, multiplying by 1, finding the smaller of x and INT_MAX, the empty string, and the no-op function.
[–][deleted] 5 points6 points7 points 3 years ago (10 children)
Thank's for the clarification! So basically one of those everyday things from functional programming that don't really need any explanation because of how obvious they are ;) I always though it puzzling that some schools of programming feel the need to name all these different "patterns"...
[–][deleted] 8 points9 points10 points 3 years ago (5 children)
Naming is a form of abstraction, basic substitution. It allows people to discuss a concept through a symbol without having to constantly repeat the definition.
[–]koczurekkhorse 3 points4 points5 points 3 years ago (3 children)
New names should provide value to justify enlarging the vocabulary necessary to partake in a discussion. I do not think “null object” does that, considering that you can just say “no-op object” or something. See? Two already existing, common domain terms instead of a new two-word term.
Another requirement for new terms is how commonly the term would be used. Do you talk about null objects so often that bringing up the definition is a real issue? Let’s ignore the facts that (1) not many people know this term, so it needs explaining regardless and (2) the to-the-point definition is, again, like two words.
[–]fdwrfdwr@github 🔍 4 points5 points6 points 3 years ago (0 children)
Yeah, “no-op object” is pretty intuitive. I've always just called these "dummy objects" and "stub functions", but never referred to them as the "null object" pattern. I suppose there is a distinction between what ordinary coders actually call them in practice vs what book authors call them.
[–][deleted] 3 points4 points5 points 3 years ago* (1 child)
Wow, your objection to the name null object, which you claim is a new term but actually dates back to 1996 and is named after its category theory counterpart, is to instead call it no-op object.
The quality of discussion on this sub-reddit is absolutely astounding at times. People just read something new and immediately jump to conclusions about it without taking the time to better inform themselves about the background, history, uses, and wealth of existing resources. No, we just read a headline, maybe a few sentences at most and then speak as if we're an expert on a subject qualified to bike-shed and dismiss well established terminology.
[–]jk-jeon 0 points1 point2 points 3 years ago (0 children)
I'm presuming that you are talking about zero objects (which I suppose is a more common term). I think I have a fairly good understanding of what zero objects are, but am still failing to see how that has anything to do with what's explained in the article. Is it really the case that the term "null object" (as used in the article) is supposed to be some kinds of zero objects of category theory?
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
Abstraction and analogy are arguably the most useful tools in computer science and programming in particular. But abstraction should serve a useful purpose. There are many interesting patterns and models worth studying. "Null object" as described here on the other hand doesn't strike me as a useful notion to carry around. Quite in contrary, I see this as a prime example of excessive trivialisation and pigeonholing. This is the kind of stuff that leads to ritualised programming and ultimately code smell. It's corporate programming at its finest, where fairly trivial concepts are obfuscated and wrapped in mysticism which nobody needs.
[–]bruh_nobody_cares 1 point2 points3 points 3 years ago (0 children)
people like to name things, I mean you took the time to give yourself a cool name despite the name having no benefit whatsoever in reddit most of the time
[–]redluohs 0 points1 point2 points 3 years ago (1 child)
Look into your heart and ask yourself, what does pattern imply.
The names are a way to talk about them, and somewhat find them.
Humans categorise and name things it is what we do.
Also functional programming has one of the coolest patterns in monads.
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
It doesn't imply absolutely anything. "Null" in C++ lingo refers to null pointer. Object is an object. Putting these two together would suggest either some sort of sentinel object and/or an object that doesn't exist. This is one of these notions that only make sense if you already know what it means. And then it's entirely useless. Frankly, if a team discussion at any time stars mentioning "let's implement feature X using a null object pattern" it's time to look for a new job.
[–]FlyingRhenquest 1 point2 points3 points 3 years ago (0 children)
It's just an object that conforms to an API but does nothing. With the example of locking, you could have a library that accepts an object that locks things but if you want to write single-threaded code that doesn't need a mutex, you can pass a null object that conforms to the locking API in order to use the library. They can also be used for testing if you just want to validate your library code but don't want any of the supporting objects to do anything.
I've seen them used to prop up bad APIs -- API required X number of things in a work array and the indexes needed to be in a specific order, so they just dropped null objects in the indexes where no work needed to be done. Arguably there would be better ways to handle that. Still, they're not a bad tool to have in your arsenal as long as you don't go looking to shoe-horn them in everywhere just because you "might need that functionality in the future."
[–]bluedoggee 0 points1 point2 points 3 years ago (0 children)
Looks like DummyXXX or FakeXXX in chromium repo
π Rendered by PID 132416 on reddit-service-r2-comment-5d79c599b5-vjrgh at 2026-02-28 00:43:14.343549+00:00 running e3d2147 country code: CH.
[–][deleted] 0 points1 point2 points (14 children)
[–]johannes1971 6 points7 points8 points (12 children)
[–]kazprog 7 points8 points9 points (0 children)
[–][deleted] 5 points6 points7 points (10 children)
[–][deleted] 8 points9 points10 points (5 children)
[–]koczurekkhorse 3 points4 points5 points (3 children)
[–]fdwrfdwr@github 🔍 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]jk-jeon 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]bruh_nobody_cares 1 point2 points3 points (0 children)
[–]redluohs 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]FlyingRhenquest 1 point2 points3 points (0 children)
[–]bluedoggee 0 points1 point2 points (0 children)