Forbidden C++

Поделиться
HTML-код
  • Опубликовано: 20 мар 2020
  • 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
    RUclips: / javidx9
    / javidx9extra
    Discord: / discord
    Twitter: / javidx9
    Twitch: / javidx9
    GitHub: www.github.com/onelonecoder
    Homepage: www.onelonecoder.com
  • НаукаНаука

Комментарии • 2,6 тыс.

  • @javidx9
    @javidx9  4 года назад +2019

    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 года назад +37

      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...

  • @veda-powered
    @veda-powered 4 года назад +4878

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

    • @alphaforce6998
      @alphaforce6998 4 года назад +182

      That was his basement.

    • @Kirides
      @Kirides 4 года назад +178

      @@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 года назад +116

      @@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.

  • @mr649001
    @mr649001 4 года назад +3547

    "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 года назад +45

      @@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 …..

  • @codeman99-dev
    @codeman99-dev 3 года назад +1019

    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 года назад +151

      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 года назад +50

      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 года назад +56

      Oh, recursive functions? *Pulls out pepper spray*

    • @jeffspaulding9834
      @jeffspaulding9834 3 года назад +17

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

  • @Archimagus
    @Archimagus 3 года назад +297

    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 года назад +19

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

    • @typowyjnn2300
      @typowyjnn2300 3 года назад +7

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

    • @tappineapple3381
      @tappineapple3381 3 года назад +3

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

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 2 года назад +3

      @@typowyjnn2300 Embedded?

    • @nikkiofthevalley
      @nikkiofthevalley Год назад +5

      @@typowyjnn2300 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)

  • @Digidan5
    @Digidan5 4 года назад +1009

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

    • @ekremdincel1505
      @ekremdincel1505 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 3 года назад +3

      I love this comment so damn much because i relate

    • @ArIyan_yt
      @ArIyan_yt 3 года назад +1

      😂

  • @usmanahmed3035
    @usmanahmed3035 4 года назад +1012

    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

  • @BerkaySoyluoglu
    @BerkaySoyluoglu 3 года назад +215

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

  • @chrisbartlett9930
    @chrisbartlett9930 4 года назад +1115

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

  • @thepuzzlemaker2159
    @thepuzzlemaker2159 4 года назад +746

    "...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...

  • @subcivil-youtubechannel7283
    @subcivil-youtubechannel7283 4 года назад +2327

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

    • @orocimarosay1447
      @orocimarosay1447 4 года назад +102

      Quantic physics ;)

    • @ke5uq1we8h
      @ke5uq1we8h 4 года назад +183

      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 года назад +112

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

    • @whythosenames
      @whythosenames 4 года назад +50

      Володимир Герасимчук 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

  • @OnboardG1
    @OnboardG1 3 года назад +322

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

  • @BG-qv5xj
    @BG-qv5xj 3 года назад +419

    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 года назад

      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_

  • @SelyHaudy
    @SelyHaudy 4 года назад +404

    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 3 года назад +15

      its all made in light mode IDE

  • @renhoeknl
    @renhoeknl 4 года назад +549

    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 3 года назад

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

  • @easyaspi31415
    @easyaspi31415 3 года назад +525

    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 года назад +101

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

    • @easyaspi31415
      @easyaspi31415 3 года назад +76

      @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

  • @NXTangl
    @NXTangl 3 года назад +143

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

    • @billgatest7563
      @billgatest7563 3 года назад +32

      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

  • @jimfcarroll
    @jimfcarroll 4 года назад +1784

    Best macro ever:
    #define private public

    • @brilletjuh2
      @brilletjuh2 4 года назад +275

      even better: #define public private

    • @brilletjuh2
      @brilletjuh2 4 года назад +64

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

    • @rauldragu9447
      @rauldragu9447 4 года назад +142

      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

  • @addvert_br0009
    @addvert_br0009 4 года назад +585

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

    • @javidx9
      @javidx9  4 года назад +161

      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

  • @Gastell0
    @Gastell0 3 года назад +65

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

    • @petergamache5368
      @petergamache5368 3 года назад +16

      You're thinking of Java.

    • @Gastell0
      @Gastell0 3 года назад +14

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

    • @patrickgono6043
      @patrickgono6043 3 года назад +19

      100% memory speedrun

    • @Gastell0
      @Gastell0 3 года назад +2

      @@patrickgono6043 Now that sounds like a worthy challenge!

  • @BernardBernouli
    @BernardBernouli 3 года назад +43

    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 Год назад

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

  • @GrandHighGamer
    @GrandHighGamer 4 года назад +102

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

  • @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. :)

  • @garthor
    @garthor 3 года назад +31

    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

  • @C_Corpze
    @C_Corpze 3 года назад +30

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

  • @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

  • @trolleyproblem4318
    @trolleyproblem4318 4 года назад +137

    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 @.

  • @MrHatoi
    @MrHatoi 4 года назад +27

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

  • @iMCOCOarmy
    @iMCOCOarmy 4 года назад +31

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

  • @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

  • @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

  • @gameprogramme
    @gameprogramme 3 года назад +4

    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.

  • @z0mbiebanana9891
    @z0mbiebanana9891 4 года назад +136

    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 RUclips 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.

  • @pako_powr
    @pako_powr 4 года назад +183

    The Halloween special we never knew we wanted..

  • @andreyzolotykh9005
    @andreyzolotykh9005 10 месяцев назад +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!

  • @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

  • @erykaemilien77
    @erykaemilien77 4 года назад +115

    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

  • @MichaelRichardson-bw5xh
    @MichaelRichardson-bw5xh 4 года назад +130

    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.

  • @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.

  • @brianhourigan
    @brianhourigan 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!

  • @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 года назад

      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 года назад +2

      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.

  • @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.

  • @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.

  • @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.

  • @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"

  • @whynotanyting
    @whynotanyting 4 года назад +39

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

  • @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!

  • @benjaminlum5894
    @benjaminlum5894 3 года назад +7

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

  • @nerdudi5745
    @nerdudi5745 4 года назад +15

    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.

  • @utf-238e8
    @utf-238e8 4 года назад +31

    That's one hell of an intro

  • @KG4JYS
    @KG4JYS 3 года назад

    Thank you for the suggestions. I will try to use these techniques in all my code going forward!

  • @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!

  • @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

  • @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”.

  • @JG-og3qy
    @JG-og3qy 3 года назад +1

    Great work, Javid! Nice clear explanations, concise, well-spoken.

  • @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 !

  • @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.

  • @kevinhansson2177
    @kevinhansson2177 4 года назад +40

    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 :)

  • @ghollisjr
    @ghollisjr 3 года назад +10

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

  • @simaesthesia
    @simaesthesia 4 года назад +1

    Absolutely marvellous! I love the humorous approach to what are very real issues.

  • @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.

  • @johnjackson9767
    @johnjackson9767 4 года назад +23

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

  • @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.

  • @darriusbeleiu1377
    @darriusbeleiu1377 3 года назад +1

    The voiceover at the beginning of this was downright impressive!!

  • @natevb9901
    @natevb9901 4 года назад +2

    I got a _"Tales from the Crypt"_ jive there at the end and at times throughout.
    This could totally become a new series worth accumulating some "horror stories" for sharing over time.
    As always, thanks for sharing!

  • @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.

  • @felixmerz6229
    @felixmerz6229 3 года назад

    Favourite programming video right here, thanks a lot. Also got me in the Halloween mood that is quickly approaching!

  • @joe7992
    @joe7992 4 года назад +7

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

  • @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.

  • @GingerGames
    @GingerGames 4 года назад +16

    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".

  • @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!

  • @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)

  • @mokopa
    @mokopa 4 года назад +3

    It's stuff like this where Stroustrup's personality actually shines through. His character is somewhat woven into the language, and through this, he will live as long as C++ and its descendants are around.

  • @MuradBeybalaev
    @MuradBeybalaev 4 года назад +16

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

  • @doublegdog
    @doublegdog 4 года назад

    Love your videos man! I think you are the best youtube programming channel. You actually provide useful information and tell it how it is.

  • @Silver_Knee
    @Silver_Knee 4 года назад

    For the goto-netsted-loop example, I would add, that you can solve this use-case in a high-level language by creating a function and returning from inside the 3 loops.
    It may require more overhead passing the neccessary variables to the loop, but it makes it clear what is needed and you also typically have already a name for it like "findThingInArray" which is already a pretty good indicator for a possible function

  • @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 года назад +14

    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 года назад +4

      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.

  • @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.

  • @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.

  • @seankayll9017
    @seankayll9017 4 года назад +5

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

  • @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.

  • @koalawombatkangaroo
    @koalawombatkangaroo 3 года назад

    This looked like sooooo much fun to make! I'm getting some "The Mighty Boosh" vibes from this too!

  • @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

  • @metroid031993
    @metroid031993 4 года назад +5

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

  • @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.

  • @backseatgaming2145
    @backseatgaming2145 3 года назад +9

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

  • @coolbrotherf127
    @coolbrotherf127 3 года назад

    This is really cool, as a student, I've been taught a lot of the older ways of programming by older professors. I didn't even know of the newer ways of handling memory allocation. I've just been using the new and delete.

  • @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.

  • @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..

  • @derekmont
    @derekmont 3 года назад

    This is just such good content. You have truly changed my way of looking at progamming. Thank you.

  • @ErikTheHalibut
    @ErikTheHalibut 4 года назад +6

    “system(“pause”);

  • @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.

  • @edwinmartens509
    @edwinmartens509 4 года назад +1

    Working @ home I had a good laugh at this, then shared it with my collegues... I bet some can learn something from it :D

  • @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

  • @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++

  • @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.

  • @ale-lx9gp
    @ale-lx9gp 4 года назад

    This is an incredible video! Thank you so much!

  • @xemuth1643
    @xemuth1643 4 года назад +1

    Thanks for this video, it was very interresting !