Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > % operator -- did Python or C++/boost come first?

Reply
Thread Tools

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

 
 
Roy Smith
Guest
Posts: n/a
 
      07-14-2003
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.
 
Reply With Quote
 
 
 
 
Evan
Guest
Posts: n/a
 
      07-15-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Roy Smith) wrote in message news:<bev3p6$h4l$(E-Mail Removed)>...
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When did ASP.net 2.0 come out? Emu ASP .Net 3 11-29-2005 03:42 PM
Where did this screen come from ??? BC Computer Support 11 12-31-2004 10:06 PM
Come One, Come All Jess Guim Digital Photography 0 12-02-2003 04:43 PM
where did they come from? ska4reak ASP .Net 1 11-14-2003 04:47 PM
% operator -- did Python or C++/boost come first? Roy Smith Python 1 07-15-2003 04:46 AM



Advertisments