<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx</link><description>Joel's law of leaky abstractions rears its ugly head once more. I try to never use smart pointers because... I'm not smart enough.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#10198902</link><pubDate>Tue, 23 Aug 2011 08:46:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10198902</guid><dc:creator>sbi</dc:creator><description>&lt;p&gt;What does &amp;quot;smart&amp;quot; stand for in a &amp;quot;smart pointer&amp;quot; when you have to call a Disown() function for it to get ownership semantics right? A good smart pointer would do ownership transfer at assignment itself, when the possibly failing operations are sorted out. &lt;/p&gt;
&lt;p&gt;Yes, you will have to think about the stuff at the low level (this is C++, after all), but only when you are _implementing_ a smart pointer. If you need to think about it when you are _using_ it, it#s the wrong one. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10198902" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#7981824</link><pubDate>Sun, 02 Mar 2008 00:09:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7981824</guid><dc:creator>Milan Sekler</dc:creator><description>&lt;p&gt;I can not beleive I found somebody that thinks like I do about the smart pointers. I agree with the author 100% and I spend 10 hours a day looking at C++ code. How do I convince myself to use this &amp;amp;%^@#:&lt;/p&gt;
&lt;p&gt;template&lt;/p&gt;
&lt;p&gt;&amp;lt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; typename T,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; template &amp;lt;class&amp;gt; class OwnershipPolicy = RefCounted,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; class ConversionPolicy = DisallowConversion,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; template &amp;lt;class&amp;gt; class CheckingPolicy = AssertCheck,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; template &amp;lt;class&amp;gt; class StoragePolicy = DefaultSPStorage&lt;/p&gt;
&lt;p&gt;&amp;gt;&lt;/p&gt;
&lt;p&gt;class SmartPtr;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7981824" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#194531</link><pubDate>Sat, 24 Jul 2004 11:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:194531</guid><dc:creator>indranil banerjee</dc:creator><description>I agree with Brian that neither example illustrates a problem with smart pointers. &lt;br&gt;&lt;br&gt;The first is just an example of the unpredictable order of evaluation in C++ program.&lt;br&gt;&lt;br&gt;This code has exactly the same problem, and no smart pointers:-&lt;br&gt;&lt;br&gt;map[new Foo('A')] = new Bar(&amp;quot;Aarcvark&amp;quot;);&lt;br&gt;&lt;br&gt;&lt;br&gt;The second is just the horrendous complexity of ATL. But then again anything to do with COM is horrendously complex.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=194531" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#172186</link><pubDate>Sat, 03 Jul 2004 00:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:172186</guid><dc:creator>josep</dc:creator><description>That's because you have bad smart pointers! Don't blame a concept because of a lame implementation!&lt;br&gt;&lt;br&gt;Look at boost smart pointers and you'll find referenced count smart pointers which can be inserted in any STL container (shared_ptr). &lt;br&gt;&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=172186" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#148745</link><pubDate>Fri, 04 Jun 2004 19:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:148745</guid><dc:creator>Eric Lippert</dc:creator><description>No, I'm saying that smart pointers suck because to use them properly, you have to understand _exactly_ what they are doing.  &lt;br&gt;&lt;br&gt;An abstraction is supposed to relieve you of the burden of understanding the abstracted thing, but smart pointers do a poor job of that.  In order to use them correctly, you have to understand exactly what they're doing to ensure that you don't use smart pointers to violate the very rules they are designed to abstract away.&lt;br&gt;&lt;br&gt;That's a lousy abstraction.  It is easier for me to learn the rules of COM and apply them than to learn the rules of COM AND learn the entire smart pointer framework.&lt;br&gt;&lt;br&gt;The .NET framework does a much better job of abstracting away the details of how the underlying system works, because it was designed to do that from day one.  Smart pointers are a kludge written post hoc.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=148745" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#148681</link><pubDate>Fri, 04 Jun 2004 18:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:148681</guid><dc:creator>The Sim</dc:creator><description>Never mind, I reread the post, that seems to be exactly what you said. C# 4ever, whoop!&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=148681" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#148678</link><pubDate>Fri, 04 Jun 2004 18:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:148678</guid><dc:creator>The Sim</dc:creator><description>so basically you are saying smart pointers suck, because you don't know how to use them properly?&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=148678" width="1" height="1"&gt;</description></item><item><title>Aaargh!  Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#125890</link><pubDate>Tue, 04 May 2004 21:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:125890</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=125890" width="1" height="1"&gt;</description></item><item><title>Aaargh!  Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#94653</link><pubDate>Tue, 23 Mar 2004 20:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94653</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=94653" width="1" height="1"&gt;</description></item><item><title>re: Smart Pointers Are Too Smart</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/53016.aspx#94826</link><pubDate>Tue, 23 Mar 2004 20:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94826</guid><dc:creator>Eric Lippert</dc:creator><description>&amp;gt; using them is almost always a better idea than trying to manage the refcounts &amp;quot;by hand&amp;quot;. I've used them for years and they've been the least of my concerns.&lt;br&gt;&lt;br&gt;I disagree.  I've debugged ref count bugs caused by me forgetting an AddRef, and I've debugged ref count bugs like the one above with the fifteen-deep call stack of meaningless (to me) gibberish, and the former are a whole lot easier to track down.&lt;br&gt;&lt;br&gt;I agree that COM code looks gross, and that it tends to emphasize the error paths and cleanup code rather than the program logic.  Two points:  First, given that the error paths and cleanup code are where most of the bugs are, I want them to be as explicit as possible.  Those ARE the program logic.  &lt;br&gt;&lt;br&gt;Second, I understand the urge to abstract them away into classes that take care of the details for you.  But in my experience, the abstraction is both complex and leaky.  The abstraction is easy to use for simple cases, and thereby affords creation of much more subtle, hard-to-debug bugs.&lt;br&gt;&lt;br&gt;My point, simply, is that AddRef/Release/QI are a pain in the rear to USE, but they are EASY to understand.  Smart pointers are easy to use and hard to understand, and I prefer to understand the code I write.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=94826" width="1" height="1"&gt;</description></item></channel></rss>