[OT] fortran lib which provide python like data type

Michael Torrie torriem at gmail.com
Mon Feb 2 11:25:32 EST 2015


On 02/02/2015 12:39 AM, Marko Rauhamaa wrote:
> Michael Torrie <torriem at gmail.com>:
> 
>> http://en.cppreference.com/w/cpp/utility/functional/function
>>
>> Thus if we were to shoehorn your example into C++, the result would be
>> idiomatically very similar to what you have in your Python code.
> 
> I can understand why you wouldn't write out my example in C++:

I wouldn't write it out because it's a contrived example, and why should
I waste my time? You have no intention of being impressed with C++, let
alone simply learn about it.

> 
>    using std::placeholders::_1;
> 
>    std::function<void(int)> f_add_display2 =
>         std::bind( &Foo::print_add, foo, _1 );

Looks okay to me.  That's normal C++ that would be clear to any C++
programmer.  And for a statically compiled language, that's incredibly
powerful while providing for a measure of safety.  You may shudder, but
it's a really good statically compiled solution, given the constraints
of C++ and its compiler.

But like I said, idiomatically in C++, this isn't normally what you'd do
anyway.  You'd store a std::ostream object.

> vs
> 
>    f_add_display2 = foo.print_add
> 
> The cherry on top: "_1"! The C++ compiler figures out template types
> heroically but can't wrap its head around the arity of the method.

std::bind is a generic function that works with undecorated function
pointers.  There's no possible way for the compiler to know the arity of
the function without you telling it (how else would you do it? I
honestly want to know.).  That you would find this fact to be
incredulous suggests that you have very little understanding of
compilers in general.  Python being a dynamic, interpreted language can
examine a function at runtime.

Python is a very expressive language compared to C++ that can do things
at runtime that C++ cannot.  It's also an interpreted, dynamically-typed
language, whereas C++ is a statically-typed language that is clearly
faster at many things than Python is.  It's a matter of different tools
for different jobs.  For most of my jobs Python is the right tool.  But
I can see why people would still want to pick a compiled language, and I
can understand why some people still use C++.  It's a very powerful
language.

I'm a little unclear as to why you're even bringing up the comparison
with C++.  What's your point?  To feel superior?





More information about the Python-list mailing list