r/programminghorror • u/Kadabrium • Oct 21 '26
c++ Using namespace std, then proceeds to spell out std anyway
116
u/KaleidoscopePlusPlus Oct 21 '26
when i see 'std' i cant help but think sexual transmitted diseases
85
u/Top-Permit6835 Oct 21 '26
Technically speaking C++ developers are transmitted sexually
9
u/Nightmoon26 Oct 21 '26
Is that why I inherited a lifelong interest in computing? (I kid... I'm older than C++ by a couple years. Although... My mother using C while pregnant might be related to why I had to be delivered by C-section)
1
1
u/Top-Permit6835 Oct 22 '26
Yeah sorry mate, using C during pregnancy is known to cause various developmental disorders, such as ADHD, autism and an unhealthy interest in software development
5
1
u/blitzr1000 Oct 22 '26
same but it’s diminished since i started saying “stood” instead of “s tee dee,” i think i heard it said like that first in a Conor Hoekstra talk. sounds way better to say eg “stood string” imo lol
1
u/phycsIT Oct 23 '26
Every single time I look up "std-something" on google I get the definition of STDs instead of the damn doc. Then I always need to make a new search by adding "c++"...
0
88
27
u/Chesterlespaul Oct 21 '26
I have a different theory I haven’t read.
Someone, by habit, spells out namespaces in code. Then someone else collaborated, and didn’t have that habit. They added the namespace, and didn’t want to update all the currently working code.
5
u/Normal-Narwhal0xFF Oct 22 '26
Alternately, I worked with someone who would add "using namespace std" to every cpp file of it wasn't there. If code already provided with ns qualifiers, they didn't get changed. I prefer them to be left because I can remove the "using" more easily.
25
u/No-Dentist-1645 Oct 21 '26
I wouldn't call that "horror", just remove the using statement and you're good
4
u/Bemteb Oct 22 '26
Nah, that will break half of the code. You don't think they consistently use std everywhere, do you?
8
35
u/JohnVonachen Oct 21 '26
Looks like a cut and paste error.
2
u/Objective_Rate_4210 Oct 21 '26
naaah u/JohnVonachen removed only the reply. what a loser. I know, right?!
0
3
3
2
2
2
u/aikurou_mikisugi Oct 22 '26
I think it's the first time i see such a simple and clean C++ code btw )
2
1
u/OkPosition4563 Oct 23 '26
Usually happens to me when I switch to a new editor and they just put the using namespace std; there when you create a new file.
1
u/An1nterestingName Oct 27 '26
I don't know cpp yet, but my guess is that using namespace std makes the std:: redundant. Is that correct?
1
u/esp_mkb Oct 30 '26
If they are a team member please be gentle and let them know more about std inception - I crashed out on c++ back when I was trying to learn IrrLicht... Pressure busts pipes, be mindful of their 'rated load'
1
0
1
-1
-1
u/wvd_vegt Oct 21 '26
My guess is the programmer forgot once the std:: prefix and intellisense (or ai) correctly added the namespace at the top.
2
u/Nightmoon26 Oct 21 '26
Eh... Some organizations enforce a coding style that requires using fully qualified names everywhere, although even the most pedantic ones usually make an exception for the standard libraries (nobody in their right mind ever explicitly writes out
java.lang.Stringoutside of documentation) with import and using statements only being used as a convenient way for humans to remind themselves about dependencies before digging into the code. Other styles mandate that you must use fully qualified names unless the name is used a certain number of times in the file
386
u/Extension-Branch7938 Oct 21 '26
I often look at less experienced devs work and think “lol what are they thinking”
But you have to remember: “you don’t know until you know”
When i was learning cpp in 5th grade i added using namespace std; to every program no matter what… because no one had told me what it meant! It wasnt until later when i started working with namespaces that it started making sense. Don’t laugh or shun inexperience, instead use it as an opportunity to foster growth.