Тёмный

Named Field Init in C, C++20, Zig, Rust, & D 

Context Free
Подписаться 23 тыс.
Просмотров 23 тыс.
50% 1

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 67   
@ashrasmun1
@ashrasmun1 4 года назад
auto main() -> int I can already feel the C programmers shivering with disgust :D
@DBGabriele
@DBGabriele 4 года назад
This is only because C ++ gives the ability to write type expressions.
@Mateus.007
@Mateus.007 4 года назад
My C intellisense puts the prototypes in this way, without the word auto, though.
@AndrewKelley
@AndrewKelley 4 года назад
I love these videos! I'm a happy subscriber. 7:35 It's fair to say that Zig's defer feature is similar to Go's defer feature, but if you make that comparison, it might be also worth pointing out an important difference: Go's defer appends the defer expression to a heap-allocated function-local list, and executes them upon function exit. Zig's defer (same as D's scope(exit)) applies to the current scope only. The difference is important when, for example, using a defer statement inside a loop.
@contextfree
@contextfree 4 года назад
Glad to hear it! And I do hope to interview you on Zig sometime this year probably, if you're agreeable. Just waiting until I feel like it's the right time.
@contextfree
@contextfree 4 года назад
And thanks for the clarification on defer!
@AndrewKelley
@AndrewKelley 4 года назад
@@contextfree I'd be happy to; send an email whenever you want :)
@StevenAkinyemi
@StevenAkinyemi 4 года назад
So nice to find Andrew here also liking these videos. Looking froward to the Zig interview.
@atimholt
@atimholt 4 года назад
It might be noted that, where C lets you change argument order here, C++ lets you know the order of execution-It gives you a different mental handle in exchange. …but code that relies on the order of execution of “semantically parallel” expressions is almost always very bad and ugly-to be avoided as a goal in itself. Still, I think it's nice to be able to have a mental picture of the stack at more points. It keeps my mind near the metal.
@lord12790
@lord12790 4 года назад
Great video, it always interesting to see working of different languages. Love to watch your videos.
@rabingaire
@rabingaire 4 года назад
These are great content loved these videos keep em coming
@rudolflovrencic
@rudolflovrencic 4 года назад
Good stuff. Subscribed!
@xseman
@xseman 3 года назад
I love your content!
@eLBehmo
@eLBehmo 4 года назад
clang has this feature since many versions. You can already use it - it's awesome! Also: clang only warns about the declaration order. Also: it's called aggregate initialization - and you can't use it if you declared a constructor.
@kcvinu
@kcvinu 4 года назад
Thanks for the video. Among those languages, D looks more clear to me. Pretty neat code.
@Nyocurio
@Nyocurio 4 года назад
Good content my dude.
@juliankandlhofer7553
@juliankandlhofer7553 4 года назад
TIL that C has named fields in struct literals. Thanks! Another reason to hate my Software engineering teacher...
@eLBehmo
@eLBehmo 4 года назад
also most c++ compiler since some years - only the standard doesn't enforced it
@nxxxxzn
@nxxxxzn 4 года назад
you will not learn proper programming in school. only people that actually get to program real world stuff with other people, or read real world program code, do learn it.
@juliankandlhofer7553
@juliankandlhofer7553 4 года назад
@@nxxxxzn yeah unfortunately that's true. I'm pretty sure I write better code than 95% of the Teachers at my school.
@marinhaalternativa3829
@marinhaalternativa3829 4 года назад
Schools teach the basics, the student use that to dive in intermediate. Like, most people should know that when doing Software Engineering.
@juliankandlhofer7553
@juliankandlhofer7553 4 года назад
@@marinhaalternativa3829 Noone would dare to say that when it comes to Civil or Mechanical Engineering.
4 года назад
I see D, I subscribe
@godnyx117
@godnyx117 4 года назад
LMAO! He doesn't do D anymore. That's why I didn't sub :(
@shailist
@shailist 4 года назад
it doesn't really matter whether you let the coder write the initializers in order or out of order. what really matters is the order of construction and destruction. having the order of destruction being the reverse of the order of construction allows default values for member variables to depend on other member variables with default values that were declared before them
@keonix506
@keonix506 4 года назад
Was really disappointed with Rust drop order. It's really counterintuitive and doesn't have any advantages. Rust have editions for introducing breaking changes, why they haven't used that? And now we stuck with this decision forever. What a waste of possibilty to do right thing from start
@LesleyLai
@LesleyLai 4 года назад
That kind of thing happens in every language. People probably rant way more on some early C++ design decisions, for example.
@contextfree
@contextfree 4 года назад
In the page I showed (from 2017), they discussed possibilities for allowing opt in to the other order. Maybe editions could be an option, too. I haven't studied any recent conversations, though, so I'm not sure of the current state.
@Karrq
@Karrq 4 года назад
I've been using rust professionally for a year now and I haven't had any issues with the destruction order. Can you provide an example where this would be a disadvantage?
@keonix506
@keonix506 4 года назад
@@Karrq It's counterintuitive. That's the only disadvantage I know of. And it's quite important to focus on ergonomics in safety obsessed language because humans can handle only so much unnecessary cognitive load without making mistakes. There might be some performance advantage in reverse drop order (like in C++) because it's similar to how stack works, but I don't have any information on that
@keonix506
@keonix506 4 года назад
@@Karrq Researched it a bit and found that: 1. Panic during initialization drops elements in reverse order (inconsistent with regular drop order) 2. Due to straight drop order, constructor and destructor might have different relations to other objects. If we look at the example in this video, we will see that "thing 2" constructor called while "thing 1" exist, but it's destructor called when "thing 1" does not exist. This might lead to bugs, because this way destructing isn't just reverse constructing
@casperes0912
@casperes0912 3 года назад
I got scared when you said Zig doesn't guarantee structs are laid out in memory the way they're defined. I use that quite a bit in my bachelor project (an operating system) when switching between C and assembly. Being able to lay out a structure in assembly and then use it in C relies on that ordering. Though I also rely on __attribute for that so I guess ¯\o/¯
@contextfree
@contextfree 3 года назад
You might check out packed struct: ziglang.org/documentation/master/#packed-struct
@casperes0912
@casperes0912 3 года назад
@@contextfree Nice! Zig is promising as a systems development language. I enjoy C for that purpose but Zig sure looks like a nice alternative to C. And the packed struct there serve the purpose I mentioned before. Quite similar to my GCC based __attribute__((__packed__)) I already use to better control padding
@mgord9518
@mgord9518 Год назад
@@casperes0912 That's the main point of it. Zig also has a lot of low-level builtins so you can do essentially anything you want with packed structs. By default, you have a good amount of safety features (at least compared to C) but you can turn them off
@blenderpanzi
@blenderpanzi 4 года назад
2:36 When you take the address of a struct literal, where does the struct live? Is it put on the stack? What is it's lifetime? Usually temporaries only live for their enclosing statement, but that would mean the shown code has a dangling pointer. So I guess this is not what happens?
@SolomonUcko
@SolomonUcko 4 года назад
According to §6.5.2.5.5, "The value of the compound literal is that of an unnamed object initialized by the initializer list. If the compound literal occurs outside the body of a function, the object has static storage duration; otherwise, it has automatic storage duration associated with the enclosing block." (Spec version: ISO/IEC 9899:201x Committee Draft April 12, 2011 N1570, www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf )
@casperes0912
@casperes0912 3 года назад
Wait, what? I'm pretty sure I've been on GCC-10 for a while now
@contextfree
@contextfree 3 года назад
I don't remember the context enough, and I haven't rewatched much. What's the context for the question?
@fredhair
@fredhair 4 года назад
I originally learned C when I first started out coding years ago and then moved onto C++ because I naively thought it would be 'better' in some way or 'more powerful' and harder to make mistakes... More recently I have learned how wrong I was and how uneducated the people were who were telling me this. It seems like C++ has massively held me back in terms of productivity in ways that C never did and I'm just about ready to ditch C++ altogether and jump back to C for the majority of my code and possibly C# for some things that C isn't great at natively (web mainly).
@azyrael96
@azyrael96 4 года назад
One of the few things i don't like about c is missing oop, but otherwise, it really is one of my favorite languages as well.
@fredhair
@fredhair 4 года назад
@@azyrael96 C can very easily perform everything 'oop' thats useful in c++. The only thing I can think would be a challenge to implement easily and well maybe multiple inheritance which I generally avoid if I can in c++.. generally if you're faced with an object that is an x and a y it's usually very easy to refactor to say object has an x and has a y. Oop has always existed in C it just doesn't have the syntactic sugar to express that. C++ has templates and more compile time features but generally many of this can actually be done with macros and pre processor.
@totalermist
@totalermist 4 года назад
@@fredhair > C++ has templates and more compile time features but generally many of this can actually be done with macros and pre processor. That's simply nonsense. C++ templates are a Turing-complete language that fully integrates with the rest of the language and its runtime. The pre-processor is a primitive text-replacement tool that shares no semantics with C and cannot interact with C in any way shape or form. Same with lambda's and destructors. These features cannot be emulated by C and have to be written manually each time. There's simply no way to do type-safe meta programming in C and nice utilities like auto-pointers or type inference just don't exist in C. That's not just syntactic sugar, that's fundamental language features.
@fredhair
@fredhair 4 года назад
@@totalermist Type safe meta programming is overrated. Not sure what you mean about C not being able to do 'auto pointers' but C is certainly capable of doing reference counting on pointers. You really don't know C very well I'm guessing..
@totalermist
@totalermist 4 года назад
@@fredhair I honestly don't care about your opinion on type safe meta programming. I pointed out that your statement was factually wrong. And C is *not* capable of automatic life-time management, no matter what your cognitive bias tries to tell you. You really don't know what you're talking about is what I suspect, since you don't even grasp the difference between *automatic* lifetime management and tools like reference counting. *Automatic* being the keyword here. > You really don't know C very well I'm guessing.. I don't need to guess to know that you don't have the faintest clue what you're even talking about.
@Klayperson
@Klayperson 4 года назад
auto main() -> int what the fuCK
@igorthelight
@igorthelight 4 года назад
main() has to return execution code (0 or non-0)
@mgord9518
@mgord9518 Год назад
@@igorthelight Pretty sure they're talking about that format compared to "int main()"
Далее
Generators in Rust, C++20, Go, and More
12:45
Просмотров 19 тыс.
Namespaces & Modules in Rust, Zig, C++20, and More
14:27
Bike Challenge
00:20
Просмотров 20 млн
Первый день школы Катя vs Макс
19:37
Interview with Zig language creator Andrew Kelley
17:30
All Rust string types explained
22:13
Просмотров 168 тыс.
Comparing C to machine language
10:02
Просмотров 5 млн
Zero Cost Abstractions in C++20, Rust, & Zig
14:10
Просмотров 32 тыс.
Bjarne Stroustrup: C++ | Lex Fridman Podcast #48
1:47:13
Named Args in TypeScript, Python, C++20, & Rust
11:22
Arenas, strings and Scuffed Templates in C
12:28
Просмотров 85 тыс.
Demo: C++20 Concepts Feature
11:47
Просмотров 50 тыс.