Herb Sutter

gotw.ca · Personal blog · on HN since 2008

Herb Sutter writes about C++, including the Guru of the Week series, and about concurrency in software.

What HN saysHN commenters cite his C++ articles and books for best practices and the class interface principle, and his 2005 article on the move to concurrency.
84HN people shared it
56linked it in comments
31stories submitted
469story points
4 months agolast shared
2008people per year2026

Most-shared posts

  1. 1
  2. 2
    Ritchie, Stroustrup, and Gosling interview
    14 people · 264 points · first shared 2010 · 22 comments on HN
  3. 3
    C++ Guru of the Week Archives
    6 people · 2 points · first shared 2008 · discussion on HN
  4. 4
  5. 5
    Gotw 008
    3 people · first shared 2011
  6. 6
    Mill18
    2 people · first shared 2018
  7. 7
    Gotw 024
    2 people · first shared 2015
  8. 8
    Gotw 066
    2 people · first shared 2014
  9. 9
    Gotw 081
    2 people · first shared 2013
  10. 10
    Xc
    2 people · first shared 2014
  11. 11
    Mill02
    2 people · first shared 2016
  12. 12
    Mill16
    2 people · first shared 2015
  13. 13
  14. 14
    Null References (2000)
    1 people · 2 points · first shared 2020 · discussion on HN
  15. 15
    The String Formatters of Manor Farm (2001)
    1 people · 1 points · first shared 2021 · discussion on HN

What HN people wrote when they linked it

