Forbidden C++

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 2,6 тис.

  • @javidx9
    @javidx9  4 роки тому +2024

    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 роки тому +3583

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

  • @Digidan5
    @Digidan5 4 роки тому +1022

    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 4 роки тому +1

      😂

  • @usmanahmed3035
    @usmanahmed3035 4 роки тому +1014

    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

  • @codeman99-dev
    @codeman99-dev 4 роки тому +1045

    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 4 роки тому +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 4 роки тому +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 4 роки тому +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 4 роки тому +59

      Oh, recursive functions? *Pulls out pepper spray*

    • @jeffspaulding9834
      @jeffspaulding9834 4 роки тому +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 3 роки тому +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)

  • @subcivil-youtubechannel7283
    @subcivil-youtubechannel7283 4 роки тому +2346

    #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 роки тому +115

      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

  • @veda-powered
    @veda-powered 4 роки тому +4926

    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 роки тому +118

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

  • @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 4 роки тому

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

  • @BerkaySoyluoglu
    @BerkaySoyluoglu 4 роки тому +217

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

    • @johnhajdu4276
      @johnhajdu4276 Місяць тому +1

      Global Variables are execution allocated spaces which makes the exe file bigger. The other thing is, that nowdays we have multicore processors where can happen that a global variable is accessed the same time, (the problem if it is written)
      because we do not know which or how man cores is/are going to execute the code with the same variable in the same time. Every change of the global variable makes the cache of the other core invalid. So it is recommended to use the the actual value of the global value by passing it to the subprogram. (And not using it directly)

  • @chrisbartlett9930
    @chrisbartlett9930 4 роки тому +1124

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

  • @thepuzzlemaker2159
    @thepuzzlemaker2159 4 роки тому +754

    "...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 4 роки тому

      @@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 4 роки тому

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

    • @StepDub
      @StepDub 4 роки тому +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 4 роки тому

      felt that...

  • @jimfcarroll
    @jimfcarroll 4 роки тому +1791

    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

  • @addvert_br0009
    @addvert_br0009 4 роки тому +587

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

  • @OnboardG1
    @OnboardG1 4 роки тому +327

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

  • @Eegal-Ayed
    @Eegal-Ayed 4 роки тому +428

    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 3 роки тому +4

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

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

  • @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 4 роки тому +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. :)

  • @GrandHighGamer
    @GrandHighGamer 4 роки тому +104

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

  • @easyaspi31415
    @easyaspi31415 4 роки тому +531

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

    • @sodiboo
      @sodiboo 4 роки тому +20

      just start from scratch lmao

    • @easyaspi31415
      @easyaspi31415 4 роки тому +104

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

    • @easyaspi31415
      @easyaspi31415 4 роки тому +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 4 роки тому +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 4 роки тому +13

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

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

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

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

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

  • @Gastell0
    @Gastell0 4 роки тому +67

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

    • @petergamache5368
      @petergamache5368 4 роки тому +17

      You're thinking of Java.

    • @Gastell0
      @Gastell0 4 роки тому +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!

    • @kimgkomg
      @kimgkomg 22 дні тому +1

      If you're not using all of your memory you're wasting system resources

  • @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 4 роки тому

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

  • @mohammade.8770
    @mohammade.8770 4 роки тому +133

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

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

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

  • @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 4 роки тому

      @@ccgb92 troll

    • @ccgb92
      @ccgb92 4 роки тому

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

    • @mvisperas
      @mvisperas 4 роки тому

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

  • @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 4 роки тому +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 4 роки тому +2

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

  • @garthor
    @garthor 4 роки тому +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

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

  • @MrHatoi
    @MrHatoi 4 роки тому +27

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

  • @pako_powr
    @pako_powr 4 роки тому +183

    The Halloween special we never knew we wanted..

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

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

  • @OskarAriaAttar
    @OskarAriaAttar 4 роки тому +4

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

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

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

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

    • @mjdegans
      @mjdegans 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 4 роки тому

      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.

  • @johnjackson9767
    @johnjackson9767 4 роки тому +23

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

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

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

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

  • @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 4 роки тому

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

    • @billkeithchannel
      @billkeithchannel 4 роки тому +5

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

    • @Nikarus2370
      @Nikarus2370 4 роки тому

      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.

  • @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 4 роки тому +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 4 роки тому

      @@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 4 роки тому

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

  • @marcovalentinoalvarado3290
    @marcovalentinoalvarado3290 4 роки тому +74

    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.

  • @mrbrown6421
    @mrbrown6421 4 роки тому +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!

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

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

  • @michaelmahn4373
    @michaelmahn4373 4 роки тому +35

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

    • @cezarcatalin1406
      @cezarcatalin1406 4 роки тому +1

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

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

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

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

  • @whynotanyting
    @whynotanyting 4 роки тому +39

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

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

  • @iMCOCOarmy
    @iMCOCOarmy 4 роки тому +32

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

  • @benjaminlum5894
    @benjaminlum5894 4 роки тому +7

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

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

  • @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 4 роки тому

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

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

  • @ghollisjr
    @ghollisjr 3 роки тому +10

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

  • @utf-238e8
    @utf-238e8 4 роки тому +30

    That's one hell of an intro

  • @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 4 роки тому +1

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

    • @beskamir5977
      @beskamir5977 4 роки тому

      @@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 4 роки тому

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

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

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

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

  • @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 4 роки тому

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

  • @MuradBeybalaev
    @MuradBeybalaev 4 роки тому +16

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

  • @cole-nyc
    @cole-nyc 3 роки тому

    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.

  • @BalancedEarth
    @BalancedEarth 4 роки тому +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!

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

  • @Terszel
    @Terszel 4 роки тому +3

    Void* is perfect if a void* from one object/function is known when used by another object/function and you know exactly what type of object it may be so you can cast it to what it needs to be, while at the same time storing as a "generic" pointer.
    Some cases interfaces and generic templates cannot help, void* is extremely powerful.

  • @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 4 роки тому

      @@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 4 роки тому

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

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

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

  • @metroid031993
    @metroid031993 4 роки тому +5

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

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

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

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

  • @unknown6656
    @unknown6656 4 роки тому +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 4 роки тому

      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 4 роки тому

      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;

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

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

  • @kleinebre
    @kleinebre 4 роки тому +8

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

  • @Khantia
    @Khantia 4 роки тому +1

    1:04 The dark side of C++ was surprisingly bright!
    However, this video was extremely helpful for someone rather new to the language (and programming in general). I didn't know about the "any" cast, as well as the macros (#define). And I finally understood what namespaces are and how/why they're used. I haven't had the need to use global variables yet (outside my "main.cpp"), as my projects are still quite small, and are more on the "experimentation" stage, but I'm certain that it will be helpful in the future.
    I've actually been using the void* to research how variables are saved into memory, by reading byte by byte the address of the variable through its size. However, this video gave me insight on how to do what I'm trying to achieve (and the reason I've been trying to figure out how are different variable types saved in memory)

  • @gameprogramme
    @gameprogramme 3 роки тому

    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.

  • @joe7992
    @joe7992 4 роки тому +7

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

  • @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 4 роки тому +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

  • @emonymph6911
    @emonymph6911 4 роки тому +3

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

  • @RPG_Hacker
    @RPG_Hacker 3 роки тому

    I've once worked on the remaster of a game that had a "using namespace" in hundreds of header files, and one of the classes in that namespace was simply called "String". I don't think I have to mention how much fun we had once we started porting that game to the Xbox One, which also has its own class called "String". Fixing that name conflict was such a pain in the arse.

  • @coso2
    @coso2 4 роки тому

    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!

  • @amortalbeing
    @amortalbeing 4 роки тому +3

    Great talk. I enjoyed every seconds of it :)
    great great job :)
    by the way you forgot to point out that void* is also very handy when it comes to creating wrappers in C that can then be used in other languages (creating DLLs to be used by other languages for example)!

  • @memespdf
    @memespdf 3 роки тому +8

    0:00 Intro sketch
    2:00 Global Variables
    8:00 Macros
    12:28 Goto
    16:14 Void*
    22:04 Using namespace std
    27:12 New & delete
    31:52 Final thoughts
    [Feel free to paste this into the video description, this will allow UA-cam to automatically generate chapters for the video]

    • @memespdf
      @memespdf 3 роки тому

      oops just realized this video is a year old.. I saw the covid comment and the upload date in march and assumed it was from this march. but alas this pandemic has been going on for longer than I realized.

  • @ErikTheHalibut
    @ErikTheHalibut 4 роки тому +6

    “system(“pause”);

  • @darriusbeleiu1377
    @darriusbeleiu1377 3 роки тому +1

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

  • @mingusog7036
    @mingusog7036 4 роки тому

    My Comp Sci professor taught us to use using namespace std, even with multiple files and headers, and never told us about the determent's. I had always heard it was bad practice but never understood why until this video. Very useful information

  • @swrdghcnqstdr
    @swrdghcnqstdr 4 роки тому +124

    as a low-level (mostly c) programmer, things like goto and void* are very useful and calling them forbidden and/or terrible is irritating

    • @javidx9
      @javidx9  4 роки тому +98

      Completely agree! Just dont let the internet hear us say that 😂

    • @ishdx9374
      @ishdx9374 3 роки тому +22

      Go-to is good for breaking out of nested loops

    • @JuliusCesar2781
      @JuliusCesar2781 3 роки тому +12

      I'd see no problems using goto as long you do it the right way. But there are thousands of ways to doing things.

    • @jfbeam
      @jfbeam 3 роки тому +23

      For something as rigidly structured as C++, one should make every effort to avoid using GOTO. (the biggest Evil(tm) with GOTO is how it can break scoping rules.)

    • @nextlifeonearth
      @nextlifeonearth 3 роки тому +5

      @@ishdx9374 Also nested switches.