[OT] fortran lib which provide python like data type

Marko Rauhamaa marko at pacujo.net
Sun Feb 1 02:58:32 EST 2015


Paul Rubin <no.email at nospam.invalid>:

> Marko Rauhamaa <marko at pacujo.net> writes:
>> Stroustrup apparently has never had to deal with callbacks; his thick
>> books never made a mention of them last time I checked.
>
> C++ has function pointers just like C,

Et tu, Brute!

C's callbacks always use a void pointer for the "self reference." In C,
I can use void pointers and type casts idiomatically. In C++, type casts
are apostasy.

Qt gave up on C++ when it comes to callbacks ("signals") and went for an
apocryphal metacompiler.

> but more idiomatically you'd pass a class instance and the library
> would invoke some method on it.

Yes, that's what I ended up doing, defining a class for each callback
type:

   struct ButtonPushListener {
       virtual void buttonPush(int x, int y) = 0;
   };

(Yes, "struct" and not "class"! Why?)

Typing all of that in was quite a chore. All because Stroustrup didn't
think of delegates (Delphi, C#, Python). C++'s method pointers are
ridiculous and useless, they should have been defined as delegates.

> There is also Boost::Coroutine which can get rid of the need for
> callbacks in some situations.

Boost is the world's biggest fig leaf.


Marko



More information about the Python-list mailing list