Thanks from a python programmer

mipri mipri at minimaltype.com
Fri Mar 5 16:15:12 UTC 2021


On Friday, 5 March 2021 at 12:21:19 UTC, bachmeier wrote:
> On Friday, 5 March 2021 at 06:11:33 UTC, mipri wrote:
>
>> This sets a C #define and then includes everything from stdio.h
>> as a struct with #defines as variables, C functions as Zig
>> functions, C #define *macros* also as Zig functions, etc. This
>> time the magic is not from C codegen and deferring the work to
>> a C compiler, but from Zig's compiler properly digesting C's
>> header files.
>
> *shrug* I work with C libraries all the time, and while dstep 
> and dpp might not handle everything, the parts they don't are 
> minor.
>
>> What D has is very fine, but it's general seating. Any language
>> with an FFI at all should be about as capable as D's FFI.
>
> As far as calling C functions? Of course, but those languages 
> are also as capable as Zig if all you want to do is call 
> functions.
>
> If you're talking about C interoperability more generally, you 
> have a strange definition of capable. You can create a D shared 
> library that can be called as if it's a shared C library. You 
> can go further and restrict yourself to betterC mode and then 
> you're basically writing modernized C code that without further 
> modification can be dumped in the middle of an existing C 
> project. I don't think, say, Ruby can do that even though it 
> has an FFI.

You can absolutely do that with Ruby. You write a library that
loads Ruby as a library, then have it run your Ruby code, then
export C ABI functions that call into Ruby. It involves writing
(or generating) a bunch of C, which is the same on-the-wing
experience I referenced above with getting Python to call C
libraries. Start with
https://stackoverflow.com/questions/2801346/embedding-ruby-calling-a-function-from-c

You can do it. The existence of someone who can say "*shrug* I
work with C libraries all the time, and while rstep and rpp
might not handle everything, the parts they don't are minor."
is therefore not impossible. Would that mean that Ruby's a
first-class language for writing shared objects? If someone
claimed "Ruby has first-class C integration" would you not be
able to imagine any more-luxurious seats that a language might
have a ticket for?

> Then there's the big issue of passing data back and forth. 
> That's a language design issue and D makes it easy.

Why, what big issue? You *can* pass data back and forth. You
*can* even only write in a dialect of Ruby that would have a
great deal of sympathy with C and not require as much data
conversion, cheaply converting between char*s and
UncheckedByteArrays like the 'Native' JVM dialects.

You can do it, so it's first class, so it can hardly be
improved, and I certainly can't think of any languages that do
it better.


It's really tiresome to make a point this simple and then still
have to explain it. Of course I have a "strange definition of
capable" for you when I'm describing features you don't miss
because you're satisfied with less features. Airlines generally
make passengers walk past first-class to get to their cheaper
seating, so you at least don't hear conversations like

   A: I wish general seating had more comfortable seats.

   B (defensively): what do you mean? I fly all the time and the
     seat padding is as good as it gets. They'll even bring
     little packets of peanuts to you mid-flight! You can't get
     *that* kind of service elsewhere.



More information about the Digitalmars-d mailing list