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

R

Roy Smith

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.
 
E

Evan

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,765
Messages
2,569,568
Members
45,042
Latest member
icassiem

Latest Threads

Top