Why I don't "using namespace std"

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ม.ค. 2025

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

  • @TheCherno
    @TheCherno  6 ปีที่แล้ว +402

    Finally got around to answering this question, hope you guys enjoyed the video!
    What's the biggest issue you've had because someone stuck a using namespace somewhere?

    • @MiaWinter98
      @MiaWinter98 6 ปีที่แล้ว +22

      First time i learned c++ the tutorial i watched the guy "using namespace std" and other namespaces, so i assumed it is ok. Couple of hours later, i actually added something like that in a header file, didnt mind. A bit later, everything broke. Needles to say i stopped doing this.

    • @thepdg5160
      @thepdg5160 6 ปีที่แล้ว +5

      Tron I restrained from using it in a global scope, but I still use it in a local scope, because I don't see problems with that personally. But everyone has their own religion here.

    • @AJMansfield1
      @AJMansfield1 6 ปีที่แล้ว +18

      In my algorithms class, the test runner that was supplied to the class had `using namespace std;` in the global scope in one of its header files, and as a result when I did the quicksort assignment I discovered minutes before the assignment was due that I'd actually been calling std::sort for everything when I'd been testing it earlier, rather than the function I'd written. Fortunately my sort function worked perfectly once I fixed that but it really could've been bad.

    • @ssjim826
      @ssjim826 6 ปีที่แล้ว +8

      Im glad someone is finally addressing this. I've been helping people program in C++ for the last 5-6 years , and the one thing i notice is people always tend to use namespace std. There arent many tutorials that actually tell people not to use it because it could cause a lot of bloat. Ive actually was working with someone on a game, and it literally screwed with my custom vector class as well as custom map class.

    • @connorhorman
      @connorhorman 6 ปีที่แล้ว

      I write a C++ program and broke every. Worst part is that I couldn't trace the issue at all and had to actually look on StackOverflow to realize that it was because of using namespace std.

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

    When he says "never ever, EVER, use namespace in a header file" you can see the culmination of several hours of debugging agony in his eyes.

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

      Thats solid advice. I can feel it.

    • @AviPars
      @AviPars 2 ปีที่แล้ว +18

      My college does all the time lol

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

      @@AviPars ur college should be in hell rn tbh

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

      Zooming into those eyes and flashing through a thousand memories from 2am would've been a masterful edit for sure.

  • @paul70079
    @paul70079 6 ปีที่แล้ว +2047

    There a guys who start their video with an ad. And there is cherno, who shows how to make coffee in slowmo instead

    • @will8090
      @will8090 6 ปีที่แล้ว +19

      Excuse me , but obviously his name is "A Jenner" according to (closed caption).Better to use subtitle options (CC button over there).

    • @ITR
      @ITR 6 ปีที่แล้ว +40

      As someone who has never before heard about this channel, I was very confused

    • @michaelsherwin4449
      @michaelsherwin4449 6 ปีที่แล้ว +10

      I just want a list of ingredients that he puts in his latte. I want to talk that fast and type that fast and recall all the language details that fast. It must be the latte because something is giving him superhuman brain function!

    • @michaelsherwin4449
      @michaelsherwin4449 6 ปีที่แล้ว +5

      Also I suggest that Cherno puts a few drops of his latte in the cactus plant every video. I suspect that the cactus will grow to be 6ft tall and form ears, eyes and a mouth and have an IQ of about 200. My IQ measured by Mensa is 145 but it could sure use a boost! lol

    • @batabatonica
      @batabatonica 6 ปีที่แล้ว

      ward

  • @yonikeshet8691
    @yonikeshet8691 6 ปีที่แล้ว +1280

    You know that you can write "using namespcae std" instead of writing std::, it will make a lot of the examples in this video clearer to read and understand.

    • @AmeshaSpentaArmaiti
      @AmeshaSpentaArmaiti 6 ปีที่แล้ว +32

      but the using keyword is so situational it's not really worth it. It also becomes much less clear if you "using" more than one namespace.
      ...that was a pretty clunky sentence.

    • @kristupasantanavicius9093
      @kristupasantanavicius9093 6 ปีที่แล้ว +34

      The only thing that you get by "using namespace std" are broken code samples which you have to go over and add std:: everywhere after you pasted the code.

    • @farberbrodsky
      @farberbrodsky 6 ปีที่แล้ว +138

      It was a joke xD

    • @useraccout1635
      @useraccout1635 6 ปีที่แล้ว +26

      That's not true. Any experienced c++ developer is completely familiar with anything inside the std namespace. The problem is with people (like he mentioned in the video) who try to replicate the STL and give it the exact names as the original. Yeah, that's gonna fuck everything up. There is absolutely no reason to std:: everywhere when you know what's what. All it does is unnecessarily bloat code. I'm not say don't not use it, but don't exaggerate it's limited consequences, which when they do arise, are easily solvable with any decent IDE.

    • @skaruts
      @skaruts 6 ปีที่แล้ว +20

      I use condoms. So there.

  • @LucidStew
    @LucidStew 6 ปีที่แล้ว +292

    The reason this question gets asked a lot is because programming courses don't want to have to explain scope and scope resolution early on, and once they do, using namespace std is so ingrained they don't bother undoing it.

    • @VictorOrdu
      @VictorOrdu 5 ปีที่แล้ว +12

      Great observation!

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

      That shit happened to me when I started lol

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

      My teacher didn’t even know about unique scope name resolution lol. They’re too caught up in C World.

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

      True, it's same also in universities with fields not related to the programming directly. Like we have C++ course on our first year on mechanical engineering, and we were told write using_namespace as mandatory and never got explained what it actually is, because we always used to work with console output, never used more than 2 extensive libraries (vector and cmath) and nor wrote more than 800 lines of code. Thanks to the Cherno I've learned not to do it

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

      Thankfully my teacher explained why using namespace std is not good on the second day of the class. Even though most of us don’t understand what he’s talking about at that time.

  • @h.hristov
    @h.hristov 6 ปีที่แล้ว +584

    “Never EVER use ‘using namespace’ in a header file. “ Noted.

    • @worsethanjoerogan8061
      @worsethanjoerogan8061 6 ปีที่แล้ว +46

      Learned this the hard way

    • @JoseGonzalez-rt5fk
      @JoseGonzalez-rt5fk 6 ปีที่แล้ว +16

      You can if you don't use other libraries like he does, it would save you a bit of time. Although, it would raise a bad habit.

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

      If you in contest about Algorithm (like ACM ICPC, ...) then you should use "using namespace std", else you shouldn't use it.

    • @nextlifeonearth
      @nextlifeonearth 5 ปีที่แล้ว +15

      @@JoseGonzalez-rt5fk You can if you know for an absolute fact that the software will never be developed upon again after version 1. If it's for a customer; don't, you don't know what they're going to do in the future.
      If it's for your company; don't, you'll be the one that has to deal with it later because they wanted to use that one feature you need a lib for.
      If it's a personal project you might open source some day, also don't.
      Like there are very few cases where you could, but probably still shouldn't.

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

      Ok, but did you understand why?

  • @ScaramangaG
    @ScaramangaG 6 ปีที่แล้ว +1344

    You don't have to bring the entire std namespace. I mostly use:
    using std::cout;
    using std::endl;

    • @sandeepr7141
      @sandeepr7141 6 ปีที่แล้ว +138

      and using std:cin;

    • @PoojaDeshpande84
      @PoojaDeshpande84 6 ปีที่แล้ว +359

      lol didnt even know I could do that...
      new to c++

    • @DarkLevis
      @DarkLevis 6 ปีที่แล้ว +83

      You probably shouldn't use std::endl much at all

    • @zeyode
      @zeyode 6 ปีที่แล้ว +38

      @@DarkLevis I mean, if you're just outputting variables or something, it's easier than typing '
      '. What's wrong with endl?

    • @DarkLevis
      @DarkLevis 6 ปีที่แล้ว +86

      @@zeyode nothing horribly wrong just it calls std::flush after '
      ' which is often not intended.

  • @MrBLARG85
    @MrBLARG85 5 ปีที่แล้ว +74

    “Remove all the STDs.”

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

    Dude! Your videos are highly appreciated. I'm a CS student and I find your "real world" perspective on things to be extremely helpful.

  • @zemlidrakona2915
    @zemlidrakona2915 5 ปีที่แล้ว +346

    I'm kind of an old timer. Been programming since '81. I've even programmed on a computer with real magnetic core memory. You could open the box up and see each bit.......no joke..... In any case, you're one of the few TH-cam programmers I like. Keep up the good work.....

    • @mattizzle81
      @mattizzle81 5 ปีที่แล้ว +25

      Wow, I first played with QBASIC, Assembly, etc in 1993 and I thought those were the old days. Lol. Makes me feel young. ;)

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

      I envy y'all early programmers. You had it cooler back then

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

      @@_lapys ikr, people that time had less resources to learn from, i respect old programmers, they r rly hardworking

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

      wow...
      would you say that programming was easier (or at least simpler) back then when the machines were less complicated and things were less abstract?

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

      are you guys insane, today any 9 years old can download a radom App (for him) a radon tutorial on the internet and star programming on the get go, and in a couple of weeks he already know how to do lots of simples algorithms.
      back them you literally need to have electronics degree to understand whatever the fuck that maching were doing or else everything would break.

  • @will8090
    @will8090 6 ปีที่แล้ว +73

    Why I don't "using namespace std"
    "latte art could use a bit of work but really hits the spot"
    -TheCherno

    • @zBMatt
      @zBMatt 5 ปีที่แล้ว

      Will read your comment while he said that.

  • @Aqsa792
    @Aqsa792 6 ปีที่แล้ว +27

    I dont know the basics of C++, I have zero programming knowledge and yet I understood what you were trying to tell. My mind is blown away by how great you are at teaching/explaining stuff to others!
    BEFORE ANYONE ASKS: I accidentally saved this video in my Watch Later and I was confused how/why it was there so I decided to check it(trying to figure out why i saved it) and then I was mesmerized by Cherno's excellent slow-mo coffee making and I just decided to stick till the end and wow I learned something great today.

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

      TH-cam is a strange place

  • @pako_powr
    @pako_powr 6 ปีที่แล้ว +349

    Now we all know where the Patreon money is going towards lmao.

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

      Probably his EA money to be fair

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

      Going to Costa Rica cofee plantations

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

      Making good content ?

  • @arcanesunku
    @arcanesunku 6 ปีที่แล้ว +21

    "What you may have noticed at the beginning of this video"
    You making coffee?

  • @jrcowboy1099
    @jrcowboy1099 6 ปีที่แล้ว +877

    longest. intro. ever.

    • @IsakFyksen
      @IsakFyksen 6 ปีที่แล้ว +87

      This guy clearly does not listen to Pink Floyd.

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

      @@IsakFyksen lol

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

      best. intro. ever.

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

      Yeah but i loved every second of it

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

      so you are new here

  • @mkmabdelkawy
    @mkmabdelkawy 6 ปีที่แล้ว +12

    We are in 2019 and your series still rocking. Your high quality videos and all the many advice you give are invaluable, because it is coming from years of practical experience in this industry. Keep up the good work.

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

      2020 :)

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

      2021, still top tier

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

      2022!

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

      2023...

    • @CodersGang
      @CodersGang 5 หลายเดือนก่อน

      2024..🚀🔥

  • @rissandimo
    @rissandimo 6 ปีที่แล้ว +10

    Great job, I loved this video, it was very informative! I always try to follow best practices and I've been programming in C++ for about a month now. I am going to take your advice.

    • @theshedman
      @theshedman 5 ปีที่แล้ว

      The same with me too. Very new to C++ (3 wks now). I like this very channel. Already learning a lot. A big thanks to @TheCherno for his great job.

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

    this video starts with 2 minutes of making coffee

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

    I'm newer to C++ and have thus far been using namespace std. I recognize the reasons why it isn't optimal to use it, however my rationale is that I want to get a hang of the syntax and function library before worrying about namespaces in general. It probably is about time to make the switch before my programs get too complex to keep track, though.

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

      I wanted to add the addendum to this comment that I have since stopped using namespace std in my programs. It took about a week before it felt natural. For reference I'm usually coding about 30 minutes a day. It was worth switching, but I am glad I used it for my first few weeks of coding in C++. Stopping helped to develop a better understanding of scope, which becomes more important as your programs become more complex.

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

      I am also new to C++ , and searching for people to join me on discord to build a small community to share knowledge and help newbies.

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

      @@laveeshtomar I am interested in talking to other aspiring programmers. Feel free to post the discord link when it's up!

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

    That intro was one of the most cleanest, beautiful things I have ever seen. Well done, man!

  • @IgnoreSolutions
    @IgnoreSolutions 6 ปีที่แล้ว +46

    wtf man the last time i watched you it was you talking over visual studio now you out here being a videography pro

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

    I was like: "GASP!" when he waved the mug around the laptop!

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

      someone here has ptsd because of accidents with coffee. I understand you perfectly :p

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

      @@dionyzus2909 My dad spilled a drink on his laptop keyboard. it was instantly dead.

  • @tedleahy8075
    @tedleahy8075 6 ปีที่แล้ว +7

    Really good, interesting video. I've only recently started learning C++ so this was something I've never even thought about. But why on earth do you think people who've clicked on a programming video would want to watch 2 minutes of you making a coffee first??

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

    Hey, you know you can just using namespace std; and then you don't have to type std everytime

  • @SamTanXYZ
    @SamTanXYZ 6 ปีที่แล้ว +122

    I'll sneak into your codebase and add "#define eastl:: std::"

    • @kylecox5127
      @kylecox5127 5 ปีที่แล้ว +53

      You're like hitler, but even hitler cared about Germany or something

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

      @@kylecox5127 lol

    • @मेबीराज
      @मेबीराज 4 ปีที่แล้ว +4

      Then suddenly all EA games will become free and slower xD
      (IDK if that makes sense or not. all I am saying is EAAAAAA = PAYYY and stdlib = slow lib!!)

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

      @@kylecox5127 Lol nice reference

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

      monster :0

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

    there are plenty of new programmer channels now, but yours is still my favourite number one, bc the others just brag about how great their life as software engineers is, while you offer valuable interesting content.

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

    That is a good argument. Makes me think twice about using it.
    That being said, it will be an extremely long time if ever before I need to worry about massive files. No more namespace.

  • @abhijeetjain04
    @abhijeetjain04 6 ปีที่แล้ว

    I was waiting for this video from quite some time and now wait is over. Really good video !!!. Thanks

  • @errorlooo8124
    @errorlooo8124 6 ปีที่แล้ว +11

    I know you probably know this but i just wanted to leave this out here because you can say "using std::(function name/ class name);" (ex. "using std::cout;"), i think this is better because you are just saying exactly what you want and it's easier because now if you want to for ex. to use another function from a namespace called "cout" you can actually see that there is already a "using std::cout;" so for this case i think that it is better plus you can actually see what functions/classes you are using from std(any namespace), again just becuase it's the best of both worlds dosen't mean you must use it, i just find it easier and better this way, and the rest is basically the same as Cherno, just wanted to say this, as he did not cover this.

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

    These intros are the cherry on top of the cream on top of the cake. Beautiful content in every sense.

  • @Day13May
    @Day13May 5 ปีที่แล้ว +6

    That intro was oddly mesmerizing

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

    This is 2021November, a bit late....but your coffee /latey making procedure is both calming and mesmerizing...good start for a vid!

  • @almondhete3623
    @almondhete3623 6 ปีที่แล้ว +139

    Sorry, I have a question. Why don't you use namespace std?

    • @luisponce3580
      @luisponce3580 6 ปีที่แล้ว +34

      Yeah, and also, what programming ide is this?

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

      Visual studio 2017

    • @jjbailey01
      @jjbailey01 6 ปีที่แล้ว +5

      Technically he does use namespace std. He details this in the video. He does so by explicitly declaring it each and every time he makes a call from std. What he doesn't do is obfuscate the use of namespaces by calling "using namespace std;" which is essentially the lazy way of doing so and can easily make it difficult to remember which function is being called from which namespace.

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

      Nice name tho...

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

      Thanks a lot.

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

    Thanks for the tip on the header. I haven’t experienced any issues because of that but I can see how that would be disastrous in a group setting

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

    Lol, love it... more and more of Peter McKinnon :) Keep it going!

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

    I thought it was going to be about slowing the program down to begin with given the extremely long intro
    but what he actually said makes much more sense

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

    What I was always told was it ok to use in main and no where else but I think I might stop doing even that

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

    Fantastic intro, mate!

  • @meanmole3212
    @meanmole3212 6 ปีที่แล้ว +68

    Is that a coffee or a milkshake?

    • @jjbailey01
      @jjbailey01 6 ปีที่แล้ว +13

      mean mole It is a latte. Basically a fancy steamed coffee milkshake.

    • @xeekk
      @xeekk 6 ปีที่แล้ว +7

      Hard to call it a milkshake when it's not cold or made with icecream. It's simply a cafe latte, espresso + steamed milk.

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

      @@warrick_lo Very brave.

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

    We can use namespace std before certain functions which uses the std library. While if we need to use a user-created library, we can just call it wherever required. Eg, std for regular keywords, and apple::(keyword) wherever needed.

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

    I really like having complete knowledge and control over my types. Yes in theory if I don't import any other stl like classes I will know what I am working with, but I want to see it explicitly, and I also want to see it explicitly in 6 months. I also don't use auto much.
    I guess this also comes down to what you work on and your role in the team. I do a lot of reverse engineering and often think about actual individual bits of data. I am often also the guy that they call when something "should work but it doesn't" and it's always some small detail like a bug in a private method. Abstraction and short code are great, but some of us have to dive into the ugly details so making everything explicit became a habit of mine.

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

    You should post more these type of concept videos ,i was about to go to bed and after watching this well my sleep is been chased away .It was good and thank u

  • @joey546
    @joey546 6 ปีที่แล้ว +45

    I think the better question is why does EA have their own Standard library?

    • @Grougal
      @Grougal 6 ปีที่แล้ว +36

      The std library is often not really fit to use in low level engine programming because you need performance, thread safety, memory leak safety etc. pp.
      Creating your own std library that mimics the actual std library but is better for your purposes ist quite common actually.

    • @PoojaDeshpande84
      @PoojaDeshpande84 6 ปีที่แล้ว +25

      they need to hide the code where they fleece the customers with dumb dlc

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

      ​@@PoojaDeshpande84 The EASTL is publicly available on GitHub, and code that handles DLC wouldn't be defined there. I get that you're trying to knock EA here, but at least say something that makes sense.

    • @Ginger_Hrn
      @Ginger_Hrn 7 หลายเดือนก่อน

      Bc Std::vector is not very well optimised

  • @atharvananoti5481
    @atharvananoti5481 5 หลายเดือนก่อน

    Bro this video is literally the reason I got my internship. All the good wishes and power in the world to you Cherno

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

    At least he knows the important of a good espresso before anything is said.

  • @jousboxx9532
    @jousboxx9532 6 ปีที่แล้ว

    The intro honestly adds so much to the video even though it has nothing to do with namespaces.

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

    I thought I accidentally clicked on video about coffee

  • @atuljain2845
    @atuljain2845 6 ปีที่แล้ว

    Very nicely explained. And other than that video editing and intro section was also nice.
    Thank You.

  • @brandygonz12
    @brandygonz12 5 ปีที่แล้ว +12

    Interesting. It's like the fact that I prefer to code in my native language (french) so I don't mix my functions (in french) and more general functions (in english).

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

    I am laughing so hard on the intro
    Welcome back to my Coffee++ Series, my name is Cherno

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

    Good to see someone has basically the same view I do when it comes to name spaces.
    I'd probably used vector as an example you have std::vector and then you can have math and graphic libraries with vectors which are entirely different in nature.
    When I first stared using C++ the std wasn't near as good as it is now. It was pretty easy to write better performing code on your own. So people very often created their own versions of what was in std.
    99.9% of the time I don't use it. The times I do it is usually something short that is being made and I probably just had the default code system create a console project and was to lazy to delete it to simply show someone else how something works. For large projects I never use it.

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

    Lovely intro
    lovely topic
    and best video
    in the TH-cam i have ever seen
    Keep going..(:

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

    Hold on!
    ..I need to watch this with a coffee. Brb.

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

    Mate..what a great content! Thx for the explanation!

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

    Well there it is, one of the examples what separates good coders with lousy ones.

  • @sayoojmandodi1172
    @sayoojmandodi1172 5 ปีที่แล้ว

    adorable intro and as always your explanation made it more easier to understand :) ; Enjoyed it ;

  • @cantcode1001
    @cantcode1001 6 ปีที่แล้ว +13

    First two minutes of the video == using namespace std;

    • @jjbailey01
      @jjbailey01 6 ปีที่แล้ว

      Skyclad lol.

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

    A whole two minutes of dramatic coffee making vibes.
    Fantastic video.

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

    I've been programming in C++ since before namespaces existed . Using "using namespace std" was something I latched onto pretty quickly when namespaces first became a thing and it hasn't ever confused me before, nor has it ever confused anyone working with my code. I guess it's just a matter of style.
    So my question is, when you are using functions from eastl, are you also using functions from std simultaneously? You mentioned that eastl is an API replacement for std, so I would expect one would only use one without the other.

  • @ToxicityGameDev
    @ToxicityGameDev 6 ปีที่แล้ว

    Watched half, didn't even need to finish, I was sold on not using namespace in like video three lol, so I was already convinced before this video. Great work Cherno.

  • @derpmarine216
    @derpmarine216 6 ปีที่แล้ว +9

    Then there’s Rust.
    #[macro_use] // I think that’s the syntax.
    extern crate clap;
    use clap::*; // oof.

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

      Derp Marine i think if you have clap in your Cargo.toml then you only have to:
      use clap::*;

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

    Good point. Who knows what may happen if you were "using namespace std;" and "using namespace eastl;" and called a function, that was included in both, but varied slightly in definition.

  • @gage2560
    @gage2560 6 ปีที่แล้ว +69

    that intro tho

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

      GAGE was long.

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

    Very well explained! Thanks for the tip about using a namespace!

  • @jannikkoch4944
    @jannikkoch4944 6 ปีที่แล้ว +27

    I'm a simple man, I get a youtube notification when Cherno uploaded a new video, I hit like.

    • @Psychedique
      @Psychedique 6 ปีที่แล้ว +7

      You are so simple, you can't even come up with an original comment.

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

    My biggest catastrophe with "using namespace" so far was not finding The Cherno's channel earlier

  • @MrJ-vs7vr
    @MrJ-vs7vr 6 ปีที่แล้ว +47

    Hey man. There are folks whining about the intro. Don’t listen to them, they are brilliant because you’re not just a robot teaching us code. We want to know you as a person in ways you’ll want us to.
    Heck, throw in some drone footage of yer homeland Australia, We’ll love it.😍
    Soo.. thank you so much, you taught me a lot of good programming practices.
    Cheers

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

      People come here to learn C++. They find a high quality video and class FOR FREE and still complain about seconds of coffee making intro. Those shouldn't be here then.

  • @lynnstrunk6408
    @lynnstrunk6408 6 ปีที่แล้ว

    Everything I wanted to know...... but didn't know enough to ask an intelligent question. THANK YOU..... SUBSCRIBED!!!

  • @slap_my_hand
    @slap_my_hand 6 ปีที่แล้ว +18

    What's the point of the long intro?

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

      slap_my_hand porn

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

      He probably bought an expensive dslr and doesn't do much with it so he needs to make long intros to justify getting the camera

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

      It's art. Art is the point of art.

    • @789blablajaja
      @789blablajaja 6 ปีที่แล้ว +1

      +slap_my_hand Coffee is like 80% of coding, Its a coding tuturial.

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

      Whats the point on asking whats the point of the long intro?

  • @patrykpogoda7323
    @patrykpogoda7323 7 หลายเดือนก่อน

    I've liked it after intro because of nice coffee making scene... and about C++ it is as good as always! Great job!

  • @alexkiecker4175
    @alexkiecker4175 6 ปีที่แล้ว +8

    Myself and most professionals don't because of name conflicts

  • @krisitak
    @krisitak 6 ปีที่แล้ว

    Another great video. Never looked at it that way! Thank you!

  • @ThePhinista
    @ThePhinista 6 ปีที่แล้ว +11

    Nice intro but WHY SO MUCH CREAM

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

      because it's a latte

  • @WildGrowthJ
    @WildGrowthJ 4 หลายเดือนก่อน

    the random edit energy sometimes lol. They're pretty nicely done. Can't program without coffee after all

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

    Using std:: actually makes your code cleaner

    • @SR-er6hx
      @SR-er6hx 4 ปีที่แล้ว

      It's and it prevents sudden headaches!!

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

      Depends you could use it in function context and make a rule that you never use it in global context

  • @MrTopfpflanze1
    @MrTopfpflanze1 6 ปีที่แล้ว

    You have a really good point, usually explicit code looks a little bit more bloated, but is much more readable!

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

    using namespace std
    at the top of the program violates the reason why namespaces were added in the language.

  • @someguy2910
    @someguy2910 5 ปีที่แล้ว +2

    0:10 roflol, is that your daily coffee ration? Reminds me so much of Seattle where the people drink coffee like trucks drink gas.

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

    6:36 i laughed so hard

  • @andysester7785
    @andysester7785 6 ปีที่แล้ว

    You've convinced me! Excellent video.

  • @KaranLobana
    @KaranLobana 6 ปีที่แล้ว +91

    "using namespace std;"
    ahh the mark of an amateur

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

      Karan Lobana could not agree more

    • @arnerademacker8548
      @arnerademacker8548 6 ปีที่แล้ว +27

      Heavily disagree. Because like any naming convention, whether “using namespace std;” makes code easier or harder to read depends entirely on your code.
      Just like in actual language, btw. If you were to stick to your guts you’d use punctuation and capitalization. You don’t, because implying proper qualification of your sentences is enough to be understood. Just like implying proper qualification of functions is often enough for code to be understandable.

    • @ChrisLeeW00
      @ChrisLeeW00 6 ปีที่แล้ว +7

      It’s like the mall grabbing of the coder world.

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

      I agree its context dependent. If I were to be showcasing a piece of code on a slideshow, I would use this expression. But for any professional codebase or project, I would never use this. And most would agree with me on this.

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

      Ah yes, the mark of code that will never see the light of day :)

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

    I am watching this at morning and the intro... I didn't had a coffee

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

    Hands down one of the most pointless intro I've ever seen.

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

      Simon Dimas no need to be rude. You could express the same sentiment saying something like ”Thanks for the videos. That intro was a bit long and doesn’t really relate to the content. Keep up the gopd work!”
      By the way, I liked it as a one off thing but it would get tiresome if it was in every video.

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

      @@martinlarsson8947 Whip anf naenae

  • @Tony-cm8lg
    @Tony-cm8lg 2 ปีที่แล้ว +1

    Why is it so ubiquitous in school to use namespace std in the header ? It seems like not very useful to learn something that should be avoided at all costs when using the :: syntax actually teaches you how namespaces work

  • @steakiefrags1866
    @steakiefrags1866 6 ปีที่แล้ว +57

    I hate these way too long intros

    • @jdnoidea
      @jdnoidea 6 ปีที่แล้ว +8

      SteakieFrags same, seem pretty pointless for coding vids

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

      Every time i see that i wanna click away from the video.

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

      I think his other passion is videography, so be supportive ;-)

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

      Toxicity Game Dev He would be able to create another channel for that.

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

      Or you just don't complain about it and let him do what he wants with his skills / free time, I am sick of people saying "Im here for the this", if you don't like it. Go else where for you C++ videos.... Oh wait, they are all terrible so I guess you can either give him props or complain and watch it anyway lol. Because lets be honest, you are going to watch them anyway...

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

    The most comforting intro ever

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

    I can see your point here. There have been times when I revisited code after a month. If there was any ambiguity... Oh man... I've had to rewrite code and double down on documentation. I totally see where you are coming from.

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

      I mean, the whole point of having namespaces was for name resolution. It's so that we know where certain symbols come from. What's the point of having that feature in the language if people are just going to refuse to use it?

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

      @@NyscanRohid if you use "using namespace std" at the head of your code, and you have a similarly named function in another namespace, then you are not going to be using namespace to make your code more clear. If you use namespaces then use them correctly, but not with std and not when there could be ambiguity, otherwise you'll muddy your code up. That's what he's saying

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

      @@MrJdcirbo No, that's what I said. I'm agreeing with him. When you use `using namespace std;` you're not actually _using_ the namespace, you're just obscuring it in your code. Yeah, you say that you're `using` namespace std, but are you really _using_ it, or are you _misusing_ it?

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

      @@NyscanRohid I misunderstood. I apologize. I'm so used to arguing in these comment sections. Does that say something about me or society?... Or both?

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

    Great explained. Thanks!

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

    Dude, new C++ programmer. Your channel is gold. I wish you were my friend.

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

    You're a better C++ teacher than any of my C++ professors.

  • @effexon
    @effexon 6 ปีที่แล้ว

    this is very important lesson, especially if you ever need to maintain or update that code. it's near imossible to remember how your code works after eg. 6 months, let alone how many hours and googling and stackoverflow posts reading goes then to figure out why this funny runtime code abnormality. very well presented lesson.

  • @waliddu62
    @waliddu62 6 ปีที่แล้ว

    Ty for that, I all the time using namespace std and I didnt know there would be some situations where using that would be a problem, it's good to be aware of that.

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

    I'll admit that there are projects where this matters, but I've been going for a long time now and haven't burnt myself yet. So I think I can hold out on changing like, a hundred header files for a little longer.

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

    I just think that since your channel is dedicated to helping people understand coding, it'd be much easier for us newbies to read when there aren't a million std:: everywhere... yeah maybe to you it looks cleaner the other way but not all of us are as good as you :P food for thought

  • @rajanimandlecha8888
    @rajanimandlecha8888 6 ปีที่แล้ว

    Thanks for clearing the confusion

  • @emilemil1
    @emilemil1 6 ปีที่แล้ว

    I guess it depends on your environment. If your IDE shows you information about functions as you type them or select them (yours appear to not do that), then that removes a lot of the confusion. It can show both which namespace the function belongs to, which parameters it takes, and most crucially it can show that there are several functions available with the same name.
    I would also say that if you're going to include "use namespace std", then you should stay consistent and do it in every file. Even when it's not included, assume that it is there, and don't include some other namespace with a function like find_if or print. That way you know that if you ever see "print" without a prefix, you can be certain that it's std::print.
    Same thing if you're in the other camp and want to avoid "use namespace X", then I see absolutely no reason why you should accept it for namespaces with longer names. It's much better to be consistent and use an alias to shorten the name: "namespace rlns = ::reallylongnamespace"

  • @CombatFXZone
    @CombatFXZone 5 ปีที่แล้ว

    I think for halloween my costume is going to be a header file that uses namespaces.

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

    I was wondering that same question every since I first watched your videos. Yeah, when I first found out "using namespace std" I really thought it was the best thing in the world. But your point is surprisingly compelling. Makes me think that if I ever intended to make a complex code library with more than a handful of classes I should actively try to understand and use namespaces to segregate classes.

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

    Came for the programming lesson. Stayed for the slow-motion latte art.

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

    I used to think "there's 0 possible reason to not use namespace std because it reduces so much clutter and even in a short program tens of std::cout and std::endl" but then I was thinking that many times I also write programs that have maybe one output print. And I was thinking it possibly adds some unnecessary amount of junk in compiling the code (maybe not) so I maybe shouldn't use it without exception. And now hearing this it all makes sense, especially having used many python libraries and considering the possibility that they might become part of me using C++ as well, the non-standard libraries.