Boost logo

Boost :

Subject: Re: [boost] Boost namespace abreviations
From: raindog_at_[hidden]
Date: 2008-11-28 21:47:18


I prefer the method used in the filesystem examples:

Namespace fs = boost::filesystem;

Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: edam <edam_at_[hidden]>

Date: Thu, 27 Nov 2008 18:51:03
To: <boost_at_[hidden]>
Subject: [boost] Boost namespace abreviations


Hi there,

I just wanted to hear the boost community's thoughts on abbreviating
boost's namespaces. According to Boost's library naming conventions
(http://www.boost.org/development/requirements.html#Naming_consistency)
this is strongly discouraged, and with good reason -- having clearly
(and consistently) named namespaces is a good thing! Having used boost
for a (mere) couple of years now, though, I've started to find its
namespaces a bit unwieldy.

I try to avoid going "using namespace" (for a few reasons, nicely
summarised here: http://dev.lsstcorp.org/trac/wiki/DiscussCodeStandards)
and I can't bring myself to go down the route of announcing to the
compiler that I will be "using ..." specific symbols from whichever
namespace either. So I am left with having to explicitly specify the
namespace of each symbol, like this:
  std::cout << std::setw( 2 ) << std::setfill( '0' ) << hours;
While this requires more typing, I prefer it to the alternatives.

As a boost user though, I find this becomes a bit more of a pain.
Boost's namespaces, whilst well named, are a lot to keep typing out!
Here's a quick example:
  boost::posix_time::time_duration foo = boost::posix_time::hours(2);
Multiply this by a thousand lines of boost-using code and you've got a
lot of typing!

I wondered if there would be any interest in a boost abbreviations
header that, if included, would provide abbreviated names for boost's
namespaces. Something along the lines of a boost/abrv.hpp:

  // this is an incomplete example
  namespace bst = boost;
  namespace boost {
      namespace gd = gregorian;
      namespace pt = posix_time;
      namespace dt = date_time;
  }

This would allow the developer to shorten the above example code to
  bst::pt::time_duration foo = bst::pt::hours(2);
in this case saving a full 18 characters! Multiply this by 1000 lines of
code and you may save some finger-ache.

What I'm proposing sounds terrible, I know, but if you consider that
users would "opt-in" to this by including the abbreviations header
(meaning it wouldn't affect existing users), I wondered if there would
be any merit in it? I'm expecting a lot disapproval to this idea, but I
thought I'd ask what people think anyway. Please don't shoot me down too
much -- this is my first post to the boost mailing list! :o)

Regards,

Tim.

--
  edam - www.waxworlds.org/edam
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk