Article Discussion
My Most Important C++ Aha! Moments... Ever
Summary: In this article, Scott Meyers shares his picks for the five most meaningful Aha! moments in his involvement with C++, along with why he chose them.
26 posts on 2 pages.      
« Previous 1 2 Next »
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: October 31, 2006 4:27 PM by
Bill
Posts: 409 / Nickname: bv / Registered: January 17, 2002 4:28 PM
My Most Important C++ Aha! Moments...Ever
September 6, 2006 9:00 AM      
In this article, Scott Meyers shares his picks for the five most meaningful Aha! moments in his involvement with C++, along with why he chose them.

http://www.artima.com/cppsource/top_cpp_aha_moments.html

What were your most important aha! moments in C++?
Jitendra
Posts: 1 / Nickname: jkd20 / Registered: September 6, 2006 5:00 PM
Re: My Most Important C++ Aha! Moments...Ever
September 6, 2006 10:39 PM      
My most important Aha moment had been when came to know about the function objects.

() operator can be overloaded and the object can itself act as a function !!
Vincent
Posts: 40 / Nickname: vincent / Registered: November 13, 2002 7:25 AM
Re: My Most Important C++ Aha! Moments...Ever
September 7, 2006 1:02 AM      
Enough already! It's like hearing the same joke over and over.

What's next? The Most Important Piece of Cable that's ever carried C++?

