Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   % operator -- did Python or C++/boost come first? (http://www.velocityreviews.com/forums/t319668-operator-did-python-or-c-boost-come-first.html)

Roy Smith 07-14-2003 08:28 PM

% 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 07-15-2003 04:46 AM

Re: % operator -- did Python or C++/boost come first?
 
roy@panix.com (Roy Smith) wrote in message news:<bev3p6$h4l$1@panix2.panix.com>...
> 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.


All times are GMT. The time now is 12:12 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.