% operator -- did Python or C++/boost come first?

Discussion in 'C++' started by Roy Smith, Jul 14, 2003.

  1. Roy Smith

    Roy Smith Guest

    Up until recently, Python was the only language I'd ever seen that
    used the % operator for string replacement. Today, I was perusing the
    C++ Boost libraries, and discoverd that boost::format uses a very
    similar syntax. The following lines print the same thing in Python
    and C++, respectively.

    print "int->%i, string->%s" % (42, "wugga, wugga")
    cout << boost::format ("int->%i, string->%s\n") % 42 % "wugga, wugga";

    The question is, which came first? Did boost adapt the Python syntax,
    or the other way around, or did they both evolve in parallel? I'm not
    talking about the use of % in the C/printf style format specifier, but
    the use of % as an operator to connect the format specifier with the
    data to be formatted.
    Roy Smith, Jul 14, 2003
    #1
    1. Advertising

  2. Roy Smith

    Evan Guest

    (Roy Smith) wrote in message news:<bev3p6$h4l$>...
    > Up until recently, Python was the only language I'd ever seen that
    > used the % operator for string replacement. Today, I was perusing the
    > C++ Boost libraries, and discoverd that boost::format uses a very
    > similar syntax. The following lines print the same thing in Python
    > and C++, respectively.
    >
    > print "int->%i, string->%s" % (42, "wugga, wugga")
    > cout << boost::format ("int->%i, string->%s\n") % 42 % "wugga, wugga";
    >
    > The question is, which came first? Did boost adapt the Python syntax,
    > or the other way around, or did they both evolve in parallel? I'm not
    > talking about the use of % in the C/printf style format specifier, but
    > the use of % as an operator to connect the format specifier with the
    > data to be formatted.


    If you haven't already, I reccomend reading the design rationale for
    any extensions you're interested in (and that have it of course). The
    one for format is at http://boost.org/libs/format/doc/choices.html.
    Python's use of the same syntax is mentioned, along with many other
    reasons for the choice of the operator (and many more for why << is a
    bad choice). So it would appear that Python came first.
    Evan, Jul 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ska4reak

    where did they come from?

    ska4reak, Nov 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    311
    Bill Priess
    Nov 14, 2003
  2. Emu

    When did ASP.net 2.0 come out?

    Emu, Nov 29, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,807
    Juan T. Llibre
    Nov 29, 2005
  3. Roy Smith
    Replies:
    1
    Views:
    307
  4. 2Barter.net

    Were did that wave come from?

    2Barter.net, Mar 9, 2007, in forum: C++
    Replies:
    0
    Views:
    296
    2Barter.net
    Mar 9, 2007
  5. Tricky
    Replies:
    9
    Views:
    1,403
    Jonathan Bromley
    Aug 31, 2010
Loading...

Share This Page