[Ns-developers] Ipv4Address and Ipv4Mask, getting rid of "implicit" constructors

Mathieu Lacage mathieu.lacage at sophia.inria.fr
Wed May 14 08:05:48 PDT 2008


On Tue, 2008-05-13 at 20:01 -0700, craigdo at ee.washington.edu wrote:
> > > I would like to make all these constructors "explicit", 
> > thus you have to
> > > type Ipv4Address ("1.2.3.4") instead of "1.2.3.4".
> > > 
> > > Comments?
> > 
> > +1: avoids many implicit conversion traps.
> 
> It's a lot of "extra" typing for manual address assignment, but now that we
> have automagic IP address generation in place I don't see it as being a huge
> nuisance.  
> 
> Of course, the tutorial uses this as an example of how type implicit type
> conversion works, so it's my turn to have the same reaction as Gustavo about
> API changes.  Every time we make a change like this it obsoletes large
> sections of documentation.  I suppose we could change the implicit type
> section to talk about node helpers, but it's more work.

It is hard to argue against that. This is a real problem.

> What kind of traps are you trying to avoid?  Can you give me an illustration
> of what would be a plausible scenario that would be avoided?

I don't have any specific example in mind (other than the obvious one
where you have multiple overloaded methods, one which takes an
Ipv4Address and another which takes a const char *) but I have been
bitten by way too many very subtle implicit conversion problems over the
past 5 months so, I am becoming paranoid about them: the extra typing
does not bother me much given the pain I have had to go through to deal
with a couple of unexpected type conversions when they are triggered by
the compiler. 

So, I approve of gustavo's proposal as a matter of generic policy: all
our constructors which take a single primitive type as argument should
be made explicit except those for which we really want to provide the
implicit conversions (the only I can think of are those which take an
Address and even there, we could make that explicit).

regards,
Mathieu



More information about the Ns-developers mailing list