Tuesday, June 28, 2005


Never, in the recent past, have I been so occupied with various stuff. (Observe no posts since friday!) Ummm - Well lets see where to start - Okay weekend.

Saturday morning I get up, I don't why/how, but I feel this sudden urge to go to a book shop and buy some books. So, I leave for book paradise right after a late breakfast. 3 hours later, I'm at home with 5 books!

1) Exceptional C++ - Herb Sutter
2) More exceptional C++ - Herb Sutter (This guy's the chief architect for the MS VC++ team)
3) Design Patterns - By the famous 'gang of 4'
4) C traps and pitfalls - Andrew Koenig
5) Excuses, excuses, excuses - [Don't remember the author - but really funny to read!]

I got so much engrossed into the books that I skipped some social function on sunday. Monday I come to office and viola, loads of work formed right in front of me - like manure from compost!! As I'm writing this, I see a mail pop-up... must be another escalation! Phew! Yesterday, there were many small discussions...

1) Avinash was of the opinion that the 'singleton' pattern does not need any special implementation in C++. According to him, a class with just static data and static members would be as good as a singleton.
Partly agreeable. 'Cos static members are class wide - so there would be only single instances of all the members. But there's nothing that's expressly disallowing users from instantiating multiple objects. Also, without careful class design, there's no way to control the construction and destruction of these static members. May be the members need a constructor-like initialization and not just static initialization. But something to think about anyway.

2) Goutham - One of the constant critiques of C++ questions that in the C++ singleton implementation, why is there a need for a private static handle to the same class - why can't the private handle be a normal member of the class?
Okay, had not really thought about this. What I feel is that such a construct is not safe. A pointer within an object (just 1 object - mind you, its a singleton) to self - No, that's not safe. What might happen if that object is to be serialized onto backing store? Object serialization usually uses deep-copy semantics. This means, that the object serialization would recurse endlessly. This was what I could think of. There might be other and more compelling reasons for it too.

3) Microsoft is drafting the new C++/CLI standard that's likely to get approved in 2006/2007. What the new standard is all about is bringing 'Concrete C++ language on the virtual platform' (As quoted by Herb Sutter in his keynote address at the OOPLSA). What is aims to do is to bring the best from the worlds of C++ and managed languages together.
Imagine -
'Destructors and finalizers' together! ( T::~T() and T::!T() - These are the new syntax)
'Templates and Generics' together!
Ability to create objects on system heap or the managed runtime heap!
(T* ptr = new T; and T^ gcPtr = gcnew T; - This is the new syntax)
The complete video of the keynote address is available here. Do have a look at it! Sounds exciting! (Herb Sutter is a great speaker)

Ah well, time for me to get out of my tech fantasy and attend to my work at hand... OnO.


  1. Hey... neat post.. i want to buy those books too.. i have been far away from any tech books lately.. high time i start digging again :-)
    We will discuss abt the new draft for C++/CLI next we meet up! ;-)

  2. Eh - got a question, doc.

    Regarding point 1 of your discussion... Wouldn't you be able to disallow unrestricted construction of objects by making the constructor private and just opening up a static public query method that creates an object if that has not already been created and returns that. That way you have just a single instance of that class, and you can keep all your member variables and methods static i.e class-wide.

  3. Ah! Now I got you!
    You still dont have a convincing answer (atleast I am not convinced) for my question. You cooked up something and just shut me up the other day...and on the blog you are still "thinking"!!

  4. naren - we can 'discuss' provide we know something substantial - which we don't at this moment!

    sub0 - yes. that's how singletons are implemented. private constructors and assignment operator and open up a public static method that returns the single object handle. but the query was not that. is there really a need for all that when there are only static members. the other side of the issue is that not all classes are suited to have only static members. because, the static member initialization happens before main is invoked, this may not suit objects which require a constructor to initialize its members properly.

    goutham - yes, i'm still thinking of other possible pitfalls of having a per-object handle to self. its obviously not a safe construct.

  5. I was musing about why static data+ static functions != singleton that day when we discussed. There are plenty of answers to this:
    1.Firstly, as you point out, there is no single point of initialization for all the members. Initialization could be non-trivial for singletons - example - the value of one of the members depends on some other member.
    2. The actual Singleton patterns was originally expounded in Gamme et al book(GoF). The method of combining static data and static functions is another pattern(pretty close to the concept of Singleton) called 'Monostate' pattern.
    That was a good discussion.
    Avinash Kulkarni.

  6. First I thought Java was going the C++ way... And now looks like C++ is going the Java way :-DD

    For example,
    'Templates and Generics' together! -> Introduced in Java 1.5

    Ability to create objects on system heap or the managed runtime heap! -> JNI and Java

    'Destructors and finalizers' together! -> No need of explanation there ;-))

    You can look at the Java 1.5 spec to see how Java seems to be going the C/C++ way. They have "specific" generics with compile time type checking, console input and output similar to C printf/scanf, and a lot of other things...

    Very interesting indeed :-)

  7. avinash - monostate eh? it seems to have been developed after the GoF design pattern book. I could not find it in the book. Interesting...

    sub0 - ya. i think more than Java becoming like C++ or vice versa, one can say that they both are coming together. Sounds very interesting. Did you look at the video? Do have a look at it.

  8. the most hilarious sentence in the book i'm reading...
    while pointing out the subtle mistake that programmers do in expressing "IS-IMPLEMENTED-IN-TERMS-OF" relationship as public inheritance, he says...

    Being 'a little bit incompatible' is like being 'a little bit pregnant'.


  9. im more interested in knowing about "excuses excuses excuses" wats it all about???

  10. raju - its abt people in call-centres giving excuses in various situations... very hilarious. all are real-life incidents :))

  11. Looks like I am the odd one out.

  12. baejaar - odd man?? why??
    anyway, this is the one technical post that has attracted these many comments. i post such stuff even though i know that they won't attract comments, 'cos i like talking tech stuff. hey, can any of my photos figure on your photoblog dheepak??


What I want to say is: