C++ and Rust At The Same Time | Prime Reacts
Вставка
- Опубліковано 19 жов 2024
- Recorded live on twitch, GET IN
/ theprimeagen
Reviewed article: www.kdab.com/m...
By: Loren Burkholder
MY MAIN YT CHANNEL: Has well edited engineering videos
/ theprimeagen
Discord
/ discord
Have something for me to read or react to?: / theprimeagenreact
Kinesis Advantage 360: bit.ly/Prime-K...
Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
turso.tech/dee...
the editor deserves a raise 🤞
Flip is the best
D can literally import C code too. The feature is literally called importC! Having used D for over a year, it's a great language. You should give it a try for a few days. There will be things you start to like. I guarantee it. If not, well dangit I'm sad. EDIT: And somebody mentioned this in literally the last 30 seconds.
Hey, great you liked Loren's blog. Thanks for commenting on it on your channel!
Prime is so great at reading aloud and internalizing simultaneously.
I honestly think this has a lot of potential. If there are tooling in the future that can create the D file automatically, it might be possible to seamlessly use Rust in a C++ codebase. Maybe if you have a C++ application and there’s a feature that would be easier to manage with Rust.
It could also potentially make it easier to gradually move a project from C++ to Rust one function at a time, without needing to use gRPC or other microservices shenanigans
Why should i move from C++? Why don't you keep on working with Rust and stop suggesting ways of removing a language like C++ that many others like to use?
Completely agree. Keep in mind that most of the people complaining about C++ have no clue about C++, or they don't use anything after C++11@@feynman_QED
I wonder how viable it would be to use D as a build system in this case. Just have a D program generate the bindings then kick off the compilers for all 3 langs then execute the program. Cool thing there is getting D + its package manger/build system Dub + some libraries to use only takes < 10 minutes, starting from having non if it installed. Even better given some of D's other features many D programmers are use to writing code to generate code.
@@feynman_QED Why are you so defensive? I’m not telling anyone to move away from C++, you can code in whatever language you like. However, there are people that would like to take a legacy codebase and migrate over to Rust and the article showed a very promising way to possibly accomplish it.
@@Ellefsen97 First of all, i am not defensive. With one of your level? Come on. Second, you wrote that "It could also potentially make it easier to gradually move a project from C++ to Rust". It's not consistent with what you've just said. This sentence says another story. Why should i move a project from C++ to Rust? Explain that to all of C++ programmers why. They are really interested.
who needs C++ and Rust when you can program in D!
Hi, author of the blog post here! Very exciting to see that my crazy ideas are well received:)
D glue? Nobody wants to touch that
Ain't no way
Why not?
The order of fields in C structs is absolutely guaranteed
Sounds crazy to hint it's not
The creator of sokol wrote an article a while ago about how he uses the AST json dump from clang to auto generate bindings. It would be awesome if a wrapper could be built on top of VCPKG for instance that would autogenerate bindings for a given language.
D does a really good job at glueing stuff together hehe
Prime looks unusually good in this new video 😄
The camera could be an overheating or buffering issue.
Also amazing editor * chefs kiss * perfect cut/edit deserves a raise!
D seems to be good at combining other languages. It can also be used to automatically generate python bindings for C-libraries.
That's sweet and I will have to keep that in mind for my company.
@@TJackson736 details are in an article "calling c from python" in the blog "atila on code"
The lip sync is anazing😮
I hope Prime looks the same for next stream lowkey
It works on audio input. Easy task for streaming or editing software.
I used the GMP C library in Zig recently and it wasn't that bad to figure out and use. I used it to calculate some constant I created to arbitrary precision based on a Michael Penn video. It was an order of magnitude faster than Boost for C++.
D is my preferred system programming language. Read like JavaScript, fun to write like python, and powerful like C++ (template metaprogramming).
The next step would be cutting the "middle D" and implement the Extern(C++) functionality directly into the rust compiler.
Well, that's not something a lot of languages will even attempt to do, and in D, multiple inheritance from C++ classes won't really work, and from what I've heard your only option there is to dupe the D compiler that the class doesn't have multiple inheritance and the compiler won't have a problem during name mangling. However, multiple inheritance is usually not a good thing.
It already exists as a macro crate called "cxx". You put in some declarations about the C++ side & the Rust side and it handles all the mangling for you. AFAIR it also goes both ways between C++ Rust
Makes me wonder, why not just use D?
I had my experience using the Digital Mars C++ compiler many, many years ago and revisited it on occasion. I've always been impressed with the quality of their product, which can only be produced by the developers talent that has always been and is still above my full comprehension.
I remember the excitement and passion they had for D when it came out but was resistant to adopt yet another emerging language at the time. It's clearly matured and is striving toward what other languages specialise in and C++ struggles to keep up with.
Probably because there is a lot of exciting C++ code out there…
D's tools libraries in general suck the big one at least last time I checked (about 1.5 years ago). The VS Code extension for example still is the state where the compiler says one thing and the extension something else.
@@floppa9415 Thanks for the feedback. That doesn't surprise me. The reason I didn't continue using the DM C++ compiler was because of the linker's limited support to OMF, requiring you to convert MS-COFF libraries to VS6 MS-COFF to then use their COFF2OMF tool, or I guess use another linker...it was limitations like that which put me off using it.
Fantastic product with a lot of passion behind it, but impossible to use when you step outside the eco-system.
Reading the GCC page, David Friedman is no longer the developer with the D project having been revived in 2009 by Iain Buclaw and other contributors. I wish them well but it seems D never reached the critical mass it needs to thrive.
Rust will pack struct for optimal performance with minimal padding. c and c++ will add padding bytes until types are aligned, and have deterministic (albeit inefficient) layout.
Its not that it's inefficient its just that the responsibility of creating an efficient layout is on the programmer
@@pxolqopt3597 Yes, indeed, and you end up with structs where field order has nothing to do with code readability, which is "fun" for larger structs. Enjoy!
Optimal performance is why the padding is used. If you pack you lose performance but gain efficiency in size. Rust picks the least performant but safest way every time.
I always make sure to properly align the struct if i need it packed so it's not up to the compiler.
@@anon_y_mousse Yeah of course. I'm thinking small structs going over the wire personally. I'm just countering the ops assumption that packing means performance gain which it does not when accessing the members, the contrary in fact. Every dive i take into rust just proves the wildly inefficient choices they made.
ThePrimeagen might be my favourite PNGtuber
I don’t code and idk what you’re talking about most of the time but I enjoy your channel and humor. Might learn to code as a new hobby
Wow how did you find the channel then?
Oh and please don't start your coding journey with any of the languages mentioned in this video XD Maybe C++ as a flavour of C if you wanna start knowing from the very basics, but if you're not already curious about computer fundamentals, this will be harder than starting with Python/JS.
@@VivekYadav-ds8oz I googled how to code for video games. I went down the rabbit hole and ended up here. A lot of people say don’t learn c++ first but primetime can’t stress enough how important the fundamentals are so I believe I’ve made my choice. Now where to begin lol. I definitely hope to spell cast in vim one day too!
Did the editor manually set keyframes for Prime's mouth, or automated it based on mic audio amplitude?
automated (hopefully)
As the prodigal Dlang son, my ts-rust-zig-deez implementation may be not as organized or thoroughly tested, or turned into a proper compiler not reliant on GC. But I can at least say that I wrote a pretty dang good incremental compilation model for a Monkeyscript REPL through the power of Haskell Maths!
This is a pretty cool idea and proof of concept. It has a lot of potential to become a very powerful and versatile tool. I'd like to see where this kind of project will end up being in say 3-5 years... Hmm, maybe do an update video on this say in 2005 or 2007 to see if there's been any progress with it.
Coincidentally, I've been playing a lot with SystemC and creating my own meta language that can expand upon the zig and nim compile time semantics to allow for managing firmware, RTL, mixed signal simulation, and application code in a single source file(s). Wouldnt it be great to describe a memory mapped peripheral, the actual rtl/hdl, as well as a digital/analog simulation in a single namespace? Thats my dreamworld.
15:25 Since "and" is in German "und", "C++, Rust und D" actually makes even more sense, lol.
Gives me "trying to use every JVM Language in a project vibes".
Throw wren in there and you got yourself a CD-RW
I just wanted to say that Rust *does* indeed allow you to set the mangled name of a function/static via. #[export_name = "..."] attribute 🙂
Watching Prime at that state gave me nightmares.
That's my main gripe with Zig, it's very young and Kelley seems a bit aloof and not very concerned with it. However, this is a negative, Rust started as private project and has grown to be a mature systems programming language. When Zig hits that point i would see it as viable but in its current state, it's a no go.
When rust was as old as zig is now it was also in alpha stage, despite having many people working on it full time with large corporate backing and zig is trying to cover a larger range of programming than simply a programming language and compiler. It's good that it takes it slow before zig is version 1.0 where backward compatiblity breaking changes cant be made. I remember when rust was in alpha and it also made breaking changes every month.
D is such a great language, honestly wish I could just seamlessly use it with Rust to write apps for any platform, no more C++.
I had to do something similar the other day where a C++ library that I could not change exposed a C ABI with function pointers but no user defined context argument, and I needed to call it from a capturing closure. What a nightmare.
All this programming language nonsense is boring. Just code everything in assembly language. Then you only need a cross-assembler to compile for different CPU architectures, which can cross-assemble itself to run on those architectures.
@robinpage2730 A few things about assembly languages and assemblers you might find informative:
- Assembly language is not a single language, but a rather a type of language. There are multiple different, system-specific assembly languages.
- A cross-assembler is a program that runs one type of system, but generates machine code for a target system of a different type.
- Programs which take code written in one assembly language and translate that code into a different assembly language don't really exist, because there are fundamental incompatibilities between systems. To make that work, you'd have to translate the assembly code into some kind of higher-level representation - or in other words, decompile the assembly language into a programming language. There a few exceptions to this: for example, translating linux 32-bit risc-v assembly to linux 64-bit risc-v is generally quite possible, depending on the risc-v extensions supported by the target cpus.
It would be so cool if there was some mega standard that allowed you to connect any language together just flawlessly, it would be very complicated and never happen but its interesting
Dee Snuts (creator of D lang) would be proud of this guy
Can this handle anything using more advanced features than simple non-generic function with only primitive types as parameters and return values?
You'd have to instantiate the templates/macros in all 3 languages. It's doable, but hard as you have to know in advance which instances you need.
Member functions
i like the new prime he looks so calm
Of course, the solution was D all along!
Lol, used to bootstrap F# to my Xbox using C# and XNA, mixing is oldskool
Does adding D to C++ equals C#
This guy really sold us on the massive D glue.
Finally dlang mention
What's not to like about D? Does @ThePrimeTime hate D? For what reason?
Would be interested to know
[c++] feature compatibility is not that much of a meme... CL implement a good 80% of C++ 20, [including importing modules ] and I'm good like 30% of C++ 23
There is no reason any new projects written in C++, on Windows at least, and should not be using C++ 20 features..
You should have a look at Swift’s C and C++ interop, which is done by making the Swift compiler cooperate with Clang. This makes using multiple languages in a project very easy and enables things like inlining functions from one language in another. The following video gives a nice overview:
ua-cam.com/video/ZQc9-seU-5k/v-deo.htmlsi=q9uyDBmzYp9JwVrA
funfact:
Julia can use python, C, Java, and R libraries.
so.... a natural next addition to Polyglot? >:3
Complains about the "crazy toolchain" but works on projects in some javascript framework that adds its own syntay on top of typescript and "compiles" to javascript in order to run on a browsers vm to show some catpictures to your grandma 😂
That's a little CRustD
C++ + Rust + Deezznut?
We need a v lang wrapper for the d code.
i wonder if the jaw moves were coded
I’m new here, why is everyone mentioning lipsync and his editor? I noticed some lag but other than that, am I missing the joke?
good one
Prime talking about his camera 3:47. Foreshadowing 4:20.
Add a bit of pascal in the stack
the real C-RUSTacean
I mix c,c++,and ada all the time.
Did he ever read part 2 or did he adhd past that at the end and forget
Flip'in awesome
This edit 👌👌👌👌👌👌
I was focusing on the lip sync and not on the content of the video.
Damn, why doesn't D become part of Linux kernel...
I like this VTuber arc 4:36
I made rust oob. You just have to use traits in illegal ways. All safe though.
I don't think we need to abuse d for that. Based on this idea, it should be possible to write a "object file aligner" that unifies all differently mangled labels to 1 uniform style. Unifying equal signatures from different languages.
oh we definitely need to abuse d.
The compiler could implement a library to do that unification, aligning everything to whatever the convention is for the language in which the main() function is written: if it's in C++, then that convention is used, but if it's in Rust, then Rust's convention is used.
polyglot shoulda been SEMentD
You know what I did for fun?
I wrote a filesystem.
In JavaScript.
With native AES/XTS encryption support.
And surprisingly enough, about 20Gb/s sequential write speeds.
Why? Because now I can brag and poison the minds of anti-javascript evangelists with my heresy.
damn i just did extern
Missing HTMX there
That made my C++ hard
Oh, so he is canadian.
Add U and you got a modern webapp.
Could you just target WASM with each language?
crust
lua and c interop. C# and JavaScript interop in blazor webassembly PWA.
The longer I program in C++ the more I am convinced it is one of the ugliest languages I've come across and with the most inconsistent syntax. And Rust is among the most beautiful.
Ban all programming languages. Everything should be coded in assembly for minimum compile time, file size, and maximum running program speed and programmer torment.
RIID
Deez
D propaganda
Otagle
That prime key framed mouth is distracting
Why would you want to interop with C++? Rust is just a better C++. That's why they didn't bother with interop with anything except C.
Because C++ is one of the most used languages in the world. Rust is better in many ways, but thinking it will replace C++ is delusional
@@vercolit we will see how that statement ages.
However I agree that there is a lot of code written in c++ today and that code won't vanish overnight. Meaning that there is a need to interact with this code even in case rust replaces c++.
The current status quo that everything interops over c is not ideal as shown in the article.
We have something like 50 years' worth of extant C++ code that's still useful. And if you're a plugin developer for any graphics app (Adobe, Autodesk, Rhino, everything), the SDKs are all C++ and won't ever be rewritten. This interop is DESPERATELY needed.
Rust can't be a "better C++" until it adds inheritance, proper generics (including variadics), function overloading, default parameters, and exceptions, to name only a few.
@@redcrafterlppa303 "
The current status quo that everything interops over c is not ideal as shown in the article."
The status quo is that for a very good reason: the semantic ideas the various different languages add on top of C are generally incompatible. Doesn't Rust, for instance, feel free to move memory around unless you explicitly pin it? Trying to interop between two disparate languages without making sure they talk in the absolute lowest possible denominator is a recipe for disaster.
THIRD
F O U R T H