How different are C and C++? Can I still say C/C++?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so today we're talking about c and c plus and really how different they are [Music] welcome back everybody i hope you're doing well most of my videos on this channel focus on c but occasionally i talk about c plus plus a little bit and i write some code in c plus plus or u c plus plus in the title and occasionally people kind of lose their minds and the most triggering thing seems to be when i write c slash c plus like this and when i do i tend to get comments like this so today i just wanted to wade into this topic a little bit and i might ruffle a few feathers maybe my opinion isn't your opinion but hopefully i can provide some clarity to those of you that are new to this or who wondering what all the fuss is about because i could see this causing a little bit of confusion to people who are new to programming and who are trying to understand what c and what c plus plus is and why don't they seem to get along so let's start at the beginning and talk a little bit about a simplified history of the world in the beginning ada loveless invented the first no that's too far back a bit after the beginning dennis ritchie invented c and c was without type safety and objects and yes objects existed but just barely they had just been developed in small talk which was the mother of all object-oriented languages and small talk came out about the same time as c and programmers saw that it was good or at least better than basic pascal fortran and cobalt then bjarna strausstrip said it is not good that c should not have classes and objects and so he created c plus plus now beyond estrella strip the creator of c plus plus describes c plus plus as a better c and some have debated the better part and i'm not going to dive into that in this video but let's just say that c plus plus is c with some additional language features like data abstraction object oriented programming and generic types and of course this is an oversimplification and not exactly 100 precise but the point that i want to make is that in the beginning dennis ritchie and brianna strausstrip were not rivals they were friends and bjarne was simply trying to build off of dennis ritchie's work and for a long time people have used the term c c plus plus to describe situations where the distinction between c and c plus didn't really matter that is when we're talking about things that are pretty common among the two languages but then something interesting happened between 1998 and 2021 and a lot of c plus plus developers have started getting a little touchy when you start to talk about them in this way when you start to talk about them like they belong together so what's going on well yes both languages have evolved a bit c plus plus has added a bunch of new features some of them i like some of them i don't like but that's a topic for another day stay on topic jacob but today most c code will still compile with a c plus plus compiler with little or no change to the code c is still almost a subset of c plus plus but not quite and now just to be clear if anyone involved in standardization or the standards community is listening i am a big fan of the idea of having cb a subset of c plus i like the idea of them being one language i don't see the point of having two languages with slightly different semantics i think it makes headaches and it's a pain and so if anyone out there who's actually actively working on this is listening i would like to see the two communities come together rather than move further apart and for what it's worth i'm pretty sure that bjornik strausstrip had that in mind when he started yarni please correct me if i'm wrong if i'm putting words in your mouth that don't belong there i'd love to have you on the channel but the point is is culturally that's not what happened now today i don't want to spend too much time burdening you with a lot of history about standards drift and how that happens i think it's pretty clear how that happens different projects have different opinions and they kind of push things in different directions the thing i'm interested in today is talking about the cultural drift and the animosity and what the fuss is all about because i mean this situation is kind of funny it's like two sisters and older and a younger and the younger now doesn't want to be associated with the older because she never learned how to appropriately encapsulate data or something it's kind of sad but maybe we can understand it a little at least i'm going to share you some of my thoughts and maybe they'll help because you see over the years it wasn't just the language that changed it was the culture and the community as well as the standard library and today in 2021 c plus has really split into two different things in my opinion on the one hand we have this c plus plus language syntax the compiler the tools and i'm going to call that big c plus plus big as in big tent and on the other hand we have the c plus plus culture community recommendations and standard library and i will call that little c plus and to be clear my big tent and little tent is really just a sense for how broad the definitions are it's not meant to be pejorative in any way but now why do i separate them well if i look at this line of code is it c or is it c plus well it doesn't matter as long as we don't invite little c plus to the conversation this code works fine in c and it works fine in c plus plus you get the same semantics and behavior in both languages and both compilers will accept this code as valid but while this code is perfectly fine in c and perfectly legal big c plus code it is considered bad awful hazardous to your health little c plus i can tell you from experience that if you call this code c plus plus in a youtube video you will catch flack for it you will get grumpy comments and if you ask them why you're likely to get something like something about community standards and modern alternatives and yeah now specifically what are we talking about well little c plus plus doesn't like unions they want you to use standard variant instead little c plus plus doesn't like passing pointer arguments use references character pointers nope use the string class and don't you dare include string.h come to think of it little c plus doesn't even really like pointers anymore whenever it can avoid them they're saying use smart pointers instead and i could go on and on but the point is that all these things are totally legal c plus plus they are part of the c plus plus language they are accepted by the compiler and the tools but they're just strongly discouraged by a large portion of the c-plus plus community and to be fair there are a lot of good reasons behind a lot of these recommendations some have to do with type safety some are trying to help you avoid memory leaks and other errors some allow the compiler to do smart things for you allowing your code to be more efficient or secure or more flexible and then of course some of them do just feel arbitrary like someone just decided that it should just be this way now personally i think some of this comes from the challenges that people face when they try to teach c plus to absolute beginning programmers to be fair it's a pretty difficult job and it's one that i griped about in a previous video but i can totally see them saying ah this is just a headache just just use strings stop using character pointers because maybe they don't want to teach both or maybe by mixing one with the other it's just confusing their students and scrambling their brains like eggs and they're just tired of their students failing exams either way what's happened and what's happening is that the c plus community has tried and is still trying to create a c plus world that looks like this where the c core of the language is tucked away as much as possible with object-oriented abstractions often rather leaky ones that they want programmers to use instead and will you might ask if you don't like these things in here why not remove them from the language i mean java and ruby don't have malachalic realic and free they don't have pointers either and they've been just fine if it's so terrible why not just drop the sea stuff and move on well good question and the answer comes down to basically core philosophy you see c plus plus is based on a few core philosophical ideas that make this difficult first the goal of the language is to add object-oriented features data encapsulation namespaces smart pointers whatever without and this is important without losing the ability to be blazing fast and lightweight and to get as low level as you like the second and a very related idea is that programmers should only have to pay for what they use or what they need if they don't want to include all that extra code that is required for a standard variant they shouldn't have to they should be able to use unions so this mindset really keeps c plus from eliminating any of these features they're here to stay because if i want to get minimalistic that's really what i go to and the only thing the community can do is try to push people like me around with standards and best practices and i want to be clear there's nothing wrong with community standards and best practices except that they are sometimes wrong sometimes they make sense and sometimes they don't i mean if i'm working on a microcontroller with 10 kilobytes of code space and 2k of ram then i'm going to trim everywhere i can and that means that most of those fancy new modern object-oriented c-plus plus features i'm going to leave them out i might keep namespaces in because that's not really going to change my code size or my memory size and even a lot of the things you see in c things like dynamic memory allocation mallet calc realic and free i'm probably not going to use those either because folks as i may have mentioned i have 2k of ram now another problematic and more common example is main i mean look at main every c plus plus program starts here right well just about all of them but that's a different topic for a different day and its argument list includes an array of c style strings character pointers right but little c plus plus hates c style strings right sorry main the beginning of all programs you are now in contravention of the little c plus plus community standards and best practices now how do you explain that to a new programmer without explaining to them c style strings and what you get is you get a whole lot of hand waving and taking things on faith and those are both things that you know i'm not a huge fan of so little c plus i know you're watching and as long as you're watching this channel on this channel the only rules that matter are these what a programmer can do and what a programmer can't do for example you can accept that i'm going to occasionally use c style strings in my c plus plus code and i'm going to call it c plus or you can't but character pointers are in your blood mates and totally legal in your language so you're going to have to square with that someday savvy i hope this is helpful or at least entertaining to some of you please let me know down in the comments if you agree disagree or think i'm being unfair to the little c plus plus community i fully expect to hear lots of defenses of community standards and that's perfectly fine also some of you older folks out there who may actually remember the tech world in the 70s or 80s i was pretty young and clueless back then maybe you can clarify some of my historical inaccuracies which i may very well have just propagated and of course if you're one of the few people out there that just this makes you really really mad you might want to find a different channel because honestly if i i love you but if we keep hanging out i'm just going to bug you on the other hand subscribe if you don't want to miss my next videos and i'll see you next week
Info
Channel: Jacob Sorber
Views: 45,988
Rating: 4.9462895 out of 5
Keywords: c vs c++, c language, difference between c and c++, c++ programming, c programming, c++ vs c, c or c++
Id: Kq8m980JEeg
Channel Id: undefined
Length: 10min 25sec (625 seconds)
Published: Tue Aug 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.