AnotherGoodName · 2025-08-25
std::vector<bool> is the actual biggest stl blunder fwiw. It’s a overridden specialisation of vector that only occurs when you use bool as the type. It tries to store the bools in a bit array which completely breaks various vector and container functionality. Universally agreed as a blunder and a great example of premature optimisation. Herbs commentary on it: http://www.gotw.ca/publications/N1185.pdf
DrDimension · 2016-02-15
I'm going to have to pose an educated disagreement. According to the classic C++ article, "What's in a class?" by Herb Sutter (http://www.gotw.ca/publications/mill02.htm) - The Interface Principle suggests - For a class X, all functions, including free functions, that both (a) "mention" X, and (b) are "supplied with" X are logically part of X, because they form part of the interface of X. So yes, f(x) is part of x's interface in C++, and has been considered to be so for a long time.
Someone · 2014-12-15
Herb Sutter's Guru of the week is a nice collection of gotchas/best practices: http://herbsutter.com/gotw/ And of course, his books (More) Exceptional C++ (http://www.gotw.ca/publications/xc++.htm, http://www.gotw.ca/publications/mxc++.htm) also contain nice examples.
conexions · 2013-08-30
Herb Sutter wrote a good article on this a few years ago. It was written in 2005 and centered mostly on multi-threading and parallel programming, but definitely worth a read. http://www.gotw.ca/publications/concurrency-ddj.htm
Steko · 2012-01-24
He's talking simply about clock speed which used to make regular gains with Moore's law but ran up against the heat limits of silicon awhile back. The original article that this follows on gives additional background: http://www.gotw.ca/publications/concurrency-ddj.htm
cpeterso · 2011-10-30
Herb Sutter and Andrei Alexandrescu's C++ Coding Standards: 101 Rules, Guidelines, and Best Practices is a great, little book. It does not teach C++ (or C++11) and seems a little light at first, but it provides good advice for "modern" (21st century) C++ and gotchas from "good practices" from many 20th century C++ books. Herb Sutter's website has more details about the book and some articles with excerpts: http://www.gotw.ca/publications/c++cs.htm
chadaustin · 2010-02-12
If you're on Windows, the MSDN Library DVDs that come with Visual Studio are a great resource. They have accurate and comprehensive documentation on the syntax and standard libraries. I've worked with some people who used Google as a C++ reference, but they'd often write code with subtle problems because some random blog or reference isn't a good way to build a solid understanding. I'd suggest going straight to the source: the standard (it's not that complicated), your compiler's documentation, and Guru of the Week: http://www.gotw.ca/gotw/
Erf · 2008-04-16
I recommend Herb Sutter's classic Guru of the Week articles: http://www.gotw.ca/gotw/ There's a lot of usually-uselss arcane stuff in there, but also a lot of valuable information.
MaxBarraclough · 2020-12-02
> RAII can be decoupled from ctor/dtor mechanism, see Python's 'with' statement That may be a useful language feature, but I don't count that as full RAII. I'm inclined to agree with Wikipedia's definition that the destructor must run whenever the object's lifetime ends, to count as proper RAII: > resource deallocation (release) is done during object destruction (specifically finalization), by the destructor As x can presumably leak from the with block of your example, it isn't full RAII. I think it's equivalent to the confusingly named using feature of C#. [0] > throwing exceptions from ctors or, worse, dtors. Herb Sutter used to have a loooong list of what can go wrong in such situations Thanks for the pointer ( or should that be reference? :-P ), these are an interesting read. [1][2][3] > Explicit error codes happen to make it impossible to write ctors / dtors that can enter an error state by virtue of the fact that there is no way to return the error Yes, but this approach detracts from the RAII somewhat, as it means the programmer must move the substantial code out of the constructor and into a post-construction initialization member-function capable of throwing. That may be a price worth paying, but I do consider it a price, as we've lost a useful invariant: we must now keep track of which instances are in the constructed-but-unready state. An unfortunate slide back toward C. > My suspicion is that this is 50% of the reason of banning C++ exceptions in solid…
corysama · 2020-04-10
The megahertz-scaling "Free Lunch" was declared dead 15 years ago [http://www.gotw.ca/publications/concurrency-ddj.htm] and it's been only getting deader. People are finally, grudgingly accepting that they must go parallel unless we want to see software performance stagnate permanently. For most people here, the issue has been obvious since before they learned to program. But, still they are putting off learning how to deal with it. The first, obvious answer to that is threading. But, in my experience, SIMD is a bigger bang for the buck for two reasons: 1) No synchronization problems. 2) Better cache utilization. It's not just that SIMD forces you to work in large, contiguous blocks. Fun fact: When you aren't using SIMD you are only using a fraction of your L1 cache bandwidth! A big challenge is that SIMD intrinsic-function APIs are weird. They have inscrutable function names and sometimes difficult semantics. What helped me greatly was going through the effort of writing #define wrappers for myself that just gave each function in SSE1-3 names that made sense to me. I don't expect many people to put in that effort. And, unfortunately, I don't have go-to recommendations for pre-existing libraries. Best I can do is: https://github.com/VcDevel/Vc is working on being standardized into C++. It's great for processing medium-to-large arrays. https://ispc.github.io/ is great for writing large, complicated SIMD features. https://github.com/microsoft/DirectXMath is…
mannykannot · 2016-12-04
While I do not disagree with Fowler's criterion as being one of several to consider, The ability of function (and identifier) naming to make code "easy to understand at a glance" is frequently overstated, including in this article. Once code reaches a size where it is moderately complicated, the reasons for some action being done in a particular way are not necessarily locally obvious (or obvious at all.) One common reason for this is that things are being done in a particular way to conform to a contract that is relied upon in multiple, disparate parts of the program (and any reasonably large program does have such contracts, even if it was not produced by an explicitly design-by-contract methodology.) For a flavor of how this works, read the article [1] below, in response to Tom Cargill's classic article 'Exception Handling: A False Sense of Security'. Even though the code example here is small enough to be understood in one go, I doubt that the reasons for it being the way it is are immediately obvious to most programmers, unless they have been primed by exposure to the issue before (note that the first answer given was not entirely correct.) [1] http://www.gotw.ca/gotw/008.htm
rootlocus · 2016-11-24
> you should probably prefer the first definition ("go around, past the edge of") instead of the fourth definition, as you've done here. That was the third definition. The first definition was "a woman's outer garment fastened around the waist and hanging down around the legs." /snark > we should look more at end-user satisfaction and less at often pedantic technical analyses of solutions. They aren't orthogonal. User satisfaction comes from a smooth experience. Regardless of how shiny something is, if it slows down the rest of the system (or is itself laggy) users will notice. I choose to run foobar instead of other music players because it's small and fast. > are we further limiting a great web UX to those with the money to afford the latest laptops? This is what infuriates me. People have been talking about how the "free lunch" is over [1] since 2009. About how CPUs have stopped getting faster, and how we should make the best out of the current hardware by learning to paralelize. Yet javascript is the most popular language and it's fundamentally single threaded. High quality software is not about having "a great web UX". VLC doesn't have it (great web UX). Blender doesn't have it. Intellij IDEA doesn't have it. And they're not only extremely complex and efficient softwares, they also have great UIs. Our computers are extremly powerful. The fact that someone would wonder if they're not enough to run pretty clipboard managers and fancy text editors is making me…
millstone · 2014-08-13
Without meaning any disrespect, this is a sort of naive perspective that comes about when you consider a language in isolation. When you try to use exceptions, you'll quickly encounter the following: 1. Your C++ code may be called by C code that knows nothing of exceptions. 2. Exceptions have big implications for API design. See for example GOTW #8 http://www.gotw.ca/gotw/008.htm , which acknowledges that "some interfaces can't be implemented in an exception-safe manner." 3. try/catch/throw have performance impact. Compilers optimize for the no-exceptions-thrown case, and the practical cost of throwing an exception can be prohibitively high. Google "Zero-cost Exception" for more. The net result is that proper exception handling is difficult to incorporate gracefully, and "exceptions are all fatal errors" is a very reasonable position. Last I checked, Firefox is compiled with -fno-exceptions, and this is how Cocoa frameworks work as well.
breckinloggins · 2013-09-26
I have a prediction about where this will go: First, things will continue about the way they are now: cores will stay at the same speed or get slower but there will be more of them. The industry will stay this way for at least the next 5 to 10 years, and during that time we are going to get better and better figuring out how to take advantage of the increasing number of cores. Finally, at some point in the future (I predict between 10 and 15 years), we are going to see an explosion in materials science that allows us to suddenly jump from 3 - 5GHz / core to 400 GHz - 5 THz per core (with even more cores than we have now and dramatically lower power consumption). At this point we will be nicely prepared to exploit both the parallelism and the return of raw speed gains. We'll also see completely different architectures like Chuck Moore's greenArrays, quantum co-processors, "memory/compute fabrics" like memristor crossbar arrays, and further advancements in the GPU/APU area. These changes will continue to challenge our assumptions about what are the "proper" paradigms, languages, and architectures for computer programs. We've made great progress already. I can think of myself as an example: in 2005 I, like most of the programmers here, read Herb Sutter's essay The Free Lunch Is Over[1] and realized that he was correct: the era of easy speedups was giving way to the era of concurrency. And programmers were going to have to figure out how to take advantage of that…
barrkel · 2012-06-19
Signed arithmetic is generally only problematic when you hit the upper or lower bound. The right answer is almost never to use unsigned; instead, it's to use a wider signed type. It's far too easy to get things wrong when you add unsigned integers into the mix; ever compare a size_t with a ptrdiff_t? Comes up all the time when you're working with resizable buffers, arrays, etc. And no, Java did not choose signed by default because of legacy. http://www.gotw.ca/publications/c_family_interview.htm: "Gosling: For me as a language designer, which I don't really count myself as these days, what "simple" really ended up meaning was could I expect J. Random Developer to hold the spec in his head. That definition says that, for instance, Java isn't -- and in fact a lot of these languages end up with a lot of corner cases, things that nobody really understands. Quiz any C developer about unsigned, and pretty soon you discover that almost no C developers actually understand what goes on with unsigned, what unsigned arithmetic is. Things like that made C complex. The language part of Java is, I think, pretty simple. The libraries you have to look up." Unsigned is useful in a handful of situations: when on a 32-bit machine dealing with >2GB of address space; bit twiddling where you don't want any sign extension interference; and hardware / network / file protocols and formats where things are defined as unsigned quantities. But most of the time, it's more trouble than it's worth.
Interview from http://www.gotw.ca/publications/c_family_interview.htm (I'm including Stoustrup, since C++ was probably one of the influences of the choice of syntax familiy) Q: What languages, or features of languages, inspired you? Stroustrup: In addition to Simula67, my favorite language at the time was Algol68. I think that "Algol68 with Classes" would have been a better language than "C with Classes." However, it would have been stillborn. Gosling: They're all over the map. Using Lisp, the thing that influenced me the most was the incredible difference garbage collection made. Using Simula and being a local maintainer of the Simula compiler was really what introduced me to objects and got me thinking about objects. Using languages like Pascal got me really thinking about modeling. Languages like Modula-3 really pushed things like exception mechanisms. I've used a lot of languages, and a lot of them have been influential. You can go through everything in Java and say, "this came from there, and this came from there."
pjmlp · 2026-07-10
The reason is in this interview, http://www.gotw.ca/publications/c_family_interview.htm > Quiz any C developer about unsigned, and pretty soon you discover that almost no C developers actually understand what goes on with unsigned, what unsigned arithmetic is. Things like that made C complex. The language part of Java is, I think, pretty simple. The libraries you have to look up. You have the option in the standard library, all numeric classes have unsigned arithmetic methods. And as we are finally getting value classes in Java (first integration steps), I expect someone will come up unsigned wrapper classes rather quickly, although it will be rather verbose without operator overloading.
keithalewis · 2024-03-23
What does this do for you that the NVI idiom doesn't http://www.gotw.ca/publications/mill18.htm?
guenthert · 2024-03-08
To expand on this, "In naturally written C++ code, changing the private members of a class requires recompilation of the code using the class." -- uh, the Pimpl pattern has been idiomatic C++ for a long, long time (http://www.gotw.ca/gotw/024.htm).
sgbeal · 2023-11-11
Not a book, but an article: Herb Sutter's "What's in a Class?" completely changed the way i thought about OO programming and still holds up today. <http://www.gotw.ca/publications/mill02.htm> PS: plus anything by C++ guru Scott Meyers.
rileymat2 · 2022-12-19
> This is checked exceptions all over again... That is an interesting topic, as I went through the cycle of adding and removing them, they always felt like the right thing, but they felt like "work". They make coding less fun, having to think through failure conditions, like you say, you don't care about. I guess the answer is really there is no one sized fits all solution, we have some applications where the correct solution is to crash, we have other applications that can't crash under any condition. You just need to know where you are. Edit: Also, out of the box C++ checked exceptions implemented terribly. http://www.gotw.ca/publications/mill22.htm The (Mis)understanding section describes it pretty well.
criddell · 2022-11-24
Herb Sutter (Microsoft C++ guy) has been talking about the twilight of Moore’s law since 2005ish and I think he’s right. http://www.gotw.ca/publications/concurrency-ddj.htm
af78 · 2022-01-01
> I don't know why they couldn't have chosen something like `std::hash_map` According to Herb Sutter the name `hash_map` (or `hashmap`) had already been taken by some C++ standard library implementation that shipped a class with this name in the std namespace: http://www.gotw.ca/publications/mill20.htm
ioquatix · 2020-04-17
I completely agree it is difficult and that's also my point - that shared multi-thread is very tricky to get right, and there is a significant benefit to isolated event loops (even if they are running on threads, they should be isolated). I like this article by Herb Sutter "The Trouble With Locks". http://gotw.ca/publications/mill36.htm I have used multi-(fiber/thread/process) extensively, and at the right place they are useful tools. But by far, threads which share data (especially opaque) are the most tricky to get right. The combinatorial explosion of program states is very hard to deal with in practice and "it works for me" is a very common testing strategy.
bcrosby95 · 2020-02-18
Not only disruptive to their industry, but game changing for those of us writing software. I remember reading all the hoopla over the loss of Dennard scaling 15 years ago (e.g. http://www.gotw.ca/publications/concurrency-ddj.htm). Intel poked along at 2 and 4 core consumer systems for so long. The argument was always "no one can use more than X cores" - but software seems to trail hardware in these examples, not the reverse. When Zen was first released, many of the less expensive 6 core options performed worse than Intel's similarly priced 4 core chips. But when comparing modern software using those old parts, AMD's 6 core offerings tend to hold up better. It feels like AMD is finally ushering us into an era where being able to take advantage of large amounts of parallelism is going to become important for almost every developer.
codr7 · 2019-12-26
Itani-who? But you won't when writing C++ unless you absolutely have to, because it's a major pita to encapsulate everything. Entire books [0] have been written about exception safety in C++. Getting it right in combination with RAII, (copy)-constructors and assignment operators is very tricky. Which touches the main issue with C++ from my experience, mixing foot guns with higher level convenience. Embedded linked lists [1] is a good example. Seriously, live and let live. I'm fine with you enjoying and preferring C++, go for it. But consider taking a good look in the mirror and asking yourself why you feel the need to spread FUD about C to feel good about your choice. [0] http://www.gotw.ca/publications/xc++.htm [1] https://github.com/codr7/libceque/blob/master/source/libceque/list.h
sclangdon · 2019-08-20
C++, rather than C, but there was a GOTW post about this years ago, which explains the situation in detail. http://www.gotw.ca/gotw/081.htm
RcouF1uZ4gsC · 2019-05-23
I think Herb Sutter's 2005 article "The Free Lunch Is Over" was a signal that this was changing. http://www.gotw.ca/publications/concurrency-ddj.htm
nchie · 2018-11-15
Well, there is a way to have them on the stack even with PImpl: http://www.gotw.ca/gotw/028.htm However I'd say it's an ugly hack which should only ever be used if you _really_ need the performance.
wolf550e · 2018-06-24
This "future of programming" was very widely announced in 2005: http://www.gotw.ca/publications/concurrency-ddj.htm

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close