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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roy Smith

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

    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.
  • Evan

    #2
    Re: % operator -- did Python or C++/boost come first?

    roy@panix.com (Roy Smith) wrote in message news:<bev3p6$h4 l$1@panix2.pani x.com>...[color=blue]
    > 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.[/color]

    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.

    Comment

    Working...