[bind10-dev] suggested team call agenda

Michal 'vorner' Vaner michal.vaner at nic.cz
Wed Dec 12 09:10:32 UTC 2012


Hello

On Tue, Dec 11, 2012 at 02:12:06PM -0800, JINMEI Tatuya / 神明達哉 wrote:
> Yeah, in this discussion, we should at least distinguish the direct
> use of pointer value as boolean like
> 
>   Foo* foo;
>   if (foo) {
>      ...
>   }
> 
> and the use of smart pointer objects in a boolean context via
> (an implicit call to) boolean type conversion operator
> 
>   shared_ptr<Foo> foo;
>   if (foo) { // this is actually "if (foo.convert_to_bool())"
>      ...
>   }
> 
> I tried to explain the difference in
> http://bind10.isc.org/ticket/2377#comment:19 but there still seems to
> be some confusion.

No, it's not confusion. I do understand the difference, but I don't find it
important on any level.

Shared pointer has „operator bool“ (not really, there's some other type because
of some tricky low-level mess in C++, but that's not important*) method that
describes how it should look like in a boolean context, the behaviour is well
defined and known and the compiler will generate some code depending on that.

The bare pointer has its behaviour in boolean context described in the standard.
It is well defined and known and the compiler will generate some code depending
on that.

The only difference is, while shared pointer has its auto-conversion to bool
described in code, bare pointer's auto-conversion is hardcoded in the compiler.

Is that really that important where the behavior comes from to distinguish it on
much higher level of coding style? The code serves two purposes ‒ to tell the
compiler what to do (which it does in both cases in full or short form) and to
explain the idea to other programmer that'll read the code (on this level,
there's not much difference on if it is a shared pointer or bare pointer).

> Note that here I'm not talking about whether or not the first is a
> bad/acceptable style.  I'm simply pointing out that it doesn't
> (necessarily) make sense to discuss the former style based on whether
> the latter style is acceptable.

What I'm trying to tell, if the first is not acceptable (for a reason I still
don't fully grasp and nobody really told me yet what bad could happen if we used
it ‒ because people seem to suggest some terrible unknown things would happen,
not that it would be just matter of personal preference), the second is not any
better and they should be consistent in the code.


*: If we were to be strict, that one would make it even worse. In case of bare
pointer, there's the auto-conversion to bool, or understanding the pointer in a
boolean context. In the case of shared pointer there's the operator method and
auto-conversion of something unknown (possibly a pointer to function) to bool.

With regards

-- 
No one is to look like a sock, understand?
			-- Archchancellor Ridcully

Michal 'vorner' Vaner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://lists.isc.org/pipermail/bind10-dev/attachments/20121212/97dadfe9/attachment-0001.bin>


More information about the bind10-dev mailing list