List:MySQL++« Previous MessageNext Message »
From:Joel Fielder Date:July 13 2007 7:41am
Subject:RE: Connection::connect() interface is changing
View as plain text  
If you want to force compiler errors to avoid silent breakage, and
change the interface to be better, you could introduce a new type:

ConnectionLoginDetails (or some other more appropriate class name).

You could give that a constructor with your new preferred order of
parameters, or maybe even allow something like this:

Connection
connection(ConnectionLoginDetails().Database("whatever").Server("localho
st").Password("noh4xzorssszz"));

Each of those functions returns a reference to the object so you can
daisy chain the params in any order you like.

It's a bit more verbose, but I guess it would allow people to choose
their preferred order, allow you to specify the most common default
order as a constructor, produce compiler errors on upgrade, eliminate
(almost) the possibility of mixing parameters up, and as an added bonus
(wait for it!): in my projects I tend to have a struct or a class that
holds this info anyway (and I bet most other people do too):  

Connection connection(details.Database(), details.Server(),
details.User(), details.Password());

May as well pass them as one param.

Joel

Thread
Connection::connect() interface is changingWarren Young13 Jul
  • Re: Connection::connect() interface is changingDrew M.13 Jul
    • Re: Connection::connect() interface is changingWarren Young13 Jul
  • RE: Connection::connect() interface is changingYuantu.Huang13 Jul
    • Re: Connection::connect() interface is changingWarren Young13 Jul
      • RE: Connection::connect() interface is changingJoel Fielder13 Jul
        • RE: Connection::connect() interface is changingWilliam F. Dowling13 Jul
        • Re: Connection::connect() interface is changingWarren Young14 Jul
          • Re: Connection::connect() interface is changingWarren Young14 Jul
            • Re: Connection::connect() interface is changingAlex Burton15 Jul
              • Re: Connection::connect() interface is changingPeter Garner15 Jul
              • Re: Connection::connect() interface is changingWarren Young16 Jul
          • RE: Connection::connect() interface is changingJoel Fielder16 Jul
            • Re: Connection::connect() interface is changingWarren Young16 Jul
              • Re: Connection::connect() interface is changingAxel Howind16 Jul
                • Re: Connection::connect() interface is changingWarren Young16 Jul
  • Re: Connection::connect() interface is changingAxel Howind13 Jul
    • Re: Connection::connect() interface is changingWarren Young14 Jul
      • Re: Connection::connect() interface is changingAxel Howind16 Jul
  • Re: Connection::connect() interface is changingAlex Burton13 Jul
    • Re: Connection::connect() interface is changingWarren Young14 Jul
  • RE: Connection::connect() interface is changingJim Wallace13 Jul
    • Re: Connection::connect() interface is changingWarren Young14 Jul