Why I don't "using namespace std"

Поделиться
HTML-код
  • Опубликовано: 13 янв 2025

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

  • @TheCherno
    @TheCherno  6 лет назад +404

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

    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 лет назад +2050

    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 лет назад +20

      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 лет назад +41

      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 лет назад +139

      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.

  • @ScaramangaG
    @ScaramangaG 6 лет назад +1349

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

    • @sandeepr7141
      @sandeepr7141 6 лет назад +140

      and using std:cin;

    • @PoojaDeshpande84
      @PoojaDeshpande84 6 лет назад +360

      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 лет назад +39

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

  • @h.hristov
    @h.hristov 6 лет назад +587

    “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?

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

  • @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 RUclips 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 лет назад +74

    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.

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

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

      RUclips is a strange place

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

  • @arcanesunku
    @arcanesunku 6 лет назад +21

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

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

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

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

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

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

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

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

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

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

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

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

  • @petarsmilajkov9431
    @petarsmilajkov9431 6 лет назад +6

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

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

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

  • @abhijeetjain04
    @abhijeetjain04 6 лет назад

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

  • @Day13May
    @Day13May 5 лет назад +6

    That intro was oddly mesmerizing

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

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

  • @NinaTheLudaca
    @NinaTheLudaca 6 лет назад +1

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

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

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

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

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

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

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

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

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

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

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

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

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

  • @nekopushyo
    @nekopushyo 4 года назад +8

    I thought I accidentally clicked on video about coffee

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

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

  • @atuljain2845
    @atuljain2845 6 лет назад

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

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

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

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

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

  • @TheYahmez
    @TheYahmez 4 года назад +4

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

  • @digiandy6244
    @digiandy6244 Год назад

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

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

  • @jupitersky
    @jupitersky 2 года назад

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

  • @cantcode1001
    @cantcode1001 6 лет назад +13

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

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

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

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

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

  • @TKcKoucher
    @TKcKoucher Год назад

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

  • @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::*;

  • @WildGrowthJ
    @WildGrowthJ 5 месяцев назад

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

  • @gage2560
    @gage2560 6 лет назад +69

    that intro tho

    • @jdnoidea
      @jdnoidea 6 лет назад +4

      GAGE was long.

  • @sayoojmandodi1172
    @sayoojmandodi1172 5 лет назад

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

  • @koungmeng
    @koungmeng 5 лет назад +4

    6:36 i laughed so hard

  • @MrTopfpflanze1
    @MrTopfpflanze1 6 лет назад

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

  • @alexkiecker4175
    @alexkiecker4175 6 лет назад +8

    Myself and most professionals don't because of name conflicts

  • @lynnstrunk6408
    @lynnstrunk6408 6 лет назад

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

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

  • @martincets8334
    @martincets8334 6 лет назад +1

    Fantastic intro, mate!

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

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

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

  • @ThePhinista
    @ThePhinista 6 лет назад +11

    Nice intro but WHY SO MUCH CREAM

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

      because it's a latte

  • @jousboxx9532
    @jousboxx9532 6 лет назад

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

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

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

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

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

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

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

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

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

  • @christophermyers4515
    @christophermyers4515 6 лет назад

    This video saved me from what could have been a much bigger headache!
    I was using some library files from a program called GROMACS for simulations, and they typedef a type called "real", which could be either a float or double depending on the compile options. Apparently, this was conflicting with std::real() in the std::complex library (which I didn't even import!). It turns out that a silly "using namespace std" in an old header file of mine that I've imported was the culprit. In short, thanks for the advice!

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

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

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

  • @krisitak
    @krisitak 6 лет назад

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

  • @zeyode
    @zeyode 6 лет назад

    Video starts at 2:01
    Also
    >overloading an std function
    Y?
    As for your stl vector example, I'd imagine you could just reference the stl one with :: and you'd still know.

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

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

  • @Xxp0r
    @Xxp0r 6 лет назад +1

    Personally, I use "using std::vector;" for example in the scope it is being used. I find it a good compromise due to a lot of the flaws of "using namespace" that you mentioned in your video, it allows me to see what parts of std I'm using up front for that scope without having to continually type std::

  • @drwisdom1
    @drwisdom1 5 лет назад

    Mr. TheCherno is correct. A majority of the time that you are programming you are writing C++ classes/objects, not hanging out in main( ). The issue is when you are examining code, how do you tell where a call is coming from. Is it from within the class, one it is derived from, or external? You don't want to have to think about it, you want it to be obvious. If a call is external it helps to document where it came from so the std:: prefix is good. Clarity is far more important that saving code space, which is free anyway. When I write large classes with many derivations, I prefix the member functions with a word indicating the level it came from just so I don't have to ever figure it out. Mr. TheCherno discusses using naming conventions as an alternative. I don't do that for determining where a call came from but I do prefix static calls with an "s" so I instantly know it is static.

  • @R7Rhdev
    @R7Rhdev Год назад +2

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

  • @montleypictures7079
    @montleypictures7079 6 лет назад

    I often use stdio.h , #include thats Ok. I usually write printf.

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

    That's a good intro. I LOVE IT

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

  • @quantumac
    @quantumac 6 лет назад +1

    In one of our projects at work, we use a particular software package which defines "True" to be "-2". If you employ "using namespace std" at the wrong time, you'll get conflicts. Personally I think it was a passive-aggressive move by the developers of said package, but I can't be sure. Some people can be kinda "dictatorial" about their ideas. Thank goodness such developers can't use the language itself to enforce a particular coding style on me.

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

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

    2:23, love the coffee though