It's often said that learning a new language will help you look at things
differently and thus also improve how your program in other languages you
know. I occasionally program in C++ and I'm in one of those occasions
now so I'm thinking about how knowing Ruby has influenced my C++
programming.
One thing that comes to mind is that I'm more likely now to pass around
function pointers as a way to emulate yield. The function passed in can
be evaluated at every step of an iteration, for example, to test for some
condition.
Anyone got other examples of how your C++ programming has been influenced
by your Ruby knowledge?
This is a common C++ idiom, actually, but usually it involves a function
object rather than a function pointer, since calls into the function
object can often be more easily inlined.
Paul
···
On Tue, Oct 25, 2005 at 02:42:01AM +0900, Phil Tomson wrote:
One thing that comes to mind is that I'm more likely now to pass around
function pointers as a way to emulate yield. The function passed in can
be evaluated at every step of an iteration, for example, to test for some
condition.
Thou shalt study thy libraries and strive not to reinvent them without cause,
that thy code may be short and readable and thy days pleasant and productive.
-- Seventh commandment for C programmers
templates and generic programming: they are as close to duck typing as you
can get - implement the required signature and you're off. the vigra toolkit
i've been using is a great example of this. i've also realized the
__massive__ speed hit you incur if you write c++ without templates that i'd
say c++ is not of enough value to bother without them.
the biggest improvement, of course, is that i don't need to write much c++
anymore.
-a
···
On Tue, 25 Oct 2005, Phil Tomson wrote:
It's often said that learning a new language will help you look at things
differently and thus also improve how your program in other languages you
know. I occasionally program in C++ and I'm in one of those occasions now
so I'm thinking about how knowing Ruby has influenced my C++ programming.
One thing that comes to mind is that I'm more likely now to pass around
function pointers as a way to emulate yield. The function passed in can be
evaluated at every step of an iteration, for example, to test for some
condition.
Anyone got other examples of how your C++ programming has been influenced by
your Ruby knowledge?
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama
...
templates and generic programming: they are as close to duck typing as you
can get - implement the required signature and you're off. the vigra toolkit
I first parsed this as 'Viagra toolkit', and thought, won't that just make things harder?
On Tue, Oct 25, 2005 at 02:42:01AM +0900, Phil Tomson wrote:
One thing that comes to mind is that I'm more likely now to pass around
function pointers as a way to emulate yield. The function passed in can
be evaluated at every step of an iteration, for example, to test for some
condition.
This is a common C++ idiom, actually, but usually it involves a function
object rather than a function pointer, since calls into the function
object can often be more easily inlined.
Yes, this is probably true, but it took a trip through Ruby-land for me to
'get it' in C++ (and yes, I should probably be using functors).
...
templates and generic programming: they are as close to duck typing as you
can get - implement the required signature and you're off. the vigra toolkit
I first parsed this as 'Viagra toolkit', and thought, won't that just make things harder?
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama