Bjarne Stroustrup: C++ Zero-Overhead Principle and Object-Oriented Programming

  Рет қаралды 77,078

Lex Fridman

4 жыл бұрын

This is a clip from a conversation with Bjarne Stroustrup from Nov 2019. New full episodes are released once or twice a week and 1-2 new clips or a new non-podcast video is released on all other days. You can watch the full conversation here: kzbin.info/www/bejne/q4Xbg3lrlsxlbaM
(more links below)
Podcast full episodes playlist:
kzbin.info/aero/PLrAXtmErZgOdP_8GztsuKi9nrraNbKKp4
Podcasts clips playlist:
kzbin.info/aero/PLrAXtmErZgOeciFP3CBCIEElOJeitOr41
Podcast website:
lexfridman.com/ai
Podcast on Apple Podcasts (iTunes):
apple.co/2lwqZIr
Podcast on Spotify:
spoti.fi/2nEwCF8
Podcast RSS:
lexfridman.com/category/ai/feed/
Note: I select clips with insights from these much longer conversation with the hope of helping make these ideas more accessible and discoverable. Ultimately, this podcast is a small side hobby for me with the goal of sharing and discussing ideas. I did a poll and 92% of people either liked or loved the posting of daily clips, 2% were indifferent, and 6% hated it, some suggesting that I post them on a separate KZbin channel. I hear the 6% and partially agree, so am torn about the whole thing. I tried creating a separate clips channel but the KZbin algorithm makes it very difficult for that channel to grow. So for a little while, I'll keep posting clips on this channel. I ask for your patience and to see these clips as supporting the dissemination of knowledge contained in nuanced discussion. If you enjoy it, consider subscribing, sharing, and commenting.
Bjarne Stroustrup is the creator of C++, a programming language that after 34 years is still one of the most popular and powerful languages in the world. Its focus on fast, stable, robust code underlies many of the biggest systems in the world that we have come to rely on as a society. If you're watching this on KZbin, many of the critical back-end component of KZbin are written in C++. Same goes for Google, Facebook, Amazon, Twitter, most Microsoft applications, Adobe applications, most database systems, and most physical systems that operate in the real-world like cars, robots, rockets that launch us into space and one day will land us on Mars.
Subscribe to this KZbin channel or connect on:
- Twitter: lexfridman
- LinkedIn: www.linkedin.com/in/lexfridman
- Facebook: lexfridman
- Instagram: lexfridman
- Medium: medium.com/@lexfridman
- Support on Patreon: www.patreon.com/lexfridman

