News for hackers. Stuff that matters.
Re:Integrating Zig and SwiftUI by bestinterest on Saturday May 27, 2023 @08:34PM (#36099938)
Noob question,

What makes languages like Zig, Rust, C and C++ the best fit for cross platform applications over many garbage collected languages? Why is bringing the language runtime a problem?

What does it mean to compile to a C-compatible library?

Re:Integrating Zig and SwiftUI by dhab on Saturday May 27, 2023 @09:03PM (#36100088)
Curious to know from experts in the above to see if ChatGPTs response is valid? Me as someone who knows nothing about either, looking at a nuanced response from ChatGPT, puts me at awe - esp. response to the question: "Say I called a bunch of goroutines when I was in the Add function of the example you gave, would this be a problem?"
Re:Integrating Zig and SwiftUI by throwawaymaths on Saturday May 27, 2023 @09:11PM (#36100140)
I'm fairly good with zig and know a thing or two about go. It's pretty accurate.
Re:Integrating Zig and SwiftUI by alecthomas on Saturday May 27, 2023 @09:46PM (#36100345)
As I responded in a sibling comment, this is the point where ChatGPT goes completely off the rails and starts fabricating responses. Temper your awe :)
Re:Integrating Zig and SwiftUI by alecthomas on Saturday May 27, 2023 @09:22PM (#36100187)
ChatGPT's responses start accurate then quickly go off the rails. The section from this point onwards is completely incorrect:

> Say I called a bunch of goroutines when I was in the Add function of the example you gave, would this be a problem?

The Go runtime is initialised once only in c-shared mode for the lifetime of the application - it would make no sense to do it on every function invocation, and be incredibly slow. So the answer to this section and the next one are just largely bogus.

ie. this response

> However, once you call a function via a C or Swift bridge, it becomes a synchronous operation and will block the calling thread until all goroutines have completed execution. Therefore, you would need to effectively manage the synchronization of these goroutines to avoid unnecessary blocking of the calling thread.

And the response to this question:

> You said in 4 the Go runtime may not keep running, does this mean that every invocation of the Add function has to spin up the whole Go runtime every time? Why cant it just stay alive inside the Swift process?

Are completely incorrect.

Re:Integrating Zig and SwiftUI by Thaxll on Saturday May 27, 2023 @09:51PM (#36100369)
It's about the libraries usually, ui lib are all made in c/c++ and those "natives" langage have better integration with it ( ffi ).

For example calling C from Go is doable, but it's not encouraged and sometime a bit slow.

On the other hand Go and Java are trully multi platform and it's well supported and usually easier to do than other native langages.

Re:Integrating Zig and SwiftUI by aidenn0 on Saturday May 27, 2023 @11:24PM (#36100878)
Pretty much every modern language (Zig, Rust, C, and C++ included) depends on a runtime. The C runtime is privileged because it is already present on all 3 desktop OSes.

It is also a lot smaller than most other runtimes, which makes bundling the C runtime with the program more palatable.

A "C-compatible library" is a library (i.e. a collection of functions) that is callable in the same way that functions written in C are called. Nearly all non-C languages provide a way to call C functions (because, again on all modern desktop OSes, the operating-system interface is written in C).

If everyone wrote OS interfaces in perl, then you would want to compile to a perl-compatible library. If the Lisp machines had won, then you would be compiling to a Common Lisp compatible library.

Re:Integrating Zig and SwiftUI by justincormack on Sunday May 28, 2023 @05:24AM (#36102456)
That is somewhat conflating the calling convention and the runtime - C really doesn't have much that you can call a runtime outside the calling convention, although some libraries (eg pthreads say) have a little runtime which matters in practise for integrations, but these are libraries not parts of the language itself.
Re:Integrating Zig and SwiftUI by aidenn0 on Sunday May 28, 2023 @10:16AM (#36104177)
malloc and free are part of what I would consider a runtime. As are the file objects opened for standard I/O.

It's a very small runtime, but all the code before main is properly runtime initiation

Re:Integrating Zig and SwiftUI by kazinator on Monday May 29, 2023 @02:25AM (#36111268)
> The C runtime is privileged because it is already present on all 3 desktop OSes.

Yes, Ubuntu, Debian and Fedora.

On Windows, you don't get a C run time; you ship a MS Visual Studio run-time DLL if you're using Microsoft's tools (and not static linking), or something else with someone else's tools; maybe a CYGWIN1.DLL or whatever.

You get platform libraries like kernel32.dll and user32.dll; but those are not a C run-time. They are easy to call from C, but other than that, they are the OS run time.

Recently Microsoft has made an effort to create a "Universal C Run Time" for Windows; but I think you still have to download and ship that, and there may be reasons for someone to choose a different run-time. (E.g. needing a pretty detailed POSIX implementation.)

Re:Integrating Zig and SwiftUI by aidenn0 on Monday May 29, 2023 @03:04PM (#36116867)
I thought msvcrt shipped with windows as early as XP; was I wrong?
Re:Integrating Zig and SwiftUI by kazinator on Monday May 29, 2023 @05:02PM (#36118080)
Even earlier; but that's a private system library you're not supposed to use.

Raymond Chen explains it: https://devblogs.microsoft.com/oldnewthing/20140411-00/?p=12...

Microsoft's new Universal C Run Time addresses the problem of there not being a C library on Windows that is for public use (every compiler vendor providing their own).