Object Oriented Programming is a Dirty Rotten Low Down Trick: A Look at How C++ Works

preview_player
Показать описание
In this video we explore some of the techniques used by compiler authors achieve the mechanisms of Object Oriented languages. It is interesting to see how close C++ is to C, and how simple these mechanisms truly are under the hood. Although the video concentrates on C++, similar techniques are employed by the Java Virtual Machine, the .Net Virtual Machine in C#, and many other OO languages.

0:00 - Introduction
1:29 - Private member variables
6:26 - Member methods
11:38 - Polymorphism, Virtual Functions

'[OO] is a dirty rotten low down trick' is a quote by by Dr. Michael Brady from the lecture:

Рекомендации по теме
Комментарии
Автор

It's a moment to remember when you finally realize that C++ is just C with one scoop of syntactic sugar and ten scoops of bureaucracy trying to fix that first scoop.

khatharrmalkavian
Автор

Had to actually stop and think about why I love this particular programming channel so much and it hit me. You don't talk philosophy, just computing, and it's so unbelievably refreshing to hear someone not spend hours lecturing me on why I'm a terrible programmer and just get right down to business. Wonderfully informing as always, keep up the good work!

bundlesofun
Автор

A long time back, I debugged a buffer overflow that was corrupting a vtable pointer. Oh boy, that was a mess. Basically, execution would jump seemingly randomly and I’d end up seeing a nonsensical and corrupted backtrace.

It’s fun when your program crashes inside a function that you know for sure is never called.

pyromen
Автор

The fact that methods receive the invisible this pointer internally shows a concept which I started to understand by coding in Python, where you have to specify the self parameter in method heads explicitly. It also shows that C is not that far away from an object oriented programming language, you can do the basic stuff with structs and functions that take a struct as their first argument, just like the this pointer. Thanks for the great video!

dennismuller
Автор

"Wait, it's just pointers?"
"Always has been"

Funny you mention the alignment table at 5:07. I've actually been wondering this: On a CPU that has strict alignment rules (like 68000, ARM, or most RISC CPUs) can you get more bang for your buck by doing this with your structs:

int foo;
char a;
char b;
short y;
int bar;

instead of:

char a;
int foo;
char b;
short y;
int bar;

williamdrum
Автор

Wrote a compiler for a little language when I was in university. The language was made specifically for the class, and changed as new ideas were taught in the class. All of this lines up pretty much how I expected. If you want to learn how memory is handled in something like C++ write a compiler by hand for a small language and it all becomes pretty clear. There are lots of books you can find to follow on this stuff, but i had the benefit of an awesome teacher.

TheEclecticDyslexic
Автор

Heh. Reminds me when I was first tasked with modifying a consted variable in my introductory C++ class. People looked at me like I was a homicidal maniac when I presented my inline assembly solution and proclaimed, "well, if you want me to ignore the compiler, nothing better than a bit of assembly!" Apparently, I was only meant to const_cast that poor devil. 😂

mikicerise
Автор

Now THAT'S what I call Forbidden C++

NonTwinBrothers
Автор

The real world use case for code like this is job security.

reirei_tk
Автор

I love this guy's videos. He is revealing all the magic computers have these days.

jokerpb
Автор

I think that it makes perfect sense that an object-oriented paradigm would be implemented using the simplest and fasted code that gets the job done.

MrRobertX
Автор

im learning so much internally about programming as a whole. ive never really understood what happens in the background, only what ive been taught in school, all horseshit. thank you, you're a great teach

nilionth
Автор

Circa 1990 I was writing 65816 assembly for the Apple IIGS and was really just getting interested in C++, which was just becoming mainstream. I was using MASM, which has a very robust macro facility and wrote a set of macros to create vtables and make virtual function calls so that I could do object oriented programming in assembly language. It was so much fun!

johnheaney
Автор

I went to school for visual C++ over a decade ago. _Definitely a bit rusty_
The main thing that stuck with me is my teacher complaining about my loops not terminating. _I can modify code, but can't write from scratch anymore_
Never even messed with memory directly, I could imagine his face if I did.
I'm of a mindset that I gotta break something to figure out how it works, and this seems a good starting point to get back into coding.

zeekjones
Автор

Awesome video. I never knew the vtable pointer was placed at the beginning of the class, but thinking of it now it makes a lot of sense

dylanconway
Автор

Good to actually see why classes were design for: let the compiler deal with the Vtable. Thanks!

fredgotpub
Автор

I had always thought of C as a strictly typed language until I read the book Expert C Programming: Deep C Secrets and it pointed out it was loosely typed and having more experience I realized, that yeah, you can always get to the bytes and do what you want.

bkucenski
Автор

This has got to be the most Aussie programming channel on the internet. Incredible.

AaronBonBarron
Автор

Creel, it's a real pleasure to watch your videos and partake in your years of (especially low level) language and implementation details. Thank you.

HominisLupis
Автор

i found this channel randomly not long ago and i cant figure out why i find his videos so comfy.
I feel its to do with how its just like hes talking and having fun.
What a cozy fella

mywall