"Why contrive a name for something that will never be called anywhere else? Why contrive a name for a block of code that only makes sense in one place in the source?"
This is one of the compelling arguments for favoring C++11 over C++98(03): In older flavors of C++ the standard algorithms often required that a functor class be passed in, for example, as a comparator. Believe it or not (I'm sure you already know this, though), people had to go to all the trouble of creating a named class with an overloaded operator(), and then pass that named class to a standard algorithm just to do simple things like calling a sort routine, or a binary search routine on non-POD types. And even then it might be necessary to overload operator< as well. C++11 finally provided lambda functions, which allowed users to stop going through all the silly work just to create a comparator that would be used in only one place. In other words, in this regard, C++11 finally gained the ability to make something that should be simple, relatively easy as well, and this is one of the things that has made C++ fun, finally. Perl has had anonymous functions for...well, I don't know how long, but at least dating back to when sort and map made it into the language.
So what I don't get is, after all these years, and after so much work has gone into making older languages like C++ adopt the approach, why people still say, "now why would you want that?"
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|