Forbidden C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024
  • The unimaginable evil of C++ is unleashed. Be afraid. Global Variables, Macros, Void*, Goto, Namespace STD, New & Delete, all the tools every C++ programmer needs... right?
    Patreon: / javidx9
    TH-cam: / javidx9
    / javidx9extra
    Discord: / discord
    Twitter: / javidx9
    Twitch: / javidx9
    GitHub: www.github.com...
    Homepage: www.onelonecod...

ความคิดเห็น • 2.7K

  • @javidx9
    @javidx9  4 ปีที่แล้ว +2025

    Hello! During these miserable times, I hope this raises a few smiles. Anyway, take care of yourselves, and don't forget those that may need some additional help. Keep washing those hands!

    • @festiveFurry
      @festiveFurry 4 ปีที่แล้ว +38

      I care about old processors and processor architecture

    • @Gizego
      @Gizego 4 ปีที่แล้ว +11

      @@festiveFurry I do too. I just wouldn't like programming for their limitations.

    • @chair547
      @chair547 4 ปีที่แล้ว +18

      Isnt the "dark side of c++" all of it?

    • @PJBonoVox
      @PJBonoVox 4 ปีที่แล้ว +8

      It did raise a smile. Enjoyed your attempt at thespianism :)

    • @eformance
      @eformance 4 ปีที่แล้ว +4

      I find it ironic that it takes 14 days to show symptoms and 14 days to recover...28 days later...

  • @mr649001
    @mr649001 4 ปีที่แล้ว +3579

    "Sir, why are you walking around with a hoodie and a shovel in the middle of the night?"
    "Uhhh umm uhhh just making a programming video"

    • @PhilBoswell
      @PhilBoswell 4 ปีที่แล้ว +50

      I would be more worried about his better half's reaction to him digging up her plants 😵🥴🤬

    • @engineerbot
      @engineerbot 4 ปีที่แล้ว +5

      Phil Boswell can you restate that in terms most people can understand?

    • @WillCrawford0
      @WillCrawford0 4 ปีที่แล้ว +46

      @@engineerbot his spouse might take exception to his desecrating the vegetable patch.

    • @dazhenghu4956
      @dazhenghu4956 4 ปีที่แล้ว +2

      bravo

    • @thomasdalby3567
      @thomasdalby3567 4 ปีที่แล้ว +1

      he coulda said his toilet was bogged up …..

  • @veda-powered
    @veda-powered 4 ปีที่แล้ว +4909

    intro is clearly fake... everyone knows programmers don't go outside.

    • @alphaforce6998
      @alphaforce6998 4 ปีที่แล้ว +188

      That was his basement.

    • @Kirides
      @Kirides 4 ปีที่แล้ว +183

      @@alphaforce6998 How could he not know. Programmers are so wealthy, we buy hundreds of yards of land to create a huge basement that looks like its outside, but without other people.

    • @NilesBlackX
      @NilesBlackX 4 ปีที่แล้ว +117

      @@Kirides "outside, but without other people"
      Those are the best five words I've ever seen put together

    • @mikekrow
      @mikekrow 4 ปีที่แล้ว +27

      He is a programmer, so he can afford to hire an actor

    • @Xorberax
      @Xorberax 4 ปีที่แล้ว +33

      Can confirm. I haven't left my house since the Coronavirus started. Neither have I left it a month before.

  • @codeman99-dev
    @codeman99-dev 4 ปีที่แล้ว +1037

    14:47 Way back when I first learned C++ (in college), I wrote an assignment with a goto for clean-up. My professor forced me to re-write it even though there was absolutely nothing wrong with my usage (he admitted so himself).
    So, I re-wrote it using a recursive function. He hated that even more. :)

    • @jeffspaulding9834
      @jeffspaulding9834 3 ปีที่แล้ว +153

      My school jumped from C++ to Java halfway through my time there, so many of my upper level classes used Java for everything.
      I learned that my professor didn't actually check our homework by doing all my assignments for our Data Structures class in Clojure.
      (Gotta say though, a different professor actually laughed and gave me an A for a Numeric Methods assignment I did in Fortran 77.)

    • @cezarcatalin1406
      @cezarcatalin1406 3 ปีที่แล้ว +51

      Jeff Spaulding
      I wrote some text parser in Cobol in my first year of university and both young teachers and colleagues thought I was some kind of wizard.

    • @absurdengineering
      @absurdengineering 3 ปีที่แล้ว +57

      @@cezarcatalin1406 “Can read books/other resources and learn new stuff = wizard” - because so many people can’t learn stuff on their own, or have no drive to pursue anything “intellectually hardcore” outside their realm of experience. And also because so many students just do the minimum needed to get by - I swear that teaching sometimes must feel like being dumbed down by all those souls in the classroom that only want a grade and move on…

    • @thomaspearson3698
      @thomaspearson3698 3 ปีที่แล้ว +58

      Oh, recursive functions? *Pulls out pepper spray*

    • @jeffspaulding9834
      @jeffspaulding9834 3 ปีที่แล้ว +18

      @@thomaspearson3698 After you program in Scheme long enough, you start to feel that way about while loops.

  • @Archimagus
    @Archimagus 3 ปีที่แล้ว +301

    I appreciate this video a lot. Because it doesn't just parrot "Don't EVER do these things" but actually gives examples why, but also gives a case or to where they actually make sense.

    • @tappineapple3381
      @tappineapple3381 3 ปีที่แล้ว +20

      I agree, I hate when there are youtubers who say "never do {this}" when there is always a time when it's justified.

    • @typowy2300
      @typowy2300 3 ปีที่แล้ว +7

      Global variables are a sin and programmers who use it burn in hell

    • @tappineapple3381
      @tappineapple3381 3 ปีที่แล้ว +3

      @@typowy2300 they are more of a problem in JIT languages rather than compiled ones.

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 2 ปีที่แล้ว +3

      @@typowy2300 Embedded?

    • @nikkiofthevalley
      @nikkiofthevalley 2 ปีที่แล้ว +6

      @@typowy2300 I use them fairly regularly in game dev, you have to have some kind of global state, and global variables are the easiest and simplest way of doing that. You can also use classes to make it so they cannot be modified without using the methods of the class itself, meaning you don't have the problem of global state being able to be modified at random. I also use a "glbl" namespace so I don't pollute the global scope. (and thus local scope as well)

  • @BerkaySoyluoglu
    @BerkaySoyluoglu 3 ปีที่แล้ว +217

    2:07 Global Variables
    8:11 Macros
    12:40 Goto
    16:27 (void *)
    22:23 using namespace std
    27:31 new & delete

  • @usmanahmed3035
    @usmanahmed3035 4 ปีที่แล้ว +1015

    Probably the greatest intro I'll ever see for a coding video

    • @javidx9
      @javidx9  4 ปีที่แล้ว +80

      Thanks Usman, I like doing the sillier stuff XD

    • @ir2001
      @ir2001 4 ปีที่แล้ว +14

      javidx9 That's why I love this channel and you are one of the few coding channels I'm subscribed to :)

    • @xtdycxtfuv9353
      @xtdycxtfuv9353 4 ปีที่แล้ว +5

      javidx9 yes your intro is deemed kek. expertly done.

    • @Kaltinril
      @Kaltinril 4 ปีที่แล้ว +2

      I completely agree!

    • @manuelesparza5321
      @manuelesparza5321 4 ปีที่แล้ว

      you should see cs50 lectures intro

  • @thepuzzlemaker2159
    @thepuzzlemaker2159 4 ปีที่แล้ว +751

    "...And within lies the most heinous and evil forms of C++ code ever known. Would you like to look inside?"
    *Cut to my C++ code*

    • @inigo8740
      @inigo8740 4 ปีที่แล้ว +13

      I was watching this video while coding and immediately moved my global variables into int main...
      At a good time too, since it was right when the errors were gonna pop up.

    • @aaronwise1089
      @aaronwise1089 3 ปีที่แล้ว

      @@username6338 he has various alternative options in no particular order being
      Unity
      Unreal engine
      Lumberyard
      Ogre
      Game Maker Studio 2.3
      Construct 3
      Gamesalad
      Clickteam Fusion 2.5
      Buildbox
      001 game creator
      RPG Maker
      Dreams PlayStation 4
      Scratch
      Stencil
      Visual Basic

    • @aaronwise1089
      @aaronwise1089 3 ปีที่แล้ว

      @@username6338 technically those programs can also create Apps and software

    • @StepDub
      @StepDub 3 ปีที่แล้ว +1

      I’m no longer a programmer, merely a data monkey, but my years as a programmer were perfect training for lockdown. In fact, I’ve quite enjoyed it.

    • @plutosutton6059
      @plutosutton6059 3 ปีที่แล้ว

      felt that...

  • @Digidan5
    @Digidan5 4 ปีที่แล้ว +1019

    who else expected one of their github repos to come out of the box XD

    • @ekrem_dincel
      @ekrem_dincel 4 ปีที่แล้ว +6

      Lol

    • @Wersjon
      @Wersjon 4 ปีที่แล้ว +1

      You got me :d

    • @graphitic5578
      @graphitic5578 4 ปีที่แล้ว +2

      An experienced user that joined 12 years ago and has no content, goddamit why wouldn't you.

    • @TahasYouTubeChannel
      @TahasYouTubeChannel 4 ปีที่แล้ว +3

      I love this comment so damn much because i relate

    • @ArIyan_yt
      @ArIyan_yt 3 ปีที่แล้ว +1

      😂

  • @OnboardG1
    @OnboardG1 3 ปีที่แล้ว +325

    “Processors from the 80s, no one is going to be interested in that surely?”
    *cries in embedded hardware*

  • @Ffhbm-Bzfe
    @Ffhbm-Bzfe 3 ปีที่แล้ว +425

    Me, who's only been coding in c++ for 2 months now: "I like your funny words coding man"

    • @cinnybun739
      @cinnybun739 3 ปีที่แล้ว +10

      Bruh, I don't even know CPP.

    • @danielesquivel3155
      @danielesquivel3155 3 ปีที่แล้ว +1

      ;(

    • @Skraeling1000
      @Skraeling1000 3 ปีที่แล้ว +3

      I think his main problem is that he hasn't numbered the lines.
      Like, yanno -
      10
      20
      30
      etc

    • @pietverver8194
      @pietverver8194 3 ปีที่แล้ว +1

      This comment made my day😂👌🏼

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 2 ปีที่แล้ว +4

      Me who knows Rust: *elitist smirk** _look what they need to mimic a fraction of our power_

  • @renhoeknl
    @renhoeknl 4 ปีที่แล้ว +550

    Timestamps:
    2:00 Global variables
    8:00 Macros
    12:36 Goto
    16:20 Void *
    22:17 Using namespace std
    27:19 New and Delete

    • @1889990
      @1889990 4 ปีที่แล้ว +9

      thanks you saved me from wasting 33 minutes

    • @Drqonic
      @Drqonic 4 ปีที่แล้ว +34

      @@1889990 "Wasting" That's a funny statement. Watching this video through to the end without skipping will benefit YOU significantly.

    • @The-Cat
      @The-Cat 4 ปีที่แล้ว +4

      @@Drqonic It wont benefit that person.
      He's got a busy life....
      Idk, just assuming... whatever...

    • @Drqonic
      @Drqonic 4 ปีที่แล้ว +2

      @@The-Cat and there are 24 hours in a full day. 33 minutes won't take shit from him.

    • @Drqonic
      @Drqonic 4 ปีที่แล้ว

      @かわいいreo Not really. 33 minutes is nothing.

  • @subcivil-youtubechannel7283
    @subcivil-youtubechannel7283 4 ปีที่แล้ว +2341

    #define true (rand() % 100 < 98)
    This is just pure evil

    • @orocimarosay1447
      @orocimarosay1447 4 ปีที่แล้ว +104

      Quantic physics ;)

    • @ke5uq1we8h
      @ke5uq1we8h 4 ปีที่แล้ว +184

      Interesting to note, that if you initializing random generator with a static value, you would be getting consistent behaviour with that define. Wild, but consistent.

    • @kaushikrishi2779
      @kaushikrishi2779 4 ปีที่แล้ว +114

      Don't forget
      srand(time(NULL)) this will make it more evil

    • @whythosenames
      @whythosenames 4 ปีที่แล้ว +49

      Володимир Герасимчук No you don't initialize it like if you would do variable = (rand()%100

    • @ke5uq1we8h
      @ke5uq1we8h 4 ปีที่แล้ว +11

      @@whythosenames srand(42); // no, I DO initilize it like this

  • @SelyHaudy
    @SelyHaudy 4 ปีที่แล้ว +405

    the c++ dark side "box" is actually very bright when opened

    • @thescreemregular5168
      @thescreemregular5168 4 ปีที่แล้ว +4

      🤔?Coincidence?🤔, I Think Not

    • @natoisnazi
      @natoisnazi 4 ปีที่แล้ว +64

      White IDE

    • @Cyberspine
      @Cyberspine 4 ปีที่แล้ว +19

      it's called the dark side because once you gaze into the box, everything will become dark

    • @garrusarchangel4562
      @garrusarchangel4562 4 ปีที่แล้ว +3

      There should have been red light like in Hell :))

    • @The_Pikaboi
      @The_Pikaboi 4 ปีที่แล้ว +15

      its all made in light mode IDE

  • @chrisbartlett9930
    @chrisbartlett9930 4 ปีที่แล้ว +1124

    Me opening my IDE at 3am without a dark theme 1:05

    • @Luca-sz5uy
      @Luca-sz5uy 4 ปีที่แล้ว +28

      underrated comment

    • @thelopburgGmail
      @thelopburgGmail 3 ปีที่แล้ว +9

      Made me laugh, got my like

    • @jeshuruncarlos6649
      @jeshuruncarlos6649 3 ปีที่แล้ว +3

      True !!! 🤣🤣🤣

    • @Hackanhacker
      @Hackanhacker 3 ปีที่แล้ว +2

      OHhohhoh shit i feel that right in my eyes !!!

    • @ytivarg5371
      @ytivarg5371 3 ปีที่แล้ว +9

      cries in codeblocks

  • @easyaspi31415
    @easyaspi31415 3 ปีที่แล้ว +530

    TL;DW: The C++ community's failing attempts to erase the C from C++.

    • @sodiboo
      @sodiboo 3 ปีที่แล้ว +20

      just start from scratch lmao

    • @easyaspi31415
      @easyaspi31415 3 ปีที่แล้ว +104

      Why Scratch? Can you even call that a programming language?

    • @easyaspi31415
      @easyaspi31415 3 ปีที่แล้ว +78

      @k je Au contraire.
      #include
      #include
      int main(void)
      {
      int c = 'c';
      int cplusplus = c++;
      if (c == cplusplus) {
      puts("See? I told ya!");
      return 0;
      } else {
      puts("Clearly this compiler is broken);
      abort();
      }
      }

    • @easyaspi31415
      @easyaspi31415 3 ปีที่แล้ว +42

      @k je what are you talking about? That was C++ I wrote. It just happens to be perfectly valid C by coincidence.

    • @easyaspi31415
      @easyaspi31415 3 ปีที่แล้ว +13

      @@sodiboo I can't believe this guy is serious

  • @addvert_br0009
    @addvert_br0009 4 ปีที่แล้ว +586

    2 minutes in and i just want a whole series like this.

    • @javidx9
      @javidx9  4 ปีที่แล้ว +160

      lol, If im kept at home any longer, that may happen XD

    • @addvert_br0009
      @addvert_br0009 4 ปีที่แล้ว +16

      @@javidx9 that would be perfect

    • @gregfletcher2360
      @gregfletcher2360 4 ปีที่แล้ว +8

      Yes, please!

    • @dickheadrecs
      @dickheadrecs 4 ปีที่แล้ว +1

      here here

    • @DerKaktusAvant
      @DerKaktusAvant 4 ปีที่แล้ว +2

      @@javidx9 well the lockdown is here sooo

  • @jimfcarroll
    @jimfcarroll 4 ปีที่แล้ว +1788

    Best macro ever:
    #define private public

    • @brilletjuh2
      @brilletjuh2 4 ปีที่แล้ว +276

      even better: #define public private

    • @brilletjuh2
      @brilletjuh2 4 ปีที่แล้ว +65

      @@djordjermus2000 or why can't i access this function, is it clearly public?

    • @rauldragu9447
      @rauldragu9447 4 ปีที่แล้ว +143

      cease, demon

    • @aperson4051
      @aperson4051 4 ปีที่แล้ว +7

      This is actually very handy at the right times

    • @unstableslayer9662
      @unstableslayer9662 4 ปีที่แล้ว +149

      #define protect delete
      Now all your variables are safe

  • @GrandHighGamer
    @GrandHighGamer 4 ปีที่แล้ว +103

    My takeaway from the beginning of this is that the briefcase in Pulp Fiction actually contained a void pointer.

  • @NXTangl
    @NXTangl 3 ปีที่แล้ว +144

    "The most heinous and evil forms of C++ ever known"
    So, like...literally any production C++ for a video game?

    • @billgatest7563
      @billgatest7563 3 ปีที่แล้ว +33

      This comment reminds me of the fast inverse square root

    • @metagen77
      @metagen77 3 ปีที่แล้ว +3

      Whats wrong with games and c++

    • @itap8880
      @itap8880 3 ปีที่แล้ว +2

      @@metagen77 Well... I don't know either.

    • @regeneric928
      @regeneric928 3 ปีที่แล้ว +7

      @@billgatest7563 That was done back in the 90s. In modern times leave the thinking to the compiler and just use sqrt() and others, it'll handle it much better than most of the programmers.

    • @danielesquivel3155
      @danielesquivel3155 3 ปีที่แล้ว

      el que explique no es gey

  • @C_Corpze
    @C_Corpze 3 ปีที่แล้ว +31

    This seems very interesting, you actually cover the bad and good usecases for methods as well, I love that.

  • @Nytra_
    @Nytra_ 4 ปีที่แล้ว +168

    As a programmer who is quite inexperienced with C++, this was an extremely informative and easy-to-understand video. I'll definitely be coming back to your channel in the future. Thank you. :)

    • @chosesomething
      @chosesomething 4 ปีที่แล้ว

      @Marcelo Rocha Any more you may know of ? Please put them here :)

    • @Hyrtsi
      @Hyrtsi 4 ปีที่แล้ว +6

      Oh my. There's a lot of weird c legacy in cpp. And all of these 'evil' tools are still tools after all. One just should use them correctly. This is the most difficult thing in programming. I remember my first year - I came across all these and the situations where they are a pain and the ones where they are the best

    • @clarissagun5581
      @clarissagun5581 3 ปีที่แล้ว +1

      As a programmer who is quite inexperienced with C++, this was an extremely informative and easy-to-understand video. I'll definitely be coming back to your channel in the future. Thank you. :)

  • @frans.8906
    @frans.8906 4 ปีที่แล้ว +320

    I actually laughed at the redefinition of "true" to a probability of being true. Nice video!!

    • @kalesantosh
      @kalesantosh 4 ปีที่แล้ว +1

      +1

    • @Damaniel3
      @Damaniel3 4 ปีที่แล้ว +11

      That was the first time in this video that I actually said out loud 'now *that* is evil'!

    • @MrCh0o
      @MrCh0o 4 ปีที่แล้ว +4

      I assume this... gift will work on anyone who decides to blindly trust and include your code into their program?
      This could result in a catastrophic hair loss

    • @inigo8740
      @inigo8740 4 ปีที่แล้ว

      @@MrCh0o seems like an awfully evil way to enforce good habits, I love it

    • @yowie7169
      @yowie7169 4 ปีที่แล้ว

      @@fabricatorzayac lmao

  • @Gastell0
    @Gastell0 3 ปีที่แล้ว +67

    "Eventually I will consume all of the memory in my system" - Wait, it isn't the goal?

    • @petergamache5368
      @petergamache5368 3 ปีที่แล้ว +17

      You're thinking of Java.

    • @Gastell0
      @Gastell0 3 ปีที่แล้ว +15

      @@petergamache5368 Java is just easiest of them all to get there xD

    • @patrickgono6043
      @patrickgono6043 3 ปีที่แล้ว +20

      100% memory speedrun

    • @Gastell0
      @Gastell0 3 ปีที่แล้ว +2

      @@patrickgono6043 Now that sounds like a worthy challenge!

  • @garthor
    @garthor 3 ปีที่แล้ว +32

    You can also put your "using namespace" inside a function I believe, which is even better than leaving it outside in the global space, because it goes out of context when the function ends rather than when the file ends... =D

  • @z0mbiebanana9891
    @z0mbiebanana9891 4 ปีที่แล้ว +137

    Remember in my first year of uni I was learning C++, my first proper programming language, and for my first assignment I filled my program with goto's nearly everywhere where I could have used a while loop. 1 week before submission I showed my progress to my teacher and he ripped me a new one. I learned quick that day, a goto is a no go xD.

    • @WorBlux
      @WorBlux 4 ปีที่แล้ว +77

      The assembly produced would be almost identical. The sanity of the next person to touch your code... not so much.

    • @alphaforce6998
      @alphaforce6998 4 ปีที่แล้ว +8

      What they never teach you in any college is that the stuff you are taught won't translate to marketable skills. People who can't learn programming on their own just by doing it with self-motivation will likely end up doing customer service or tech support... but hey, look at that degree. Makes them feel special!

    • @magnuscoles5010
      @magnuscoles5010 4 ปีที่แล้ว

      @@alphaforce6998 I'm learning c in my first year of uni, the exams are in a month, and I still don't know how to properly program in c, I have finished watching several toturials and still I can't seem to grasp it, what I'm I doing wrong?

    • @MultiTrickster121
      @MultiTrickster121 4 ปีที่แล้ว +7

      @@magnuscoles5010 if you want to learn c++ have a look at The Cherno's TH-cam channel. He has a whole playlist of great c++ tutorials

    • @derrickmelton5844
      @derrickmelton5844 4 ปีที่แล้ว +16

      @@alphaforce6998 idk I learned C++ from the ground up all on my own and it hasn't helped me land a job...the reasons are all self inflicted like a lack of confidence to apply places, worry that i don't have the qualifications needed, etc...so a degree is the confidence boost some individuals need, not to mention it helps you make connections to get your foot in the door somewhere.

  • @trolleyproblem4318
    @trolleyproblem4318 4 ปีที่แล้ว +138

    Bjarne is clear: There are only two kinds of languages: the ones people complain about and the ones nobody uses.

    • @ccgb92
      @ccgb92 4 ปีที่แล้ว

      Ritchie > Bjarne

    • @frydac
      @frydac 4 ปีที่แล้ว +10

      Ritchie and Bjarne sat at the same lunchtable for 16 years or so (Bjarne said in some interview), and Bjarne is a big contributor to C and thinks C is a great language (why else would he take it as a basis). While this is no argument against the '>', it would indicate they probably have very similar views on things.

    • @sea-ferring
      @sea-ferring 3 ปีที่แล้ว

      @@ccgb92 troll

    • @ccgb92
      @ccgb92 3 ปีที่แล้ว

      @@sea-ferring Ritchie > Bjarne easily. If it wasn't for Ritchie's C, C++ wouldn't even exist.

    • @mvisperas
      @mvisperas 3 ปีที่แล้ว

      I wonder if Ritchie's keyboard is broken. Why he used * for pointers instead of @ just like in Assembly? It's much more intuitive to use @.

  • @erykaemilien77
    @erykaemilien77 4 ปีที่แล้ว +116

    You explained dynamic memory and the use of "new" and "delete" in a few seconds than an hour and a half Comp sci lecture. 😮

    • @ytltqsoft
      @ytltqsoft 4 ปีที่แล้ว +14

      std::audio developer: Making an audio adapter work as expected is very difficult bla bla bla.
      game programmer: just give me this and everyone will be happy: std::audio_source::play();

    • @EmilParkour
      @EmilParkour 4 ปีที่แล้ว +1

      Error: expected a 'better', instead you typed 'in'.

    • @CottidaeSEA
      @CottidaeSEA 4 ปีที่แล้ว +5

      @@EmilParkour I think your compiler has a bug. That's not where the error is located.

    • @Stoney3K
      @Stoney3K 4 ปีที่แล้ว +11

      "You don't own your memory, the operating system does."
      Well,. the receipt I got here from the computer shop tells me otherwise, SO I"M NOT GONNA DELETE.

    • @xybersurfer
      @xybersurfer 3 ปีที่แล้ว

      i don't think that's completely fair. without the CS lecture, this probably wouldn't be so easy to you

  • @gameprogramme
    @gameprogramme 3 ปีที่แล้ว +5

    Professional software engineer with 20+ years experience here (a good portion of that in C++).
    As others have already said, this is an excellent video for any C++ developer of any experience level. I especially like how you show both problematic and acceptable uses (or alternatives) for each of these techniques.
    I did feel you made ONE MAJOR OMISSION in your discussion of new and delete, and I mention it because you have yourself such a great opportunity discuss it, before side-stepping the issue, and jumping straight to the “correct” solution. I really wish you would have covered how exceptions interact with new and delete, because that is where I see many developers get into trouble. The more obvious case would be where a thrown exception prevents a delete from being called, would have been a great place to start. The more subtle situation (and the primary reason for make_unique() to exist) is an exception thrown within a constructor. These leaks can be particularly tricky to track down.
    Again, thanks for the great video.

  • @BernardBernouli
    @BernardBernouli 4 ปีที่แล้ว +44

    Void* brings up bad memories for me. In one of my classes we had to finish programs to implement various algorithms, but the person who wrote the pre-written parts loved to use void*, even when the type was very clear and essentially always the same. This lead to all kinds of casting problems.

    • @acasualviewer5861
      @acasualviewer5861 2 ปีที่แล้ว

      void* was typically used in C programs because they lacked OO features. C++ introduced better ways to do the same.

  • @mohammade.8770
    @mohammade.8770 4 ปีที่แล้ว +133

    1:23 is where the iconic "Hello" strikes.

    • @javidx9
      @javidx9  4 ปีที่แล้ว +26

      iconic eh? XD

    • @sebastianschneider9383
      @sebastianschneider9383 4 ปีที่แล้ว +5

      Mohammad E. It’s just what I thought. His “Hello” is so iconic. xD

    • @rickjohnson1719
      @rickjohnson1719 4 ปีที่แล้ว +1

      Thanks, thats what im here for

  • @MichaelRichardson-bw5xh
    @MichaelRichardson-bw5xh 4 ปีที่แล้ว +128

    2 minutes in and it's already the best thing I've seen all week.

    • @javidx9
      @javidx9  4 ปีที่แล้ว +17

      Thanks Michael!

    • @MichaelRichardson-bw5xh
      @MichaelRichardson-bw5xh 4 ปีที่แล้ว +5

      @@javidx9 my friend, thank you. I've been programming for 20+ years and watch every one of your videos. They are all fantastic and I have suggested them to anyone that mentions to me that they're interested in learning programming. I think the knowledge you're providing is enough to change life trajectories for people out there if they're looking to learn and better themselves.

  • @nerdudi5745
    @nerdudi5745 4 ปีที่แล้ว +16

    When my professor told us that we should never use global variables, someone asked why. He said that global variables are evil and didn’t explain any further. Thank you for sharing the dark bits of C++ and explaining them, I finally know what not to do

    • @alphaforce6998
      @alphaforce6998 4 ปีที่แล้ว +7

      Sounds like a bad/lazy teacher and you probably paid too much to have him not teach you anything.

    • @michaeldegans1354
      @michaeldegans1354 4 ปีที่แล้ว +5

      Because it's harder to test is one good reason. Units needs to be isolated to behave predictably. Applies in any programming language. He should have given reasons like this however.

    • @edgeeffect
      @edgeeffect 4 ปีที่แล้ว +2

      If your professor couldn't or wouldn't tell you why, they shouldn't be teaching.

    • @alexandrubragari1537
      @alexandrubragari1537 4 ปีที่แล้ว +1

      I remember my professor starded explaining when a friend of him wich liked to use global variables fked up a whole program (it was a big project imo, like scientific research) for a redefinition of a global variable on some file and they had to debug for 3 days and lost a huge time and money due to that e evil behavour

    • @absurdengineering
      @absurdengineering 3 ปีที่แล้ว

      Isn’t it clear, though? Imagine I had a light switch in my bathroom that controlled the light in your bathroom. That’s the first thing that should come to mind when you look at the concept of a global variable! Good luck figuring out the switch is in my house :) Of course today we have IDEs that let you find all uses of a variable at a press of a key combo, but you also need to be paranoid enough to think of inspecting that variable. And any “protocols” people agree to with respect to globals always break down.

  • @MrHatoi
    @MrHatoi 4 ปีที่แล้ว +27

    1:20 POV: You are just regaining consciousness after having been kidnapped by javidx9 and being taken to his dungeon

  • @gabrielmansano
    @gabrielmansano 3 ปีที่แล้ว +12

    22:05 "I'm impressed, well done you've made this far, not many people have a stomach like you" me with a confused face watching the video understanding like only 20% of those cursed techniques

  • @pako_powr
    @pako_powr 4 ปีที่แล้ว +183

    The Halloween special we never knew we wanted..

    • @swiatek7
      @swiatek7 4 ปีที่แล้ว +2

      MindSpyke we surely did need one though.

    • @Kaltinril
      @Kaltinril 4 ปีที่แล้ว +2

      Exactly!

    • @solaireofastora5212
      @solaireofastora5212 4 ปีที่แล้ว

      Hello there.

  • @THExRISER
    @THExRISER 4 ปีที่แล้ว +58

    12:38 Ah yes,Goto, I'm glad I stopped using it early when I started learning to code, thanks of course to all those C++ Discord users who would completely neglect the problem I was asking about and start pestering me about why I used a Goto as opposed to a while/for loop while simultaneously spamming pepelaugh emotes all over the place, classic!
    They were right though, even though I was still writing simple programs at the time, simply replacing Goto with some loop did solve the problem in some cases,so to any C++ Discord users present here, you guys are dicks, but also thank you!

    • @CottidaeSEA
      @CottidaeSEA 4 ปีที่แล้ว +10

      Yeah, a GOTO loop is the same as a while loop, but the while loop is easier to recognize due to the encapsulation and naming.
      It's not like GOTO is necessarily bad, but it does introduce unnecessary complexity. I actually quite like GOTO, but it should be used carefully.

    • @garychap8384
      @garychap8384 4 ปีที่แล้ว +1

      goto's are never strictly necessary. Usually they're a sign of very sloppy thinking.
      I've used them, rarely, in some driver code where the alternative would have been far less readable. But only EVER forwards to simplify complex logic ending in common wrap-up code. The backwards goto, on the other hand, is truly evil and I've never seen a valid case for it.
      Any time you feel the need to use a goto... you should wrestle with the decision. If it doesn't cause you, at the very least, a sleepless night or a re-factor... then you've really not thought it through properly ; )
      Using goto is something you need to agonise over and try to make peace with.

    • @DFX2KX
      @DFX2KX 4 ปีที่แล้ว +2

      @@garychap8384 there *might* be the fringe case in working with a system that has VERY little RAM to work with (such as an Arduino), but I'm not a good enough programmer that I can use GOTOs any better then the compiler would.

    • @Bistai949
      @Bistai949 3 ปีที่แล้ว +3

      Funnily enough, I didn't even know GOTOs were supported by C++. I assume it's a holdover from C because object oriented languages were still relatively new at the time C was developed. It gave me a good chuckle, and reminded me of my Assembly class in college.

    • @THExRISER
      @THExRISER 3 ปีที่แล้ว +2

      @@Bistai949 Yeah I sometimes forget how old C/C++ actually is.

  • @englishmotherfucker1058
    @englishmotherfucker1058 4 ปีที่แล้ว +462

    I didn't know about goto, seems useful.

    • @javidx9
      @javidx9  4 ปีที่แล้ว +527

      XD What have I done??!!

    • @Invalid571
      @Invalid571 4 ปีที่แล้ว +141

      @@javidx9
      You've opened the gates of bug hell. XD

    • @MrEdrftgyuji
      @MrEdrftgyuji 4 ปีที่แล้ว +53

      The Linux kernel runs off of goto

    • @EngineeringVignettes
      @EngineeringVignettes 4 ปีที่แล้ว +30

      @TBit - Nope, use a
      do { ... } while (false);
      and in the 'guts' (...) use break; to drop out of the loop when you need to. As it is false, it will never loop more than once.
      Behold the "DDW" (Doug's Do-while)
      (never mind the name... long story)
      Cheers,

    • @hqqns
      @hqqns 4 ปีที่แล้ว +14

      goto is from "c"

  • @iMCOCOarmy
    @iMCOCOarmy 4 ปีที่แล้ว +32

    define int float; define true (98% of the times) lmao I died laughing so hard

  • @YoutubeStandardLicense
    @YoutubeStandardLicense 4 ปีที่แล้ว +2

    After years of dicking around with Python with an inane fear of C++ I have started to delve into C++ and my god am I learning so much from this channel!

  • @whynotanyting
    @whynotanyting 4 ปีที่แล้ว +39

    Him: "I commend you for making it this far."
    Me, not fully understanding it: "Thanks."

  • @oracleoftroy
    @oracleoftroy 4 ปีที่แล้ว +67

    Me while watching the video: Err, I don't think _inline_ works that way.
    You: The meaning of inline has changed over the years...
    Me: better double check before embarrassing myself with a snarky comment.
    C++17: Make Inline Great Again
    Me: Neato! I learned something new today!

    • @shukterhousejive
      @shukterhousejive 4 ปีที่แล้ว +10

      After seeing how you use the goddamn bit shift operator to write to stdout I thought I'd stop being surprised by how C++ mangles its own syntax, but here we are!

    • @kneesnap1041
      @kneesnap1041 4 ปีที่แล้ว +11

      @@shukterhousejive Same. C++ is probably the most bizarre language evolution I've seen.

    • @tetsuoiiii
      @tetsuoiiii 4 ปีที่แล้ว

      @@kneesnap1041 more like de-volution

    • @kneesnap1041
      @kneesnap1041 4 ปีที่แล้ว

      @@tetsuoiiii lmao I'm with you there.

    • @oracleoftroy
      @oracleoftroy 4 ปีที่แล้ว +7

      @Michael Deloatch Yeah, it's a great change. I'm not sure why others are using my post to hate on C++, it keeps getting better and better.

  • @cpu_UP
    @cpu_UP 4 ปีที่แล้ว +43

    Woe to you, on Earth and Sea. From the devil sends the beast with wrath, because he knows you will use global variables.

  • @andreyzolotykh9005
    @andreyzolotykh9005 ปีที่แล้ว +1

    This is one of the best C++ video tutorials I've ever seen.
    Clear and accessible presentation, special effects and artistic dramatization. Absolutely super! Thank you!

  • @mrbrown6421
    @mrbrown6421 3 ปีที่แล้ว +9

    Thanks for the flashback!
    After college (1984), my first 10 years were spent on embedded systems
    in which we wrote assembler and did not have any underlying Operating System.
    I thought in terms of hardware and memory.
    I somehow managed to sustain employment in C++, but I never felt comfortable
    with it, and now....I repair small engines.
    Abandoned the software engineering career with glee!

  • @GingerGames
    @GingerGames 4 ปีที่แล้ว +17

    The criticism for why global variables are bad is not inherent to global variables and only really a concern for beginners. Yes global state has a lot issues but the concept is not inherently bad and extremely useful in many problem domains (e.g. games are a good example since there is a lot of shared state). Some people may prefer passing the global state around everywhere, but sometimes that is much more cumbersome than before. It may be wise to tell a beginner to C++ (or C) to try to not to use global variables if possible, but they should not be forbidden.
    Macros are not a replacement for templates, and macros are fine when you are trying to add functionality which templates cannot do. C-style macros are unhygienic and can cause issues because of this, but they are not inherently bad. For beginners, they should be used with a lot of caution and the user of them must know the issues with them. This wisdom comes with experience.
    The statement that "`goto` will, not might, cause spaghetti code" is only true for beginners. There are perfectly valid use cases for them in C++ which produces _cleaner_ code than not using them. This is because of C++'s lack of structured features, such as named scopes for the ability to break out of parent control structures or defer/scope-exit (the latter of which can be implemented quite easily).
    `void *` is fine, and the complaint main is that `void` is not typed, which is the entire point of `void`. `std::any` is pure evil in C++ (because C++'s RTTI is dreadful). The example to replace `void *` with `std::any` is actually much more bug prone than before because if a pointer is passed rather than the value, the value of the pointer will be written rather than the value that the pointer is pointing to. And that use of `std::any` is incorrect.
    I completely agree that `using namespace std;` is evil and I would actually go further and say `using namespace` is evil in C++ always. P.S. If people like C++ style namespaces, they should keep to one level deep any way because heavily nested namespaces do not aid in readability, refactoring, organisation, and more.
    `new` and `delete` are bad but not for the reasons stated, which is just a complaint about _manual memory management_. (P.S. Placement `new` is good if you like constructors). `std::unique_ptr` is not a replacement for `new` with automatic memory management; brings along a new concept called "ownership/move semantics". They are __not__ the same as reference counted pointers, nor an alternative. C++ is not meant to be an automatic memory managed language, please don't try to treat it like one. This is does not mean you should try to use loads of small and manual memory allocations but rather keep the allocations to a subsystem, and let that handle it if necessary.

    • @brkr78
      @brkr78 4 ปีที่แล้ว +3

      Ad global variables: If you have a single threaded application then you can, with care and a lot of shifting around of that gray mass in your head anticipate in what state a specific variable is at any given time. In debugging you can stop and then backtrack how you got there. But once you start writing multithreaded code all bets are off. Using global variables in concurrent code is just suicide.
      Ad macros: Macros are a two-sided sword. On the one hand they can be very powerfull when used correctly. At the same time that is the reason why they are dangerous. As long as you write programs for yourself and keep track of what you are doing ... more power to you. But beginning with a certain size of project those macros tend to throw off people if they have to maintain the code somewhere down the line.
      Ad goto: What you are saying kind of echoes what has been said in the video. There are SOME edge-cases where goto might make sense. But only then. If you start to code C++ with gotos like you code good old BASIC-code then you will run into spaghetti code.
      Ad void* : The usage of void* is, IMHO, nowadays realy limited. Or at least it should be. The problem is that it is sometimes used in ways that are ingenious when first implemented but nigh impossible for anyone else to maintain afterwards. I agree that std::any isn't the be all end all and that you have to be just as carefull. However, pointer to pointer logic is IMHO slowly disappearing in favor for structured types.
      Ad namespaces: There are instances where additional levels of namespaces make sense. It kind of depends on the size of the project. But I have to agree that it also tends to get out of hand pretty quickly, and suddenly you have a three or four layer deep namespace.
      Ad memory management: Not much to add there, except maybe: He's using MS C++, and that actually CAN be written with both manual and automatic memory management. And again - concurrent programming and memory management are a whole different can of worms.
      I'd like to say it all boils down to preference, but that is not quite true. It realy depends on whether the company you write code for has coding guidelines to which one has to adhere, be it as a freelancer or as an employee. Even in large OSS-projects you usually can't do whatever you want - at least if it is managed properly. If there is a code review and those guidlines are in place then you need a realy good reason why you should be allowed to circumvent them. And then you need to document it. It might look like harassment, but it usually is something needed to keep the code maintainable.
      I speak from experience.
      The team I'm part of is currently tasked with reimplementing old legacy code. The oldest programs are 20 years old, the newest about 5. It's a hodgepodge of styles, of techniques, of proficiency in the language, and nothing is documented. At first we thought we might be able to salvage at least parts of the code, but alas, it 'grew organicaly', meaning that one functionality got expanded by plopping a wrapper around it and then doing semi-rand stuff with it. There is no spearation between data-, business- and presentation-layer. The underlying database breaks every form of normalization in every conceivable way, the primary keys are all over the place, the naming of ... anything realy ... is inconsistent and half of the stored procedures are using indices instead of names which leads to some ... intresting issues. On the other hand we have SQL-queries within what could be considered the presentation layer if you realy want to strain you imagination. It is pure chaos. No documentation. Only very, very sparse lines of comments that usually do not help at all with trying to explain what was inteded to happen in wherever they are found. But on the other hand there are methods that are thousands of lines long. And somtimes there are pages upon pages of code that had been commented out. Variable names are random and more often than not have nothing to do with whatever value is stored in them. Hell, we have an application where the buttons are called "Button1" to "ButtonXX", the methods are literally called "function_1(int a, string b, SomeClass* c)" to "function_XX(char a, int b, void* c)", the variables are really called "a, b, c, d ... aa, ab, ac ...", half of them are literally names. Like "Jake", "Thomas", or "Martin". I'm not joking. I whish I were. The source code repository is contaminated with dead files, dead data, dead cache data, random shit and a boatload of features and images no one ever uses anywhere. Checking out the full repository takes an eternety as there are 250.000 files checked in - most of which are trash. At first we thought we might be able to untangle that mess, but we pretty soon gave up on that idea and started to re-implement everything. Every now and then we still have to put on our gloves and dig through that pile of dung - when we have to apply absolutely necessary bugfixes or when we are not 100% sure on how a specific feature had been implemented. It's always something that takes way too long for what is gained from it.
      The reason it got so bad was because the ones who came before us had free reign, they were spitting out features fast and everybody did whatever the f'k he wanted. Mind you, some of them were seasoned developers, but that didn't stop them from creating that monstrosity. Now every one of them has moved on to greener pastures, and we are left with their legacy. When I came on board they had been gone for over a year and my current teamleader had put the current guidlines in place. Yeah, we are not as fast when we start a project, as we need to set up a lot of shit for later, but once everything had been set up changes can be made rapidly, bugfixes usually take half an hour at most, the code is reviewed so everyone is on the same page and the guidelines are upheld and we document our code.

    • @suokkos
      @suokkos 4 ปีที่แล้ว +1

      @@brkr78 I have used global variables with threads is easy if you can make them std::atomic. But I still would prefer not to use globals unless it is clearly the easiest solution for problem. But even in this case it is likely global variable makes more sense as static member variable because it is often related to the class implementation. But multithreaded globals are quite a lot more restricted than single threaded globals because order of execution is chaotic in many cases.

    • @kered13
      @kered13 3 ปีที่แล้ว +1

      std::any does not use RTTI. It actually uses a very clever type-erasure trick: It instantiates a function template for the type that you construct it with, then stores a function pointer to that instantiation. That function can be invoked to get information it needs about the stored type, like how to cast it back.

    • @GingerGames
      @GingerGames 3 ปีที่แล้ว

      @@kered13 That is a form of RTTI. It might not be the same as the "normal" C++ RTTI with dynamic_cast, but it is still RTTI. A "clever" "trick" but insane.

    • @kered13
      @kered13 3 ปีที่แล้ว

      @@GingerGames It works with RTTI disabled, it doesn't use the RTTI and any of it's drawbacks at all. In fact the only drawback it has is requiring a dynamic memory allocation to store the actual object. It's hardly "insane".

  • @RyanVasquez6089
    @RyanVasquez6089 4 ปีที่แล้ว +6

    This is great! As someone who writes firmware in C++, this is always great to sharpen my skills. I'm primarily an electronics engineer though....most electronics need good code to run!

    • @DFX2KX
      @DFX2KX 4 ปีที่แล้ว

      darn right they do. Part of what made Ardunio into Arduino was the firmware that made it less daunting.

  • @kevinhansson2177
    @kevinhansson2177 4 ปีที่แล้ว +39

    That epic, scary... (Also well done) intro. That lead into... the... "Oh, Hello!" XD

    • @sonnenhafen5499
      @sonnenhafen5499 4 ปีที่แล้ว +1

      spoiler alert

    • @kevinhansson2177
      @kevinhansson2177 4 ปีที่แล้ว

      @@sonnenhafen5499 oh, sorry :(

    • @sonnenhafen5499
      @sonnenhafen5499 4 ปีที่แล้ว

      @@kevinhansson2177 no problem haha, but this was really inavoidable since yours was the top comment at the time and the only thing visible as comment preview in the app xD i really needed to get this off my heart

    • @kevinhansson2177
      @kevinhansson2177 4 ปีที่แล้ว

      @@sonnenhafen5499 LMAO XD That's acctually kinda funny. Still sorry btw :)

  • @OskarAriaAttar
    @OskarAriaAttar 3 ปีที่แล้ว +4

    After years of programming, I think this video made me finally fully understand the static tag. Your explanations are really clear and concise

  • @WimpyMcWeaksauce
    @WimpyMcWeaksauce 4 ปีที่แล้ว +2

    You failed to mention that the usage of Garbage Collection can introduce an enormous amount of overhead for anything other than the smallest programs. This is one of the big reasons why most games are still primarily coded in C++ (or other languages without automatic GC.)

  • @johnjackson9767
    @johnjackson9767 4 ปีที่แล้ว +23

    I think you've got another hit series on your hands. Can totally extend this to other languages as well.

  • @giladreich810
    @giladreich810 4 ปีที่แล้ว +8

    Thanks for the video! It was fun watching and you made it really entertaining! :) I specifically liked the "goto" use-case. I personally never had the need to use it by now, but I think there is a good reason why they kept it in the language. Although many programmers tend to have really extrem negative opinions about it, behind the scene when everything is compiled and translated into assembly, there are goto/jump instructions in our program all over the place.

    • @javidx9
      @javidx9  4 ปีที่แล้ว +7

      Thats right Gilad, to the CPU & Memory, everything is global, and the JUMP is everywhere in programs... Its just us strange humans that require limitations in order to understand things XD

    • @PetrPss
      @PetrPss 4 ปีที่แล้ว

      @@javidx9 It reminds me some video about genetic algorithms. There was simulation in which 100 objects roam some field, eat "food" and attack each other to survive. And after certain time top 10 of them provide code for next generation (with slight random gene mutations). Genes of the objects were program instructions by which they "live" (32 or 64 operators, I don't remember).
      First generation gene programs of the objects were random. And after thousands of generations if you look at those programs all you can see is enirely undecipherable goto-gibberish. But this objects moved to the "food" in quite short paths, attacked other weak objects and survived till end of the simulation. Just based on their strange unreadable gene programs.
      Makes you think about how our brains work.

  • @jimmyking92
    @jimmyking92 4 ปีที่แล้ว +15

    I'm a newbie in programming (I picked C++ to learn how to code because of my masochistic tendencies) and at least I understood exactly why I shouldn't (for now) do the things you mentioned and not just "aim for best practices/build good habits". You explain everything clearly without being tiring, I understand everything even though English is my second language.

    • @javidx9
      @javidx9  4 ปีที่แล้ว +5

      Thanks and that's encouraging to hear Drop Down, Good luck with your study!

    • @eyadhisham8094
      @eyadhisham8094 4 ปีที่แล้ว

      well, i think it's very important to follow an updated tutorial on c++ because it will be extremely damaging to follow an outdated one. cause C++ has changed A LOT

    • @jimmyking92
      @jimmyking92 4 ปีที่แล้ว

      @@eyadhisham8094 I follow the lesson schedule on a site called learncpp dot com, it looks updated but I can't really tell since I'm a newbie. If you have any updated book I could look use I would be grateful, I prefer having a book in front of me while at the same time compiling code on my PC rather than following video tutorials, which most of them don't go in detail.

    • @MrCh0o
      @MrCh0o 4 ปีที่แล้ว

      ​@@jimmyking92 It's just an online reference site and I only ever learned C, but en.cppreference.com seems to be a pretty exhaustive source on various language features while also mentioning language versions that introduced them.
      It does provide a nice level of detail for everything C-related, but I can't vouch for C++ side myself. The best thing is that you can find info on just the feature you're interested in without having to sift through a load of extra info. Hope you may find it useful.

    • @jimmyking92
      @jimmyking92 4 ปีที่แล้ว

      @@MrCh0o Thanks for your insight.

  • @marcovalentinoalvarado3290
    @marcovalentinoalvarado3290 3 ปีที่แล้ว +75

    system("pause"); you should talk about exploitation some day, i really want to hear you talking about such a beautiful topic

    • @numbdigger9552
      @numbdigger9552 3 ปีที่แล้ว +1

      i use that all the time...

    •  3 ปีที่แล้ว +2

      @@numbdigger9552 Here is why you shouldn't:
      Imagine someone making a program called "pause" (which, apart from just pausing, also executes some malicious code) and put it in the same directory as your program. Or even worse, in any directory that is in the path environment variable.
      In other words, when you use system(some_program) you have no control over what some_program does, and what it does could be different on different systems.
      Obviously, when you're just writing an example program for yourself, there is no harm in it, you're executing it on a system where you have control over any program, including pause. Just keep in mind that in production code, this can create security vulnerabilities.

    • @numbdigger9552
      @numbdigger9552 3 ปีที่แล้ว

      @ well since i have no plans in publishing anything, it is not a concern

    • @SerBallister
      @SerBallister 3 ปีที่แล้ว

      @ If you had access to a machine where you could replace pause in such a way then your program is already running on a compromised system. What would stop someone replacing a shared DLL you app uses ? You wouldn't need system("pause"); for trigger for that.

  • @ghollisjr
    @ghollisjr 3 ปีที่แล้ว +10

    "This type here makes no sense at all"
    [Quake inverse square root flashbacks commence]

  • @michaelmahn4373
    @michaelmahn4373 4 ปีที่แล้ว +35

    "It's quite a modern one:" *pause video, try to guess*
    "New & Delete"
    XD

    • @cezarcatalin1406
      @cezarcatalin1406 3 ปีที่แล้ว +1

      Modern... is ancient computer history still deemed modern ?
      I mean, phenom processors aren’t considered “modern”.

  • @MatthijsvanDuin
    @MatthijsvanDuin 4 ปีที่แล้ว +11

    8:55 The double-evaluation issue aside, that macro declaration is also missing parentheses around each occurrence of a parameter in the macro body :P

    • @SirRebonack
      @SirRebonack 4 ปีที่แล้ว +2

      Yes! I thought he was going to mention it. This can really screw you over when using macros.

    • @Stoney3K
      @Stoney3K 4 ปีที่แล้ว +2

      You can do some really evil things with arithmetic operators in those macros and just completely jumble up the order of operations.

    • @xybersurfer
      @xybersurfer 3 ปีที่แล้ว

      yeah. i thought it was going to be an operator precedence issue

  • @daishi5571
    @daishi5571 4 ปีที่แล้ว +62

    10 print "This is a test"
    20 goto 10
    I believe this was the 1st program I wrote.

    • @manuell3505
      @manuell3505 4 ปีที่แล้ว

      You had to do a mkdir x and chdir x in between to reach the fat16 directory nest limit.

    • @frankstern5270
      @frankstern5270 4 ปีที่แล้ว

      Pretty sure it was gw basic

    • @abj9121
      @abj9121 3 ปีที่แล้ว

      @@frankstern5270
      To me too but it does not run though.. 😷

    • @billkeithchannel
      @billkeithchannel 3 ปีที่แล้ว +5

      HELLO WORLD!
      HELLO WORLD!
      HELLO WORLD!
      HELLO WORLD!
      HELLO WORLD!
      HELLO WORLD!
      HELLO WORLD!

    • @Nikarus2370
      @Nikarus2370 3 ปีที่แล้ว

      Honestly. Having started out using basic on one of those old "kids computers" that they had in the 90s that could run basic... I pulled a lot of aggro from my college C++ professor for using gotos here and there.

  • @benjaminlum5894
    @benjaminlum5894 4 ปีที่แล้ว +7

    this "dark side" of C++ is so unholy, that not even 2 crosses could contain it

  • @ErikTheHalibut
    @ErikTheHalibut 4 ปีที่แล้ว +6

    “system(“pause”);

  • @paklenizmaj
    @paklenizmaj 4 ปีที่แล้ว +5

    For the last 6 years I have been working exclusively in java and I always miss some "evil" from c++. One of the "evils" I miss most is multiple inheritance.
    Each tool can be both good and bad, depending on how it is used.
    For example, with an ax you can make a house or hurt someone.
    Be good and write clean code. Happy coding!

    • @azaria_phd
      @azaria_phd 2 ปีที่แล้ว

      Don't see the point in multiple inheritance when you have interfaces tbh

    • @toxicni
      @toxicni 2 ปีที่แล้ว +1

      @@azaria_phd Interface is a subset of inheritance, in inheritance you "inherit" features while in an interface you get a blueprint of what needs to be done, not how. Both are useful, it's up to the system architect to decide the best usage and implementation of the problem being solved.

  • @zerenkyne
    @zerenkyne 4 ปีที่แล้ว +4

    I'm a javascript dev, why did I watch the whole video? I don't know, but I thoroughly enjoyed it as well as learned some things about C++

  • @syfp4769
    @syfp4769 4 ปีที่แล้ว +34

    Templates would also be a good alternative to void* in that example.

    • @ccgb92
      @ccgb92 4 ปีที่แล้ว +3

      eww

    • @deepdark8192
      @deepdark8192 4 ปีที่แล้ว

      Depends. Once I did a vector that could receive any variable. For instance: the first element could be an int, and the second one a double. I'm almost sure that you can't do something like that with Templates.

    • @syfp4769
      @syfp4769 4 ปีที่แล้ว +5

      @@deepdark8192 Vectors are implemented with templates.

    • @deepdark8192
      @deepdark8192 4 ปีที่แล้ว

      @@syfp4769 I did my own vector. From scratch. I don't think you can receive different variable types in the same vector when you use the std::vector.

    • @syfp4769
      @syfp4769 4 ปีที่แล้ว +8

      @@deepdark8192 I don't know the context you wanted that for, but that sounds like it belongs in the box of forbidden C++.
      I think a cleaner solution would be defining a union of the values/types you might want, and making a std::vector of that union.

  • @josephmay1255
    @josephmay1255 3 ปีที่แล้ว

    loved this whole video but i especially love that little comment you have about system("pause"). When i took my first c++ course, our instructor did not explain at first that we would need this. This was the first language I ever used so Imagine the dejection i felt when i couldn't even get a hello world program to run properly (as far as I knew) because I didn't have system(pause)

  • @arnaudparan1419
    @arnaudparan1419 3 ปีที่แล้ว +3

    void* is clearly something which was very useful in C where you wouldn't have templates. Like for example, implementing collections without templates implies using void pointers, but that would lead you to typing the collection in the name of the variable in a comment or somewhere to have to cope with the lack of typing in your collection. It's a kind of nice and bad feature at the same time. I didn't know about any type though, that's a great functionnality!

  • @MuradBeybalaev
    @MuradBeybalaev 4 ปีที่แล้ว +16

    "I've never experienced a problem with this approach myself."
    Well then, it must be evil!

  • @chbrules
    @chbrules 4 ปีที่แล้ว +3

    I stopped programming in C++ almost a decade ago. Since I'm stuck in self quarantine until god knows when, I may as well pick up programming again and have fun. This was a great video, and it made me remember a lot of C++ I learned back in the day.

  • @lmttn
    @lmttn 4 ปีที่แล้ว +7

    Standard namespace was taught to us week one in my Intro to Programming I class. I changed majors after two semesters so I had no idea it was so contentious.

    • @azaria_phd
      @azaria_phd 2 ปีที่แล้ว

      std namespace is obviously great. The "using namespace std" statement is the evil thing.

  • @coso2
    @coso2 3 ปีที่แล้ว

    Good to see that everything I did was "wrong", but contextualized was right. I wrote a program with lot of lists of different objects managed with new and delete, a function selector with an array of function pointer void*, some GOTO for handling some loops and a global variable for addressing the same data between multiple files... and was on an MCU. No memory leaks and no race conditions on the data (that was filled by the serial port). I love how you need to make your way with all the constrains a MCU have, from program space to memory to CPU power and speed!

  • @RolandNSI
    @RolandNSI 4 ปีที่แล้ว +2

    I had to switch programming language from assembly / c ( with some c++ every now and then ) to c#.... and .net
    I really miss the "dark side" that made things so easy and straightforward !

  • @beskamir5977
    @beskamir5977 4 ปีที่แล้ว +6

    These "don't" videos are awesome. I learned not to use "using namespace std" the hard way when I was first learning C++ in an intro to computer graphics course. Aside from transformation functions from the glm library clashing with my own functions (ie rotate(), scale(), etc), I think I also had an issue where I couldn't make a mathematical vector type cause it conflicted with std::vector. All in all, fun times!

    • @alphaforce6998
      @alphaforce6998 4 ปีที่แล้ว

      So you blame the namespace feature instead of your inability to do something simple like prefixing your with "myfunc_" or the like to avoid collisions? Real men of genius here... smh

    • @groszak1
      @groszak1 3 ปีที่แล้ว +1

      So you couldn't make your own vector because it conflicted with the standard vector

    • @beskamir5977
      @beskamir5977 3 ปีที่แล้ว

      @@alphaforce6998 it was my first time using c++... I was a noob. Plus I would have prefered a normal name instead of myVector. I've never been fond of the my naming convention.

    • @alphaforce6998
      @alphaforce6998 3 ปีที่แล้ว

      @@beskamir5977 It was just an example. You can prefix the namespace however you want to. When I use namespaces I treat it like a subdirectory and name the functions/code accordingly... and in general a depth of 1 has been more than sufficient for me..

  • @seankayll9017
    @seankayll9017 4 ปีที่แล้ว +5

    Very useful vid, thanks. That "mostly true" macro is priceless.

  • @metroid031993
    @metroid031993 4 ปีที่แล้ว +5

    javidx9: "I hope this hasn't given you any nightmares"
    also javidx9: *the intro*

  • @kalebbruwer
    @kalebbruwer 3 ปีที่แล้ว +22

    void* pointers are great for dealing with unknown data, like when you need to write data to TCP sockets.

    • @thetinyurlguy
      @thetinyurlguy 3 ปีที่แล้ว

      I think that is what my MUD used them for since that was all TCP based.

    • @noop9k
      @noop9k 3 ปีที่แล้ว +8

      void* actually provides some safety because it is explicitly a pointer to unknown type. You can’t increment/decrement/subtract/add/index/dereference until you cast it to another type.

    • @azaria_phd
      @azaria_phd 2 ปีที่แล้ว

      Indeed. He himself gives an example with the function he wrote. A function that writes bytes to a file, it only cares where the bytes start and how many of them there are. The function will never interact with the data so it doesn't need to ask for its type.

    • @abstractspaces8186
      @abstractspaces8186 2 ปีที่แล้ว

      @@azaria_phd Although there is danger in requiring the caller to pass in the size correctly and trust they don't cause an overflow. If you knew the type you'd also inherently know the size, I'd definitely use a template in that example.

    • @jbird4478
      @jbird4478 2 ปีที่แล้ว

      @@abstractspaces8186 Using a template would result in duplicate code for every type you use it for. What you'd really want to do is use both: a template that does nothing but call the function that takes a void* and pass the correct size.

  • @utf-238e8
    @utf-238e8 4 ปีที่แล้ว +30

    That's one hell of an intro

  • @laureven
    @laureven 4 ปีที่แล้ว +9

    I had nothing left to watch except makeup tutorials and boom ...Your video to the rescue :) ..Thank you, Thank you, Thank you :)

    • @javidx9
      @javidx9  4 ปีที่แล้ว +1

      lol you're welcome Marcin!

  • @Kenjuudo
    @Kenjuudo 3 ปีที่แล้ว +2

    Senior software engineer with 34+ years of experience here. Just wanted to say: Quality video! Great for beginner and intermediate programmers. (And not half-bad for experts either!)
    Funny! Underrated! Clean! Knuth-like!
    Earned yourself a sub, a like and a ding-dong. More please!

  • @MlleLyla
    @MlleLyla 3 ปีที่แล้ว +1

    ty, I've heard some references to these "EVIL" things before, but it's the first time I see it well explained WHY
    Most people were saying: "don't do that" because of habit more than anything else

  • @BalancedEarth
    @BalancedEarth 3 ปีที่แล้ว +2

    Very cheeky to see this in my recommended a few days before Halloween. Very cool video though and has so much good production for a video any old youtuber would have just made a run of the mill top ten list with minimal detail. I approve!

  • @daddydangerous20
    @daddydangerous20 4 ปีที่แล้ว +4

    "Would you like to look inside?" Me: "Oh fuck yeah" ... after the video.. "aah I had thought I had cast away these demons when I switched to C#.. now they have reared their head to haunt me again"

  • @kleinebre
    @kleinebre 3 ปีที่แล้ว +8

    "Join me as we visit the C++ dark side" - Forgot to bring sunglasses against blinding light

  • @emonymph6911
    @emonymph6911 3 ปีที่แล้ว +3

    HAHAHA that intro... forbidden code from the 1980s... how terrifying! You earned a sub for scaring the shit out of me.

  • @souilluminat9280
    @souilluminat9280 4 ปีที่แล้ว +1

    I love void* if you work with data you want to pass to different types of objects or structs, you can just make a function that accepts void* and you make it very flexible.

    • @igorthelight
      @igorthelight 4 ปีที่แล้ว

      Or a template.
      Also has to be used with caution :-)

  • @unknown6656
    @unknown6656 3 ปีที่แล้ว +2

    One of the most evil things is: 5[my_pointer] = L"Hello, World!".
    Yeah, that's right. You can swap the pointer with the index. It will be compiled as *(5 + my_pointer) = L"Hello, World" either way.

    • @thomaspearson3698
      @thomaspearson3698 3 ปีที่แล้ว

      Oh no I completely forgot about this...
      on a side note my_pointer, if it is the array itself you declared, isn't technically a pointer, so you can't add to it it just gets switched around at compile. But pretty scary stuff!

    • @unknown6656
      @unknown6656 3 ปีที่แล้ว

      And even more evil is the combination of the example above with digraphs and trigraphs (en.wikipedia.org/wiki/Digraphs_and_trigraphs)
      my_pointer[5] += ~42; is hence equivalent to:
      5 += ??-42;

  • @gayusschwulius8490
    @gayusschwulius8490 3 ปีที่แล้ว +6

    I remember when my first C++ programs were full of goto's, because I was used to GWBASIC. Ah, that was back in highschool.

    • @lucasgasparino6141
      @lucasgasparino6141 3 ปีที่แล้ว

      Fuck I've started with Pascal... That damned blue IDE still haunts my dreams lol now I mostly code in Fortran xD

    • @gayusschwulius8490
      @gayusschwulius8490 3 ปีที่แล้ว +1

      @@lucasgasparino6141 The pascal ide was really cool for its time, though. I still use a white-on-blue-theme while coding in VIM nowadays :D

  • @KillerMZE
    @KillerMZE 4 ปีที่แล้ว +6

    Over a decade of programming C++, I can say that in my experience, using global variables and goto where needed only makes the program easier to control and more efficient. Also using new and delete manually, you can make sure that all memory requirements are set up at start time, and no new memory is allocated during the actual run. This has a marked effect on performance of real-time software.

    • @smileifyoupoopie9926
      @smileifyoupoopie9926 4 ปีที่แล้ว

      but what about smart pointers? the main purpose of smart pointers is to eliminate or significantly reduce chance of memory leak and as you should know, it is very easy to use wrong `delete`. i can actually imagine usage of goto as flow control but imo it crashes down readability. Why global variables? are there situations where global variables actually are necessary and are really worth to use?

    • @KillerMZE
      @KillerMZE 4 ปีที่แล้ว +1

      @@smileifyoupoopie9926 Like everything in programming, there are trade-offs. If you want performance, you will need to give something up. In my opinion, smart pointers make your program less readable, and shared pointers also make performance worse with the added reference counting. Also, you won't be leaking memory if you only allocate on start up of your program. Worst case you forget to delete something, but the operating system will take care of that when you end execution.

    • @absurdengineering
      @absurdengineering 3 ปีที่แล้ว

      @@KillerMZE There’s no single smart pointer type, so saying that “smart counters do reference counting” is not generally correct. In most cases you’re supposed to use std::unique_ptr wherever you had a new. This has no overhead and you type less since there’s no explicit delete: scope controls the lifetime, although of course you can override it as needed. As for having preallocated stuff: a function is supposed to encapsulate that. If you need a “global”, it should usually live within main, and be passed around as a context object. That way you won’t run into initialization order fiasco, and it’s only a non-issue in small projects. Once you’re past 50kLOC, globals magically turn into a nightmare.

    • @KillerMZE
      @KillerMZE 3 ปีที่แล้ว

      @@absurdengineering you are replying to something I never said. Maybe actually read what I wrote

    • @jbird4478
      @jbird4478 2 ปีที่แล้ว

      @@absurdengineering std::unique_ptr and std::make_unique are one of C++'s unique ways of being the most unreadable language in existence in an attempt to protect coders from their own stupidity.

  • @backseatgaming2145
    @backseatgaming2145 3 ปีที่แล้ว +9

    "Not many people have a stomach like you"
    **casually eating**

  • @sumpferkraut
    @sumpferkraut 4 ปีที่แล้ว +1

    Upvote for presenting good examples of goto. So many people only know that "it makes spaghetti code" and have no understanding of how neat it is.

  • @billkeithchannel
    @billkeithchannel 3 ปีที่แล้ว +1

    javidx9: ...80's processors. Nobody is going to be interested in them.
    Nostalgia Nerd, The 8-Bit Guy, Techmoan, 8-Bit Show and Tell: Hold our beers.

  • @DoorThief
    @DoorThief 4 ปีที่แล้ว +16

    Ahh GOTO. I remember that back in my Windows Batch scripting days.

    • @Those2menoverthere
      @Those2menoverthere 4 ปีที่แล้ว

      Yep, (6 years ago) in highschool, what a time for me. :) When you had nothing better to do in your shitty ass computer-based classes. Bypassing all their stupid registry restrictions and such. Batch scripts were the way to go.

    • @lynnlo
      @lynnlo 4 ปีที่แล้ว +1

      @@Those2menoverthere
      First you're dabbling in VBS then you're doing full on batch.

    • @tech6hutch
      @tech6hutch 3 ปีที่แล้ว

      God, me too. I cringe at the thought of the spaghetti my code must have been.

  • @TheAgamemnon911
    @TheAgamemnon911 4 ปีที่แล้ว +7

    Before declaring a global variable, please make sure your pentagram is properly serialized, the black candles are registered with the fire and lighting manager class, you are invoking your chants in the correct order and your dagger reference is pointed at an instance of an appropriately sharp object.

    • @MrDoboz
      @MrDoboz 2 ปีที่แล้ว

      # object?

  • @davep7176
    @davep7176 4 ปีที่แล้ว +4

    for a few years at least I have been learning how to code. Was always just told Global Variables = evil and Singleton = evil without any real explanations for why. Excellent video

    • @sawomirkrynicki4492
      @sawomirkrynicki4492 4 ปีที่แล้ว

      nic takiego jak pokazano w tym filmie mi się nie dzieje w Eclipse. Używam MinGw 8.1.0 i hermetyzacja działa.

    • @absurdengineering
      @absurdengineering 3 ปีที่แล้ว +1

      The explanation is trivial: global variables look just like all other variables. Now imagine you had a nuclear launch switch next to the light switch in your bathroom. Flip one, and you light up the room you’re in. Flip another, you light up an entire city. Not only is it easy for you to mistake the two and inadvertently mess up the entire city when all you wanted is a midnight piss, but also good luck to anyone who will want to figure out what really happened when all they got is a crash dump.
      Global variables make it all too easy to mess up and all too hard to figure out who messed up and which house was the damn switch in this time.

    • @davep7176
      @davep7176 ปีที่แล้ว

      @@absurdengineering You can just name the global nuke launch switch accordingly. So that people will know what it is

  • @cole-nyc
    @cole-nyc 2 ปีที่แล้ว

    A classic example for namespace clashes on linux is when you try to include and . Both headers contain a function named "bind" and if you use "using namespace std;" you won't be able to compile the program.

  • @andhemills
    @andhemills 3 ปีที่แล้ว

    You blew my mind at the 31:00 mark, editing multiple lines simultaneously! (I don't see a practical use for this in general, but it was impressive nonetheless)

    • @javidx9
      @javidx9  3 ปีที่แล้ว

      Heh, it's surprising how handy that is...

  • @thomasstambaugh5181
    @thomasstambaugh5181 4 ปีที่แล้ว +21

    "Java: Combines the elegant simplicity of C++ with the blazing performance of Smalltalk"

    • @adityabalsane5260
      @adityabalsane5260 4 ปีที่แล้ว +5

      Ever heard of C#?

    • @CottidaeSEA
      @CottidaeSEA 4 ปีที่แล้ว +7

      Java is a lot simpler than C++ though. In regards to performance... yeah, it's not amazing.

    • @sociocritical
      @sociocritical 4 ปีที่แล้ว +4

      Mastering Java is way easier than C++ since you can do basically anything you can do in Java similar in C++, but C++ is a lot more powerful and has a lot more landmines build in.
      In terms of performance a well written C++ program will outperform a Java program but dont underestimate the JVM. It is really fast nowadays and does some amazing runtime optimizations.

    • @Pharoah2
      @Pharoah2 4 ปีที่แล้ว +6

      Lucas C. I guess im the only person who finds java nauseating while enjoying c++. I guess its because c++ is the language im most familiar with and i hadnt looked at java until i had already mastered c++

    • @sociocritical
      @sociocritical 4 ปีที่แล้ว +2

      @@Pharoah2 That Java is easier to master doesn't imply that you have to like it more. I myself also have more fun with low level languages like C++ or Rust, because they give you more control.

  • @code-dredd
    @code-dredd 4 ปีที่แล้ว +44

    *Another Evil in **_Any_** Language, not only C++:* Hungarian notation ._.

    • @shukterhousejive
      @shukterhousejive 4 ปีที่แล้ว +6

      char[] str_comment = "What's wrong with Hungarian Notation?";

    • @Kirides
      @Kirides 4 ปีที่แล้ว

      @@shukterhousejive llOk = false;

    • @code-dredd
      @code-dredd 4 ปีที่แล้ว +10

      @@shukterhousejive int gsf_refactored = 5; // I'm no longer a global static float, but a local non-static integer. I mislead everyone.

    • @MrCh0o
      @MrCh0o 4 ปีที่แล้ว

      I see. That explains why all these variables were so weirdly named, huh...

    • @code-dredd
      @code-dredd 4 ปีที่แล้ว +14

      @@shukterhousejive
      *> char[] str_comment = "What's wrong with Hungarian Notation?";*
      Refactoring leads to misleading code. We can pick apart your example a bit, too.
      char[] str_comment = ...;
      This is not _really_ a string, such as std::string, it's really a pointer to chars, i.e. char*, so it should've been named cp_comment, for "char pointer comment".
      But say the type then gets refactored to std::string? Or what if you have a float then refactored to an int or viceversa?
      Let the language abstractions "speak for themselves" instead of trying to encode type data into the variable's name, IMHO.

  • @joe7992
    @joe7992 4 ปีที่แล้ว +7

    “Join me on the dark side”
    *Gets blinded by light*

  • @evannibbe9375
    @evannibbe9375 3 ปีที่แล้ว +1

    Global variables are basically required in order to use signal interrupts, since variables with local scope cannot be passed to the interrupt handlers.

    • @javidx9
      @javidx9  3 ปีที่แล้ว

      Well at that level Evan, all variables are global anyway 😄

  • @moonhowler667
    @moonhowler667 16 วันที่ผ่านมา

    There's actually something really clever you can do with goto. Goto is the only thing that can jump from the body of an if/switch, into the body of another if/switch. It's rare to need this, but sometimes you'll find a situation where rarely you can skip a bunch of steps between two if/switch statements but mostly you need to run everything in between. Think something like a game that generates a new room every time you leave an old one, but also remembers the old rooms so you can go backwards if you want.

  • @Mal_
    @Mal_ 4 ปีที่แล้ว +19

    The f.write(...) line when using std::any is completely broken. I know it's not the intended message here to use std::any for io, but might still be worth noting that.