Пікірлер: 200
@lexfridman
@lexfridman 4 жыл бұрын
This is a clip from a conversation with Bjarne Stroustrup from Nov 2019. New full episodes are released once or twice a week and 1-2 new clips or a new non-podcast video is released on all other days. If you enjoy it, subscribe, comment, and share. You can watch the full conversation here: kzbin.info/www/bejne/q4Xbg3lrlsxlbaM (more links below) Podcast full episodes playlist: kzbin.info/aero/PLrAXtmErZgOdP_8GztsuKi9nrraNbKKp4 Podcasts clips playlist: kzbin.info/aero/PLrAXtmErZgOeciFP3CBCIEElOJeitOr41 Podcast website: lexfridman.com/ai Podcast on Apple Podcasts (iTunes): apple.co/2lwqZIr Podcast on Spotify: spoti.fi/2nEwCF8 Podcast RSS: lexfridman.com/category/ai/feed/
@Anonymous-nj2ow
@Anonymous-nj2ow 4 жыл бұрын
"when i was designing c++" what a gangster
@BackToBackSWE
@BackToBackSWE 3 жыл бұрын
yeah big 🍆 energy
@charliebitmyfinger7124
@charliebitmyfinger7124 Жыл бұрын
@pedro gomes tell me you don't know anything about CPP without actually telling me
@Abon963
@Abon963 Жыл бұрын
​​@pedro gomes bro stop u really don’t Know a shit about c++ it's not only C + classes
@manit77
@manit77 4 жыл бұрын
Please note kids, he said c++ has oop features not an oop language like java or c#
@loam
@loam 3 жыл бұрын
dude, in C# you can also use OOP technique, functional technique (because there's delegates and such; LINQ is basically functional programming if you like) or others if you want to do so. I bet same goes for Java (I'm mostly program in C# and don't have much experience in Java, except the examples I read in books)
@danb2108
@danb2108 3 жыл бұрын
@@loam he means the basic memory management mechanisms and language primitives are not designed around the OOP paradigm as in Java, C# or the big contender at the time SmallTalk (I still use Smalltalk at my job), OPP in C++ are features on a higher level of abstraction not fundamental in the language design.
@yasserarguelles6117
@yasserarguelles6117 3 жыл бұрын
@@loam In Java you can't declare things outside of a class forcing you to use classes, pretty sure the same goes for C#. C++ can be procedural without the need for any classes, matter of fact I don't think I ever need classes in C++ or certain other OOP features
@IamusTheFox
@IamusTheFox 3 жыл бұрын
@@loam True, you can do some functional things in an OO context. C++ can be used well with out a single class, on the same hand, it's not true OO because things are not derived from an ultimate root/base object. There isn't implicit boxing and unboxing in C++ like there are in pure OO languages.
@mehmetdemir-lf2vm
@mehmetdemir-lf2vm 3 жыл бұрын
c++ is not an oop language because it does not force you to write object oriented code. it has more oop features than java like multiple inheritance.
@battonfive
@battonfive 3 жыл бұрын
Bjarne is one of my long time heroes :-) some people look to footballers, astraunauts, quantum physists and sure i respect them all! but I love Bjarne :-D I mean I write in PHP but C++ is legend!
@Jacno77
@Jacno77 3 жыл бұрын
Would you have dinner with him but at the end of it you have to give him head?
@benvella1728
@benvella1728 2 жыл бұрын
@@Jacno77 asking the real questions
@federicoalbesa3748
@federicoalbesa3748 2 жыл бұрын
Saludos! Hermano del alma
@melvin4524
@melvin4524 2 ай бұрын
The guy has never shipped production code, ever. But people praise him for adding shitty features whose efficiency wasn't measured at all, to a language that has existed since the 70s and which was used to design programs made in the 80-90s that still works today ( i.e WindowsNT and Linux were made with C).
@thogameskanaal
@thogameskanaal 3 жыл бұрын
It's fascinating how much one or two people can do. If they have a clear challenge, and a bit of insight, they're very capable of doing a lot of research, gathering knowledge and experience in the process and eventually solve it in an efficient and intuitive manner. When you have a large group (say an enterprise organization), you have to worry about communication and coherence a lot. Basically ideas that sound bad on paper, but lead you closer to the answer are immediately dismissed in a larger group, while with one or two people, they'd at the very least attempt it and refine it, or scrap it but get insight on why it wouldn't work. Never underestimate the power of smart and motivated individuals. Their crazy ideas might have more merit than you think!
@kensei4237
@kensei4237 3 жыл бұрын
Makes sense I guess
@squishmastah4682
@squishmastah4682 3 жыл бұрын
I know. I'm consistently WRECKING IT solo or in small collabs.
@Artaxerxes.
@Artaxerxes. 2 жыл бұрын
Id say 4 is the limit and thats a generous number. Any more and the group totally breaks apart
@3145mimosa
@3145mimosa 4 жыл бұрын
I like this part, and the part of history of programming languages in 60s most in the interview. Thank you for your great work on this!
@megoo401
@megoo401 4 жыл бұрын
Please bring in James Gosling as well, that would be GREAT!! and a treat.
@_____case
@_____case 3 жыл бұрын
Thy will be done.
@0dyss3us51
@0dyss3us51 3 жыл бұрын
Even though I program in other langs tgan C++ I consider Bjarne to be a god damn legend and C++ a masterpiece!
@Anteksanteri
@Anteksanteri Жыл бұрын
To be fair you're allowed to think that C++ is a masterpiece if you don't actually have to use it 😩
@wednesdayaddams718
@wednesdayaddams718 7 ай бұрын
every day i needed to learn this stuff in my univ...yo.. it makes me cry but anyhow one day i wish to conquer it !!! this guy represents the entire generation lovely ..
@budiardjo6610
@budiardjo6610 Жыл бұрын
this is the first time i seeing bjarne so much happier
@Calypso694
@Calypso694 3 жыл бұрын
Learning it now. How and why this became the norm for nearly everything is beyond me.
@squishmastah4682
@squishmastah4682 3 жыл бұрын
Part of the answer is because it strikes a good balance between efficiency and ease of use. Part of the answer is in comparing it to everything that came before.
@scottanderson2871
@scottanderson2871 Жыл бұрын
I learned it decades ago. STL has improved - I mean back in the day it was so buggy we used to use the dinkum library in place of it. It’s really a terrible language. kzbin.info/www/bejne/Z5qXXphnpNCNqtk
@Funny_Family582
@Funny_Family582 Жыл бұрын
This man is really amazing
@osamaa.h.altameemi5592
@osamaa.h.altameemi5592 3 жыл бұрын
That was fantastic
@richardistvanthier5620
@richardistvanthier5620 3 жыл бұрын
The existence of the zero overhead principle in itself is already half the magic:in many languages they just think of an abstraction and if it is implementable in a "not awfully slow" way they do it. Then hope that the implementations in compilers once grow optimal. But the problem is that this way there are high chances that they miss something really similar feature that is maybe not solving the same problem, but is "good for nearly the same". In other worlds: c++ is great because it is not just a language -> compiler directional thinking, but many times they look for language features from the oher direction! They do bottom -> top thinking instead of top -> bottom. That is the magic.
@jboadas
@jboadas Жыл бұрын
Please activate automatic subtitles on these amazing videos
@deepblueharvest
@deepblueharvest Жыл бұрын
RE the discussion starting at 3:27, I in fact did write a matrix multiplication subroutine in Fortran that runs faster than the intrinsic MATMUL function about 60% of the time, but that difference might just be statistical noise lol
@binarytv2904
@binarytv2904 2 жыл бұрын
So C++ is like a giant toolbox with thousands of small and unique tools which are there to do only specific tasks. The efficiency and performance of your work depends upon which tools you took out of the box and use. You can substitute certain tools for other but don't expect similar performance (but the option is still there). So you need to have a good idea and understanding of all the tools you have at your disposal. Abstraction is a double edged sword. I actually understood it only after learning GDB and debugging some programs. That's when I got to see the assembly codes and finally saw myself how there are some instructions which otherwise I could have omitted but it's there just because I used the wrong tool. Languages like python gives you one giant tool to do a variety of otherwise dissimilar tasks but at the cost of performance.
@jasoncrawford1489
@jasoncrawford1489 3 жыл бұрын
5:43: Just to clarify, the word he used was "assembler".
@robertstimmel1100
@robertstimmel1100 3 жыл бұрын
You can thank this guy for the vast majority of modern Triple-A video games. Unreal Engine uses C++ as well as many other proprietary engines. Edit: After listening all of the way through, I doubt that anyone listening to this is unaware of what languages video games are written in. This is pretty high level lol
@hexadecimalhexadecimal5241
@hexadecimalhexadecimal5241 3 жыл бұрын
Yeah its a beast of its own, i still remember my first language....C. It was lets just say an experience. Planning on revisiting it though.
@robertstimmel1100
@robertstimmel1100 3 жыл бұрын
@@hexadecimalhexadecimal5241 I'm learning C# now. It's pretty tough because I'm going the self taught route, but it's been fun and rewarding (and really frustrating at times)
@cristiancosneanu
@cristiancosneanu Жыл бұрын
@Robert Stimmel The Devs of unreal are responsible for Triple-A video games. This guy is responsible for making a language that got popular. Games & game engines would've emerge from different languages. Look at Unity.
@oh-yes_10-fps15
@oh-yes_10-fps15 10 ай бұрын
@@cristiancosneanuwhile i 101% agree the lang doesn’t matter for video games and language debates are usually pointless for from the ground projects like game engines. It’s important to note a vast amount of unity’s backend in cpp. Just the user/dev facing scripting system and so bindgen between the cpp and CLR is c#
@user-yz7fr6kd7y
@user-yz7fr6kd7y 9 ай бұрын
C++ is not my favorite language, but I can't deny it's perhaps the most powerful out there.
@alexk6275
@alexk6275 3 жыл бұрын
It's a beautiful principle and I wish it held up in other languages, especially those on the JVM.
@euclid9492
@euclid9492 3 жыл бұрын
Yeah java is beautifully simple to me, I wish it had the same performance as well.
@alexk6275
@alexk6275 3 жыл бұрын
I personally prefer Scala after having some time to learn it. But the nice functional abstractions end up hurting performance for pretty much any CPU bound task. You end up reverting to loops and mutable variables which feel very out of place.
@kevalan1042
@kevalan1042 3 жыл бұрын
The JVM itself fails on this principle, seems to me. Performance tuning on JVM is like voodoo black magic
@bagzhansadvakassov1093
@bagzhansadvakassov1093 3 жыл бұрын
@@kevalan1042 Java is only 1.8 times slower than C. Which if you think about it is crazy.
@kevalan1042
@kevalan1042 3 жыл бұрын
@@bagzhansadvakassov1093 The JVM is indeed impressive, but 80% cost is definitely not zero-overhead. Also, optimizing C is *much* more principled and predictable than optimizing JVM-targeting code
@medusaskull9625
@medusaskull9625 3 жыл бұрын
It's not efficiency vs abstraction. It's efficiency vs deliverable. How long does it take to bring an idea to market vs how efficient is your code is in utilizing system hardware. In biological system, the things that we thought are unnecessary and inefficient became efficient and necessary when they deep analyzing it.
@thomasanderson621
@thomasanderson621 3 жыл бұрын
This danish man change the story of humanity forever, like Denis Ritchie.
@mehmetdemir-lf2vm
@mehmetdemir-lf2vm 3 жыл бұрын
yes, and he protected us from "subjective" c, which some fruit company likes very much.
@pedromiguelareias
@pedromiguelareias 3 жыл бұрын
Bjarne: sorry, faster than Fortran? As fast as Fortran, perhaps, and that only after imposing access constraints present in that Language (in C "restrict"). It's basically over now with people such as Scott Meyers abandoning ship. C++03 could have been cleaned up. What happened since then was crazy.
@MCLooyverse
@MCLooyverse 3 жыл бұрын
Maybe I'm missing something, but I just remembered when I wrote a program to draw the Mandelbrot Set to a bitmap file, and it was very slow. I had written a whole `Complex` class that (in that context) was only doing multiplication and norm, then I stripped that out, and just did the multiplication by hand, and it ran way faster.
@JakeLaMtn
@JakeLaMtn 3 жыл бұрын
I might be wrong, but I think you could do it just as fast with a complex class. But done incorrectly, it could definitely introduce inefficiencies.
@igorsilva8791
@igorsilva8791 3 жыл бұрын
He is talking about using a good abstraction, not any abstraction.
@ekremdincel1505
@ekremdincel1505 3 жыл бұрын
@@igorsilva8791 lol
@edunery
@edunery 9 ай бұрын
@@igorsilva8791what defines a good abstraction? “You are not doing it right” isn’t good advice
@paulkiat
@paulkiat 2 жыл бұрын
"My main tool for efficiency is abstraction" - Bjarne Stroustrup
@jasoncrawford1489
@jasoncrawford1489 3 жыл бұрын
Does anyone have a pointer to Doug McIlroy's discovery of C++ being faster than C?
@abelgerli
@abelgerli 3 жыл бұрын
Actually I loved C++ but I got the real problem that when you messed up the catch part and by mistake produced a exception there the whole software crashed unrecoverable. I never got in any problems with performance and looking at the const option it was just decades ahead when I think of functional programming today. I hope the catch crash problem can be handle today way better today.
@jeffmccloud905
@jeffmccloud905 3 жыл бұрын
all try...catch work this way, regardless of language (C#, Java, JavaScript, etc.)... your catch handler should never do anything that would throw an error. that is an "unhandled error". unhandled errors cause crashes. this is not a C++ thing. just use better error handling practices
@ekremdincel1505
@ekremdincel1505 3 жыл бұрын
Use something like Rust's Result maybe?
@ekremdincel1505
@ekremdincel1505 3 жыл бұрын
@@jeffmccloud905 I think swift makes exceptions more explicit.
@JamieVegas
@JamieVegas Жыл бұрын
Anywhere to find publicly written code by Bjarne? His GitGub lacks OO related projects.
@scottanderson2871
@scottanderson2871 Жыл бұрын
kzbin.info/www/bejne/Z5qXXphnpNCNqtk
@edunery
@edunery 9 ай бұрын
Maybe his GitHub does
@lenfirewood4089
@lenfirewood4089 3 жыл бұрын
Aren't a lot of the efficiency measures designed into the language also offset by the run time libraries needed to support all its functions?
@lenfirewood4089
@lenfirewood4089 3 жыл бұрын
@@__Brandon__ Do your homework before responding - it is hardly a secret that c++ relies on runtime libraries for a good deal of it's functionality.
@carlkohrs9857
@carlkohrs9857 2 жыл бұрын
"And" - Bjarne Stroustrup
@_____case
@_____case 9 ай бұрын
Guest request: Chandler Carruth.
@MisterFanwank
@MisterFanwank 3 жыл бұрын
Object oriented programming and zero cost abstractions are mutually exclusive. A compiler cannot inline a function if it doesn't know what function is going to be called.
@revimfadli4666
@revimfadli4666 3 жыл бұрын
Due to polymorphism? Doesn't c++ identify which one's which through parameter types?
@michaelrosen6478
@michaelrosen6478 3 жыл бұрын
Correct. But on the other hand, what would be the alternative implementation? Branching? Branching also has a cost. So you just have to pick your cost in some situations.
@SnakeEngine
@SnakeEngine Жыл бұрын
Zero overhead abstraction doesn't mean zero cost. It means you couldn't implement it any faster manually.
@JMRC
@JMRC Жыл бұрын
@@revimfadli4666 It does. As long as you don't use virtual functions, it's known at compile time. It can then be inlined and therefore use zero cost.
@Anteksanteri
@Anteksanteri Жыл бұрын
You are so completely wrong on this, and I am a big detractor of OOP. An object in memory is just an instance + functions. If you know the type, you know the function. Polymorphism is a separate thing. Also, not all inlinings are really zero cost (not that such a thing even exists). Sometimes saving memory is more important.
@fernsugi
@fernsugi 3 жыл бұрын
I watch this to sleep
@zakeria
@zakeria 4 жыл бұрын
hell yeah c++ concepts
@sasuke2910
@sasuke2910 3 жыл бұрын
It's funny how he can be so bold about being faster than low level code "most of the time". Maybe you can write a heap sort that's faster on certain hardware. But high abstraction applications have been trending slower and slower, and the likely culprit is something in the paradigms, but he seems in denial that such a problem could even exist.
@corinsenok
@corinsenok 3 жыл бұрын
yer funny how the dude who designed and tested this shit for decades has a deep perspective of the inner workings. super odd.
@shashishekhar----
@shashishekhar---- 3 жыл бұрын
@@corinsenok Not his point though.
@corinsenok
@corinsenok 3 жыл бұрын
@@shashishekhar---- nor was it bjarnes point.
@tridibroyarjo418
@tridibroyarjo418 3 жыл бұрын
C++ is the God And Creator Language, None should make fun of C++. If, he will regret it!
@nexovec
@nexovec Жыл бұрын
So why is it not zero-overhead then?
@NiinaSKlove
@NiinaSKlove 3 жыл бұрын
Erling P. Strand
@ericswenson1646
@ericswenson1646 4 жыл бұрын
i think low coupling is more important than object orientation
@eidiazcas
@eidiazcas 3 жыл бұрын
Yes and no, it depends, low coupling is generally achieved through writing more code, wrappers, interfaces, etc, which for some small applications it's not worth it, object orientation is just a way to not repeating code, it just works on the short term, the best language to handle that equilibrium is golang, where you make composition instead of inheritance but you do it in an inheritance way and have the best of both worlds
@KianSheik
@KianSheik 3 жыл бұрын
real life yoda
@MuhsinFatih
@MuhsinFatih 4 жыл бұрын
This man is the god of language design
@kensei4237
@kensei4237 3 жыл бұрын
pedro gomes he designed c++ is all they were saying
@MuhsinFatih
@MuhsinFatih 3 жыл бұрын
@@kensei4237 he's not even making an argument. He's pretending to have made an argument by showing off that he read a book and pointing to what I only assume is an opinionated text in the book. @pedro_gomes you cite papers and data, not opinions. now try again
@shashishekhar----
@shashishekhar---- 3 жыл бұрын
@@MuhsinFatih Lol, did you read it tho...he right in calling out your opinionated fangirling.
@coolcodingcat
@coolcodingcat Жыл бұрын
@@MuhsinFatih I looked up that book he speaks of and it costs money. I have to spend money to even see the page he is talking about. Edit: Maybe I can find it at the library.
@coolcodingcat
@coolcodingcat Жыл бұрын
@pedro gomes is that page of the book available for free or do I have to spend money to see it?
@angrycoder8808
@angrycoder8808 3 жыл бұрын
bring james gosling🤔🤔🤔🤔
@Rigardoful
@Rigardoful 3 жыл бұрын
Answer to first question: Apparently you don't
@sayokbhattacharya
@sayokbhattacharya 3 жыл бұрын
Is Bjarne a BDFL?
@Oodelally
@Oodelally 3 жыл бұрын
That’s guido van rossum for python
@michaelrosen6478
@michaelrosen6478 3 жыл бұрын
No - he doesn't actually have final control over C++ because it's created by a standards committee. He is just a "first among equals" kind of thing.
@Wiedzemir
@Wiedzemir 3 жыл бұрын
The biggest issue with C++ at the moment is the misguided clinging to backwards compatibility. Just deprecate older instructions already. It's too bloated.
@natheirabu-dahab9863
@natheirabu-dahab9863 3 жыл бұрын
Exaclty, so many things exist just for the backwards compatibility that it bloats the language. Either remove the unnecessary new stuff (like classes, we already have structs, why do we need classes?) Or forget backwards compatibility.
@gwills9337
@gwills9337 3 жыл бұрын
seems really short sighted to remove backwards compatibility, for a marginal benefit
@natheirabu-dahab9863
@natheirabu-dahab9863 3 жыл бұрын
@@gwills9337 fair point but it would also make the language easier and possibly faster. Also, because it would be nearly the same, a trans-compiler could be developed to translate C to C++.
@happygimp0
@happygimp0 3 жыл бұрын
@machine C is so popular because of the preprocessor and many other things. You can not replace the preprocessor by templates. You can replace a lot of it but not all, especially on low level. Most programming languages that want to be a replacement for C do not have a preprocessor and they all failed to become popular.
@mettaursp309
@mettaursp309 3 жыл бұрын
​@machine Templates in their current form are also a large part of what is wrong with modern C++. They are perfectly capable of doing very cool things with meta programming and are one of the big reasons why modern C++ is so good, but their current design is very deeply entrenched in backwards compatibility with techniques from older C++ versions. Many of the features that get added cater to building bridges around pitfalls that led to smelly code rather than addressing the core issues surrounding why the language fell short there. The pitfalls are still there, but they just aren't as visible as they were before. Two examples of really good features that were added that only partially mask really smelly code are C++17's fold expressions and std::apply. Fold expressions provide a shorthand way of expanding a template parameter pack without recursive templates, and std::apply provides a very nice method of unpacking a std::tuple's contents to be deployed as a function's arguments. These were both very big problems with C++'s method of meta programming with std::tuple argument expansion being particularly nasty. I love these two features because they are incredible simplifications of solutions to work around those problems, but because they are workarounds they betray the design flaws of C++'s templates. C++'s templates were never intended to be used for meta programming to my knowledge, so they weren't designed around it. However, because they were there and they were turing complete people started using them to generate and optimize run time code. I'd have to imagine this lead to an increased demand for new features to work around specific pain points with advanced template usage, and discovery of things like SFINAE further supported that usage. To be exact, I found a claim that many of these features were expanded upon specifically to aid development of the STL, and while I can believe it I cannot confirm or deny. Rather than getting a deliberately planned and well thought out meta programming feature we got expansions on templates that made them easier to use. I appreciate all the work that has been put into expanding their capabilities, but I also can't help but wish we got a cleaner and more intuitive abstraction for the features we currently rely on templates for.
@happygimp0
@happygimp0 3 жыл бұрын
The problem with C++ is compile time. Did you ever try to compile chromium?
@meuko
@meuko 3 жыл бұрын
Bruh, dont act like you work on projects that size everyday.
@ycombinator765
@ycombinator765 Жыл бұрын
@@meuko hehe got em
@iternative1865
@iternative1865 Жыл бұрын
And now comes Zig...
@frozen_tortus
@frozen_tortus 3 жыл бұрын
Python has left the chat.
@Wiedzemir
@Wiedzemir 3 жыл бұрын
What does Python has to do with anything? It's an interpreted languages not compiled. Can as well compare C++ with bash by this logic.
@Bobby.Kristensen
@Bobby.Kristensen 4 жыл бұрын
This reminds me of: kzbin.info/www/bejne/g2jKZ6OtlJWKZ7c
@nmagko
@nmagko 4 жыл бұрын
IMHO it's very difficult to compare C++ and C. If you are a C++ expert trying to rewrite your code in C sometimes you're going to make mistakes. A very good coding in C has not performance comparison to another high level programming language.
@gustavcc.m.7311
@gustavcc.m.7311 4 жыл бұрын
So 'C' is better..?.i think is more complicated.
@nmagko
@nmagko 4 жыл бұрын
@@gustavcc.m.7311 Not difficult. It takes time but you can take advantage of pointers. C++ has objects (of different type) you can create and destroy. C has pointers (of any type) you can allocate and free.
@coshvjicujmlqef6047
@coshvjicujmlqef6047 4 жыл бұрын
@@nmagko My question is WHY do you malloc/free/new/delete. What's wrong with T object. instead of T* object=new T; or auto object=std::make_unique(); ? It makes no sense for me. pointer is abused a lot in today's world.
@Anonymous-nj2ow
@Anonymous-nj2ow 4 жыл бұрын
@@gustavcc.m.7311 Joel Spoelsky, former CEO of Stackoverflow has said pretty much every programmer should know C
@tommasobonvicini7114
@tommasobonvicini7114 4 жыл бұрын
Thinking that a difference between languages is "C++ has objects while C has pointers and raw memory management" is plain wrong.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 3 жыл бұрын
Unfortunately, the “zero-overhead” principle has to be abandoned every time you try to do something actually useful with the language. Like anything involving dynamic memory allocation. Or the first time you discover that a “delete” method has to be explicitly declared virtual to avoid certain unpleasant surprises. Which means your class now has to have a vtable. And you wonder, don’t proper OO languages have tables for _all_ their classes?
@igorswies5913
@igorswies5913 3 жыл бұрын
OOP is designed to be slow
@richardistvanthier5620
@richardistvanthier5620 3 жыл бұрын
I routinely write months of code without ever writing a destructor and try to minimize dynamic memory altogether. You seem to try using c++ in java/C# style maybe???
@IamusTheFox
@IamusTheFox 3 жыл бұрын
In C++ that's c++11 and newer, there is very few reasons to use new/delete. I've written an entire state machine that is optimized away at compile time.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 3 жыл бұрын
Given the myriad applications of dynamic memory, that must severely limit the kinds of applications you write. Consider that even text strings require dynamic memory, unless you impose arbitrary limits on the lengths of your buffers. Here is a discussion of how to manage dynamic memory: github.com/ldo/a_structured_discipline_of_programming
@IamusTheFox
@IamusTheFox 3 жыл бұрын
@@lawrencedoliveiro9104 i didn't say dynamic memory. std::shared_ptr and std::unique_ptr instead of new and delete. In fairness I only glaced at it, but it looked like either c++03 or C.
@crankyunicorn4423
@crankyunicorn4423 3 жыл бұрын
this video was sposored by...Pepsi
@peterschmidt353
@peterschmidt353 3 жыл бұрын
c++ as a language is completely crap++
@TimVerweij
@TimVerweij 4 жыл бұрын
zero o'erhead :-)
@superuser8636
@superuser8636 4 жыл бұрын
Tim Verweij “The what?” (;
@rubenpartono
@rubenpartono 3 жыл бұрын
@@superuser8636 (Again) The seero o'erhead principle :-O
@superuser8636
@superuser8636 3 жыл бұрын
@@rubenpartono It's been two months and I can just read your comment out loud without having to replay the clip to understand the video :D
@carloseduardosilvalima362
@carloseduardosilvalima362 3 жыл бұрын
#include int main() { std::cout
@movax20h
@movax20h 3 жыл бұрын
Zero overhead. LOL. How about you fix unique_ptr overheads. It is atrocious.
@ekremdincel1505
@ekremdincel1505 3 жыл бұрын
Lol you are right
@MarquisDeSang
@MarquisDeSang Жыл бұрын
Everything C++ do, I can do in pure C. I can object programming with heritage and do try catch in pure traditional C. Why does C++ exist. At least Objective-C is compatible with C.
@ccgb92
@ccgb92 4 жыл бұрын
2:09. That's exactly what's happening with the language today, sad :(
@bigyanshrestha3035
@bigyanshrestha3035 4 жыл бұрын
@@deepankararya1994 Adding features isn't always good.
@bigyanshrestha3035
@bigyanshrestha3035 4 жыл бұрын
@@inxiti Agree on that! The point I was trying to make is one should be very selective while adding features to language.
@isura.m
@isura.m 4 жыл бұрын
Which features are you talking about?
@stifflery
@stifflery 4 жыл бұрын
@@deepankararya1994 , php, javascript etc
@neociber24
@neociber24 3 жыл бұрын
@@isura.m that's a good question, features like move semantics, constexpr and others are really good
@anonymous2150
@anonymous2150 5 күн бұрын
one of the smartest people ever born in history.