(Please tell me we're not going to go through this a dozen times for every language.)
Achilleas
Posts: 98 / Nickname: achilleas / Registered: February 3, 2005 2:57 AM
Re: My Most Important C++ Aha! Moments...Ever
September 7, 2006 7:14 AM      
I never had any aha moments...C++ was always a struggle for me...an endless chase of pointers, analysis of crashes, and things like that!
Terje
Posts: 33 / Nickname: tslettebo / Registered: June 22, 2004 8:48 PM
Re: My Most Important C++ Aha! Moments...Ever
September 7, 2006 8:27 AM      
One of my biggest aha! moments with C++ came when I learned that you could do metaprogramming in C++ (from Todd Veldhuizen's work: http://osl.iu.edu/~tveldhui/papers).

I was working with things like 3D graphics at the time, and compilers weren't that very good to do things like automatical loop-unrolling and similar optimisations, so I was thrilled to learn that you could actually make the compiler do this, yourself... As well as other program transformations and computations.

As is now well known, C++ happens to have a Turing-complete language at compile-time, which makes theoretically any transformation or computation - where the data is available at compile-time - possible.

You may even do it partially at compile-time, partially at run-time, and take advantage of any information existing at compile-time, to make execution more efficient or safe (the latter coming more from static typing, than metaprogramming).

In a sense, the C++ template system - with its non-type template parameters - is a little like a dependent type system.
Niels
Posts: 9 / Nickname: dekker / Registered: September 7, 2006 6:14 AM
Re: My Most Important C++ Aha! Moments...Ever
September 7, 2006 0:39 PM      
Understanding how to write an exception safe copy assignment operator, using a swap helper function. My first attempts to implement a decent assignment for a non-trivial class failed miserably. I tried (quite literally!) to assign all of its data members, catching all possible exceptions, but I ended up having hopelessly corrupted objects. I'm pretty sure I first read about using a non-throwing swap to implement operator= in an article by Herb Sutter. My initial reaction was "huh?!?" But it was followed quickly by a big "Aha!" :-)
Max
Posts: 18 / Nickname: mlybbert / Registered: April 27, 2005 11:51 AM
Metaprogramming
September 7, 2006 3:38 PM      
I have to pick metaprogramming as well. And RAII. And "wow, this sure has a lot more power than Java does" which was more a Java Aha moment than a C++ Aha moment ("lemme write this quick one-off; should I use Java or C++? in C++ I'd ..., in Java I'd ..., wait a minute, Java gives me fewer choices!")
Cleo
Posts: 6 / Nickname: vorlath / Registered: December 16, 2005 1:35 AM
Re: My Most Important C++ Aha! Moments...Ever
September 7, 2006 8:08 PM      
My best Aha! moment wasn't directly related to C++ although it uses it. I realised that programming doesn't need functions, execution points or any execution control statements at all. These things actually make programming restrictive. This makes the Turing machine irrelevant and makes your software instantly portable without any VM or anything like that. You just need a small 'kernel' that will handle the low level execution handling for you which will then be linked into your software's executable. In other words, it'll handle the Turing machine side of it. This can be written in C++ or whatever language. It's a 30 year old idea that will probably take another 30 years to come to fruition by the looks of things.
Nemanja
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: My Most Important C++ Aha! Moments...Ever
September 8, 2006 8:15 AM      
Probably RAII. I don't think any other idiom changed my programming style as much.
Glenn
Posts: 3 / Nickname: gpuchtel / Registered: August 11, 2006 0:41 AM
Re: My Most Important C++ Aha! Moments...Ever
September 8, 2006 10:33 AM      
While reading 'Object-Oriented Analysis and Design with Applications' by Grady Booch.
Sumant
Posts: 2 / Nickname: sutambe / Registered: September 8, 2006 7:43 AM
Re: My Most Important C++ Aha! Moments...Ever
September 8, 2006 0:58 PM      
My first Aha! moment was when I understood how Singleton design pattern works by making the constructor private and a public static method. Another one was pretty recent when I understood how execute-around method like pattern can be implemented in C++ using "Double Application of Smart Pointers". Given here: http://www.aristeia.com/sdnotes_frames.html
Roland
Posts: 25 / Nickname: rp123 / Registered: January 7, 2006 9:42 PM
Re: My Most Important C++ Aha! Moments...Ever
September 8, 2006 11:58 PM      
> Probably RAII. I don't think any other idiom changed my
> programming style as much.

The same for me!
Private copy constructors and assignment operators are closely related to RAII. But the rest of the Aha-list (2 misnomers, a trick that "had little impact") is rather strange.
Roland
Posts: 25 / Nickname: rp123 / Registered: January 7, 2006 9:42 PM
Re: My Most Important C++ Aha! Moments...Ever
September 9, 2006 0:03 AM      
> I never had any aha moments...C++ was always a struggle
> for me...an endless chase of pointers, analysis of
> crashes, and things like that!

Absorb RAII and the struggle will go away.
Terje
Posts: 33 / Nickname: tslettebo / Registered: June 22, 2004 8:48 PM
Re: My Most Important C++ Aha! Moments...Ever
September 10, 2006 2:46 AM      
> My best Aha! moment wasn't directly related to C++
> although it uses it. I realised that programming doesn't
> need functions, execution points or any execution control
> statements at all. These things actually make programming
> restrictive. This makes the Turing machine irrelevant and
> makes your software instantly portable without any VM or
> anything like that. You just need a small 'kernel' that
> will handle the low level execution handling for you which
> will then be linked into your software's executable. In
> other words, it'll handle the Turing machine side of it.
> This can be written in C++ or whatever language. It's a
> a 30 year old idea that will probably take another 30
> years to come to fruition by the looks of things.

This sounds interesting, could you elaborate on it, or give any pointers to where to learn about this idea?
Cameron
Posts: 26 / Nickname: cpurdy / Registered: December 23, 2004 0:16 AM
Re: My Most Important C++ Aha! Moments...Ever
September 10, 2006 1:45 PM      
> > I never had any aha moments...C++ was always a struggle
> > for me...an endless chase of pointers, analysis of
> > crashes, and things like that!

> Absorb RAII and the struggle will go away.

OMG. I went and looked up RAII and was [hardly?] surprised to see that it is nothing but "clean up in a destructor". Wow, that was a waste of a half hour of reading.

What next? Maybe we could use CFront to add methods to structs? ;-)

The problem in large-scale C++ wasn't cleaning up stuff in a destructor, it was knowing when you could (and when you had to) destroy things. Modern platforms (i.e. what we've been using for the past 10 years) automatically handle this for us perfectly -- in most cases.

Peace.
26 posts on 2 pages.
« Previous 1 2 Next »