The Artima Developer Community
Sponsored Link

Articles Forum
My Most Important C++ Aha! Moments...Ever

25 replies on 2 pages. Most recent reply: Oct 31, 2006 4:27 PM by Mike Petry

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 25 replies on 2 pages [ 1 2 | » ]
Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

My Most Important C++ Aha! Moments...Ever Posted: Sep 6, 2006 10:00 AM
Reply to this message Reply
Advertisement
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 dhamija

Posts: 1
Nickname: jkd20
Registered: Sep, 2006

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 6, 2006 11:39 PM
Reply to this message Reply
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 O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 7, 2006 2:02 AM
Reply to this message Reply
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 Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 7, 2006 8:14 AM
Reply to this message Reply
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 Slettebø

Posts: 205
Nickname: tslettebo
Registered: Jun, 2004

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 7, 2006 9:27 AM
Reply to this message Reply
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 Dekker

Posts: 9
Nickname: dekker
Registered: Sep, 2006

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 7, 2006 1:39 PM
Reply to this message Reply
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 Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Metaprogramming Posted: Sep 7, 2006 4:38 PM
Reply to this message Reply
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 Saulnier

Posts: 77
Nickname: vorlath
Registered: Dec, 2005

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 7, 2006 9:08 PM
Reply to this message Reply
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 Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 8, 2006 9:15 AM
Reply to this message Reply
Probably RAII. I don't think any other idiom changed my programming style as much.

Glenn Puchtel

Posts: 5
Nickname: gpuchtel
Registered: Aug, 2006

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 8, 2006 11:33 AM
Reply to this message Reply
While reading 'Object-Oriented Analysis and Design with Applications' by Grady Booch.

Sumant Tambe

Posts: 2
Nickname: sutambe
Registered: Sep, 2006

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 8, 2006 1:58 PM
Reply to this message Reply
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 Pibinger

Posts: 93
Nickname: rp123
Registered: Jan, 2006

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 9, 2006 12:58 AM
Reply to this message Reply
> 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 Pibinger

Posts: 93
Nickname: rp123
Registered: Jan, 2006

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 9, 2006 1:03 AM
Reply to this message Reply
> 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 Slettebø

Posts: 205
Nickname: tslettebo
Registered: Jun, 2004

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 10, 2006 3:46 AM
Reply to this message Reply
> 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 Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: My Most Important C++ Aha! Moments...Ever Posted: Sep 10, 2006 2:45 PM
Reply to this message Reply
> > 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.

Flat View: This topic has 25 replies on 2 pages [ 1  2 | » ]
Topic: A Brief Look at C++0x Previous Topic   Next Topic Topic: Human-Oriented Architecture

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use