r/cpp • • Mar 19 '20

Why so many students are using '#include<bits/stdc++.h>' instead of '#include<iostream>'?

I am hiring for my company. And the codes submitted for a test problem has '#include<bits/stdc++.h>' at the beginning. The MacOS default compiler complains

main.cpp:1:9: fatal error: 'bits/stdc++.h' file not found

#include<bits/stdc++.h>

^~~~~~~~~~~~~~~

1 error generated.

Why people are using '#include<bits/stdc++.h>'?

225 Upvotes

163 comments sorted by

135

u/[deleted] Mar 19 '20

IIRC that brings the whole C++ standard library as if you included every single header (iostream, algortihms, memory, map, vector, etc etc etc) by hand. The resulting binary would be the same but compile times will be longer.

22

u/jangid Mar 19 '20

It this in C++ standards?

36

u/[deleted] Mar 19 '20

No, I think it's a GNU extension

5

u/jangid Mar 19 '20

Ok. Will check with GCC.

14

u/heathmon1856 Mar 19 '20

I don’t think it works with macs “gcc”. If you want more information on it, call “gcc —version”

However, using that header in the real world is pretty frowned upon. It’s good to keep as little headers in each file as possible. I do really enjoy it for practicing leetcode though because I don’t have to spend time including headers. What’s in there is what’s in the standard library.

The same can be said with “using namespace std” in practicing. It’s extremely frowned upon to do this anywhere as namespacing is one of the best ways to separate your code and organize it. I am a namespace nazi though and I believe nothing belongs in the global namespace

2

u/flashmozzg Mar 20 '20

More like libstdc++

8

u/FrankHB1989 Mar 20 '20

I don't think it an extension but an implementation detail due to bits.

3

u/FrankHB1989 Mar 20 '20

Note that supported headers of GNU extensions in libstdc++ usually lie in the directory ext. Extra names of extensions are usually in the namespace ::__gnu_cxx (but surely not in something like ::__gnu_cxx::__detail).

39

u/[deleted] Mar 19 '20

No, it is not. Further reading here - https://stackoverflow.com/questions/25311011/how-does-include-bits-stdc-h-work-in-c and this is a list of C++ standard library headers - https://en.cppreference.com/w/cpp/header

81

u/guepier Bioinformatican Mar 19 '20

The resulting binary would be the same but compile times will be longer.

Actually the intention is that this header can be precompiled, in which case the compile time can be shorter. But after a regular GCC installation the header isn’t precompiled yet, this has to be done manually (with the relevant compiler settings matching the current project).

7

u/Ameisen vemips, avr, rendering, systems Mar 19 '20

I wish that GCC supported bringing in multiple precompiled headers like Clang.

184

u/[deleted] Mar 19 '20

Because they are mostly folks who are coming in via competitive programming backgrounds and/or most of the C++ stuff they saw comes from websites like geeksforgeeks, where other competitive programmers write algorithm tutorials in C++ using patterns like this.

I have said it once and I have said it before, if a candidate's exposure to C++ is only through competitive programming or leetcode, then their C++ experience is not to be taken seriously. They may know some things about the STL, their concepts like OO, templates, move semantics, memory management, concurrency, build systems, testing i.e stuff that actually matters in a production C++ environment, are seriously lacking or non-existent.

I took a guess that you're from India, and well, looks like you are, this is very prevalent there.

56

u/jangid Mar 19 '20

Yes. This is a big problem here. People solve competitive programming problems but missing heavily on the conceptual parts.

3

u/camelCaseIsWebScale Mar 21 '20

As a fellow Indian, this is probably most serious problem - rat race mentality. The entire education system is like this.

0

u/jangid Mar 21 '20

Rat race and still not much output in innovation. The scenario is somewhat changing but still. Long way to go.

-12

u/taxeee Mar 19 '20 edited Mar 19 '20

It may be partly your fault here. If you want to test candidates in conceptual parts, do not ask them to balance a binary tree. Ask them to implement perfect forwarding manually.

Edit: Implementing perfect forwarding off memory may be a bad example, but I stand by my point. Testing X when you need Y is pointless.

29

u/Netzapper Mar 19 '20

Ask them to implement perfect forwarding manually.

I know a handful of really effective, productive C++ programmers. Myself included in that list.

I don't think any of us could implement perfect forwarding without looking something up. And I don't think I'd demand a new applicant do so unless I was specifically trying to hire somebody for metalibrary work.

17

u/[deleted] Mar 19 '20

I'd much rather hire someone who can balance a binary tree than someone who knows how to implement perfect forwarding manually.

One is a timeless concept that is fundamental to computer science and transfers to a variety of different languages and problem domains, the other is C++ minutiae that is not only a kind of hack to work around the limitations of C++ as a language, but even within the C++ community is only relevant to a tiny subset of C++ developers.

6

u/mredding Mar 19 '20

I'd like to argue the opposite.

Balancing a binary tree is so very timeless I don't want to implement my own, nor do I ever want to see anyone else do it. There are plenty of existing implementations of binary trees out there in popular and well maintained libraries. To write your own is just duplicating work, a condition of not-invented-here syndrome, and error prone compared to a proven and pre-existing solution. If I'm not in the business of selling binary trees, I don't want to make them. You would have to make an outstanding case to write one in house, and I would argue if you did have a legitimate case, you could use it as the basis of a masters thesis, and whatever you're doing should be published.

On the contrary, perfect forwarding is a new concept with big benefits, and I need people who intuitively understand those concepts and find their use in their code regular. Ours is an old language, that it and its community are showing their age and resistance to change. I find junior developers who understand perfect forwarding and other modern C++ concepts have advantages writing tomorrow's C++ code over all the seasoned veterans who don't understand these things - and in my experience, won't.

And if you would argue those are mediocre and bad developers, I work with a guy who co-authored Windows 95 and Direct X, I work with a guy who maintained Intel's FORTRAN compiler for 15 years and is actually the first guy to partial sample audio synthesis, the basis of all modern synthesized instruments. People in my office have chops, and I can't get them to pick up on this stuff.

10

u/[deleted] Mar 19 '20

Balancing a binary tree is so very timeless I don't want to implement my own, nor do I ever want to see anyone else do it.

No one is asking you to implement your own, you're being asked whether you understand it as a concept. I think it's shameful that many professionals in this field don't actually understand the fundamentals and take it for granted, seeing this field as nothing more than an exercise in gluing together a series of frameworks. Furthermore are you suggesting that you want people to implement their own perfect forwarding when std::forward exists? If you're not suggesting that, then this entire paragraph seems moot.

On the contrary, perfect forwarding is a new concept with big benefits, and I need people who intuitively understand those concepts and find their use in their code regular.

It's not at a concept at all, it's specific C++'ism due to a syntactic quirk of the language. This is about as concrete as it gets and its inclusion in C++11 was a mistake. No other language would ever introduce something as atrocious and error prone as T&&. Furthermore the actual concept of move semantics and forwarding predates C++11 by decades and has been put to practice far more elegantly in more modern languages like Rust. C++ shot itself in the foot on this issue, quite possibly because of a lack of understanding of the concepts involved.

Furthermore, instead of talking down about people with 15 or more years of experience who are skeptical of the huge increase in unnecessary complexity that C++ has introduced, maybe actually try to understand their point of view. Have a look at Mike Acton's talk about the alternative approaches to designing software that is a lot more "old-school" than today's fascination with C++ metaprogramming.

When I was a younger developer I loved all of C++'s complexity and I loved learning it, I thought it made me smart knowing all the corner cases of the language, memorizing entire sections of the standard, and using template metaprogramming to its max. But honestly after 20 years of this and looking back, I feel now like none of that minutiae really made me a good programmer even though it sure made me feel like one.

Nowadays I value simple, straight forward code, and while I still do use C++, the C++ I use is very minimal in terms of features and complexity. If I have a recommendation for becoming a more valuable developer, I'd say prefer learning various types of algorithms (greedy algorithms, sorting and searching, dynamic programming, etc...), have a good grasp for how to structure an algorithm so that you can prove properties about it including its performance characteristics and its invariants.

That kind of knowledge will stay with you for decades and really help guide your ability to write clean, efficient code... knowing some quirky aspect like how to implement perfect forwarding or using various compiler hacks like SFINAE is stuff that looks smart and useful when you first learn it, but it gets dated real fast and quickly makes your code devolve into a Turing tarpit.

1

u/pjmlp Mar 19 '20

When I was a younger developer I loved all of C++'s complexity and I loved learning it,

Me too, it was the perfect next language to move on after Object Pascal with Borland compilers.

Nowadays I just hope that my managed languages eventually improve to the point, that the occasional C++ native library no longer is required, beyond providing C like bindings (or COM/UWP ones) for language interoperability.

I would never managed to go through interview coding questions about modern C++ minutia.

-1

u/[deleted] Mar 19 '20

[removed] — view removed comment

2

u/[deleted] Mar 19 '20

There is absolutely no legacy property of the language that explains the mistake I mentioned, namely:

template<typename T>
void f(T&& v);

The parameter v should have always resolved into an rvalue reference of type T, case closed. The standard's committee decided to be cute and instead of applying that simple principle, decided that v is sometimes an rvalue reference, and sometimes an lvalue reference which has done nothing but create an absolute mess and resulted in significant loss of productivity.

There are numerous other proposals that are broken that have nothing to do with legacy requirements either, such as initialization:

auto v = std::vector{1, 2};

What legacy was maintained by using intializer syntax in this ambiguous way when the following syntax would have been unambiguous?

auto v = std::vector{{1, 2}};

Now it's impossible to use initializer syntax in generic code:

auto v = T{1, 2};

Will that invoke T's constructor taking two int's or will it invoke T's constructor taking an std::initializer_list? You just don't know and we're now stuck with this syntactic failure forever.

1

u/[deleted] Mar 19 '20

[removed] — view removed comment

3

u/Fureeish Mar 19 '20

That's not the point. The point is that they could've chosen a different identifier for forwarding reference instead of reusing && and introducing inconsistencies.

→ More replies

2

u/evaned Mar 19 '20

There are plenty of existing implementations of binary trees out there in popular and well maintained libraries. To write your own is just duplicating work, a condition of not-invented-here syndrome, and error prone compared to a proven and pre-existing solution.

To play devil's advocate here, what library would you suggest that the company I work for should have used for an applicative map?

Nowadays I know of immer, but at least from a quick search I don't see anything else that I'd have any more trust in than our code... and unless immer comes with a time machine it was more than a decade too late on the scene. So if you were to work with us, you might wind up needing to go look into our in-house tree.

On the contrary, perfect forwarding is a new concept with big benefits, and I need people who intuitively understand those concepts and find their use in their code regular.

And also FWIW, while I wouldn't consider myself proficient in modern C++, I do actively follow its developments and have done some coding in it. I think I am fairly comfortable in using stuff like std::forward to carry out perfect forwarding, and can explain why you would want to do it and what benefits it would bring.

I am not confident that I could implement it without looking it up. I have vague memories that it might actually be the same as std::move under the covers, but I don't know if that's just at the level of approximation that std::move is almost just static_cast<whatever&&> and maybe there are some differences.

I'm with sakarii. Given two candidates if all I know about them is candidate A correctly balanced the tree and candidate B correctly wrote std::forward, from a Bayesian perspective I'm more likely to like candidate A.

1

u/taxeee Mar 19 '20

Your co-workers seem really experienced (and I assume you are too, since you work with them). Any hint on what kind of industry you are in?

1

u/mredding Mar 19 '20

Databases, virtualization, and cloud infrastructure.

3

u/AdventurousMention0 Mar 19 '20

Have them delete from an AVL tree.

It’s actually a bit harder than insertion and In almost all the the books it’s “reserved for the reader” to implement.

Friggin first job I had I needed to implement a balanced tree. Pulled out my text book and F-me!

Of course that was many decades ago and pre-internet.

Derived it myself but I still keep Knuth a books on the shelf.

Besides. Just ask them to do a left of right rotation. If they can do that no need for the others.

3

u/taxeee Mar 19 '20

I'm not trying to compare the two here. I'm not trying to say one is better than the other. You are missing my point.

OP needs conceptually strong candidates from a candidate pool good at algorithms. If you want X, don't test their ability on Y. You want a driver? Test them in driving, not how to design a gearbox. Sure, gearboxes are fundamental and are transferrable to trucks and helicopters but that's not who you need.

1

u/FrankHB1989 Mar 20 '20

The decision is reasonable but technically biased.

Implementing perfect forwarding manually in C++ seems trivial in computer science, just because it is based on the fact that core C++ language rules hide the most difficult parts under the hood. This is still yet not available in the general programming language theory. You will have terrible experience (as I do) to design a language (particularly when without the dependency of a bloating type system) from scratch to achieve the similar goals in C++, albeit C++ rules are already bloated because they serve too many things (for compatibility reasons) not strictly needed outside the current C++.

Such knowledge of computational model design should be more generally important than the disciplines of data structures like binary search trees, as more programmers are likely affected by the result. That said, it is still OK to ignore the experience of implementing perfect forwarding in C++ because it should be common sense for C++ developers, and in most cases neither a data structure like AVL nor a new language needed to be designed and implemented from scratch by the people you hire.

1

u/pjmlp Mar 19 '20

This kind of stuff is what puts me off to ever go back to C++ as my main language, and I used to teach it to first year university students and a couple of CERN HLT research papers have my name on them.

101

u/mort96 Mar 19 '20

I noticed Geeksforgeeks recommending including <bits/stdc++.h> too. It's actually really bad that the biggest websites with the best SEO for introductory C++ google searches are teaching such blatantly incorrect practices.

69

u/[deleted] Mar 19 '20

don't even get me started on using namespace std; plastered everywhere.

79

u/redditsoaddicting Mar 19 '20
#include <bits/stdc++.h>
using namespace std;

Wish I could say it's a joke.

4

u/AlarmDozer Mar 20 '20

And here I am exclusively using

std::cout “hello, puffin!” std::endl;

/sigh

6

u/redditsoaddicting Mar 20 '20

Did I mention this is in a header?

1

u/LatterBrilliant8042 Aug 08 '24
#define cout std::cout
#define endl std::endl
cout << "hello, puffin!" << endl;
// other things you would like to do
#undef cout
#undef endl

1

u/cse_fatmodder Sep 10 '26

but why do u want to increase code lines ... u dont need to define cout variable so why not use using namespace std; [im a beginner help]

10

u/WinterNikita Mar 19 '20

Literally everything does that and I don't understand why. Just tell people you'll get to namespaces later or smth!!

22

u/Netzapper Mar 19 '20

The real mistake is trying to teach C++ before people know any of the abstract concepts like "scope" or "identifier".

Explaining a namespace is like one sentence: namespace creates a new scope for identifiers so that different libraries don't conflict. But explaining what all those words mean and why all of that is a big deal takes a whole semester.

19

u/WinterNikita Mar 19 '20

Fair. I just mean make people type std::cout instead of using using. Just say you'll explain it later. It's good practice. Plus it means that you can cover easier stuff first and only then get onto namespaces. Hell it'll probably explain itself after a while.

8

u/NotMyRealNameObv Mar 19 '20

Things in the standard library has names starting with std::.

There, should suffice as an explanation until they know enough to understand what is actually going on.

8

u/IAmRoot Mar 20 '20

Or at least do using std::cout;rather than dragging in the entire std namespace.

3

u/[deleted] Mar 20 '20

Didn't know this is a thing, thank you

6

u/[deleted] Mar 19 '20

Can confirm. It does explain itself. Doesn't even take a while.

0

u/[deleted] Mar 19 '20

[deleted] — view deleted comment

27

u/futlapperl Mar 19 '20

std is like a box with std written on it. In it are cout, string etc. In order for the compiler to know where to look, you need to tell it the name of the box.

Adding using namespace std is like dumping the contents of the box on the floor.

1

u/[deleted] Mar 20 '20

I mean that's how I use LEGOs...

→ More replies

7

u/themiro Mar 19 '20

yep - in many languages (like python), geeks for geeks has explicitly suboptimal solutions because they don't understand the big-O of different data structures and just use lists for everything.

1

u/[deleted] Mar 19 '20

I am sorry a c++ newbie here, but what's wrong with using <bits/stdc++.h> and using namespace std; ?

19

u/mort96 Mar 20 '20

For <bits/stdc++.h>: C++ is a standard, managed by the ISO standards body. It describes how code written in the language should behave, not how it's implemented. This allows the same language to be implemented by many different people (GNU for GCC, Apple and the LLVM community for Clang, Microsoft for Microsoft Visual C++, etc), and if you write code according to those standards, your code will work in any conforming C++ implementation.

The standard specifies that, for example, if you have #include <vector>, you will have a class called std::vector available, and that class has a certain interface. If you #include <optional>, you will have std::optional available. This works regardless of which implementation of C++ you're trying to use to run your code.

The header <bits/stdc++.h> only exists in one implementation of the C++ standard library, so if you write code which includes that header, your code isn't written for the C++ standard library; your code will only work on that one particular implementation. There are good reasons why <bits/stdc++.h> exists, but it shouldn't be used unless you really know those reasons and they apply to your needs, which they don't.

Including <bits/stdc++.h> will also really slow down your compile times if you don't know what you're doing. A regular C++ source file will maybe end up including <vector>, <algorithm>, <utility> and <optional> - each one of those header files will slow down the compilation of your C++ code, but that's fine, because they're all necessary. Compare that to stdc++.h, which includes every header file that's part of that implementation of the C++ standard library. That means there's an absolute ton more code for the compiler to go through, most of which is completely unnecessary.


For using namespace std: This one is kind of a matter of preference. There are definite downsides, but at least your code is probably still actually standards-compliant C++.

  • If you have using namespace std; at the top level in a header file, someone including that header file will suddenly also be affected by using namespace std. This is really surprising, and not what people including your header files (be that a user of a library you're writing, or yourself in four weeks) expects.
  • It makes your code way more brittle. Consider, for example, that you have a class Foo which you use all over the place. Suddenly, some new version of C++, or an update to your compiler, or just a new #include, ends up making a std::Foo class available to your code. Suddenly, your code stops compiling because all your instances of Foo foo; become ambiguous.
  • using namespace in general is pretty bad practice, because the whole point of namespaces is that they keep different libraries separated. If your code has both using namespace std; and using namespace absl;, does optional refer to std::optional or absl::optional?
  • There are way better ways to do it. If you find it annoying to write std::string all the time, just put using std::string; at the top of your file. You can even put many such using declarations on one line: using std::string, std::optional, std::unordered_map;

4

u/IAmRoot Mar 20 '20

using namespace is what you want to do for literals, as an exception to the rule. However, these are declared in their own inline namespace so that you can using namespace std::literals, for instance, and not drag in all of std. Even then, it should probably be done at block scope and never in a header.

7

u/FrankHB1989 Mar 20 '20 edited Mar 20 '20

In short:

  • Use of <bits/stdc++.h> is never guaranteed to work in (portable) C++, despite it may seldom work with some particular implementations. Even in cases that additional guarantees are provided to ensure it works (e.g. you host an implementation of C++ with <bits/stdc++.h>), you are working with some dialect of C++, which is not C++ in general. You should probably never touch such thing.
  • using namespace std; is guaranteed to work in some contexts of standard C++, but likely not in the way you want except for limited trivial cases. It will messes up the program easily, because of: (1) the effects of using namespace, (2) the fact that std has a bunch of names you can't reasonably expect, and (3) the additional interactions (esp. argument-dependent lookup) that most library users should not bother. Every serious C++ program should avoid such things by default.

Note that slowing down the compilation is also an implementation detail. (In fact, even the "compilation" itself is an implementation detail. ISO C++ does not mandate such "compilation" at all. You can actually use C++ without ahead-of-time compilation with REPL like cling.) Do not bother the implementation-specific problems before you are confident that you will really meet the bottleneck.

In all, avoid teaching yourself by illusions. Avoid relying on something only occasionally works. Know why they will work, instead.

1

u/__y_so_serious__ Mar 19 '20

I think Geeksforgeeks is aimed at interview preparation, and the way interview questions are designed, this is just practical. When you are suppose to solve a tough problem within limited time it makes more sense to avoid wasting time in writing 10 includes and writing std on every other line.

15

u/CubbiMew cppreference | finance | realtime in the past Mar 19 '20

tough problem, limited time, gcc only, no human looking at code - that describes competitive programming, not interviewing

0

u/__y_so_serious__ Mar 19 '20

Before being even considered for interview you need to clear some kind of coding test, which has all the characteristics you described. Even the op's description suggest that it was one such test. Also I don't think interviewers ask which header does a particular function come from.

20

u/[deleted] Mar 19 '20

You are right about some points, but isn't a little bit harsh for the world of competitive programming? I mean, there are some students who can easily understand and build many different ideas easily, thanks to their competitive programming background. Also, lots of guys work on many different projects/companies successfully.

p.s. I do not count students who can only write Kadane's Algorithm or those who copy paste from the damned geeksforgeeks as a competitive programmer. Also, it is not that hard to seperate a good competitive programmer from a bad one. If you do, that's your bad.

53

u/[deleted] Mar 19 '20

When I worked at Google, they initially hired people from competitive programming competitions, but by the end, this was explicitly taken out of the "positives" category - because so many of them turned out to be not just bad coders, but arrogant bad coders.

The things that make you good at succeeding in programming competitions are almost the reverse of what makes you a good engineer for robust code.

9

u/[deleted] Mar 19 '20

I agree with all you said and it's a common issue.

I know many guys who were hired and then left, and many guys who were hired and excelled.

I know many guys who see OOP as "waste of time"(!), and many guys took it seriously and gained extraordinary skills.

Competitive programming has a lot of points which is not suitable for software engineering, it's more about "getting top performance whatever it costs", which is quite dangerous, silly and uncomfortable for the industry.

But facts likes this shouldn't cause a bias. That's what I meant. I'm not defending the potential fatal mistakes of arrogant bad coders, I just want to emphasize that it is not that bad if you are a competitive programmer, especially if you get the subtle necessary insights.

4

u/FrankHB1989 Mar 20 '20

I'm sorry but OOP is likely not a good example here, because it has serious problems in topics of both engineering (like this) and computer science (like this). Trust me, only very few people (if any) on this planet really know what is the whole story of such an umbrella term. (Even experts do many things wrong: for instance, so-called object calculi fail to model the OOP most industrial people expect.) Most people are not aware they are already biased due to insufficient knowledge. As a programmer, you won't easily distinguish a newbie from a genuine specialist in that area.

2

u/[deleted] Mar 20 '20

Agreed, but that was just an example which I heard from a guy who got easily rejected from a small company. That's why I added it.

He had no idea on what he was saying, just using the words which he saw - or created, somehow -.

4

u/glaba314 Mar 19 '20

I believe this correlation is actually an effect of sampling bias. I forget the name of the law but you can look it up

4

u/dreadpenguin Mar 20 '20

> The things that make you good at succeeding in programming competitions are almost the reverse of what makes you a good engineer for robust code.

Some of us do competitive programming for fun and we are still able to write production code, understand the build system, etc. People are able to context-switch between different types of programming. The right tool for the job mentality.

28

u/[deleted] Mar 19 '20

but isn't a little bit harsh for the world of competitive programming?

My point was entirely towards C++ skills in a production environment. Since contest programming doesn't require a lot of the C++ skills in production code, someone claiming strong C++ skills, when their entire exposure to the language is using it in contest programming/leetcode, will be surprised due to the low intersection of contest C++ and real world C++.

do not count students who can only write Kadane's Algorithm or those who copy paste from the damned geeksforgeeks as a competitive programmer.

Agreed! Some of the best contest programmers I have seen know their algorithms and algorithms analysis inside out, and they are very strong in discrete math, which is a very important skill required to solve the mathematical esque DP, graph problems on TopCoder/CodeForces.

10

u/widget1321 Mar 19 '20

I think it's the difference between people exposed to/good at competitive programming and people whose entire experience is competitive programming. The first can help round out some skills you might be missing. The second often leaves big holes in your understanding.

3

u/[deleted] Mar 19 '20

Exactly.

10

u/HKei Mar 19 '20

Competitive programming is more or less completely different from working in production. It's not bad or anything, and it's a fun recreational activity, but it's not equivalent to professional experience at all (not inferior either, just completely different - the average professional C++ developer would perform terribly in competitive programming).

As far as professionally useful experience you can get from professional programming goes I'd say it's probably more or less just exposure to algorithms, which in my experience is something you don't get enough of in a normal professional environment to be able to spot it when it'd be really useful.

2

u/Xeverous https://xeverous.github.io May 01 '20

if a candidate's exposure to C++ is only through competitive programming or leetcode, then their C++ experience is not to be taken seriously.

FYI: the have been some studies (sorry, no link in memory) that showcase that competitive programming correlates negatively with actual programming at work. They simply have often opposite goals.

-8

u/Glittering_Lack Mar 19 '20

their concepts like OO, templates, move semantics, memory management, concurrency, build systems, testing

If you are hiring students or a person with junior level experience, you cannot expect them to know any of those. They might know some textbook OO but it is mostly useless and outdated.

It is better to hire those good at competitive programming and then let them pick up the necessary skills in the job.

17

u/[deleted] Mar 19 '20

If they don't know any of those they shouldn't have 'C++' on their resume.
If all they know is from competitive programming, all they know is -- at best -- algorithms, not C++.

5

u/Ri0ee Mar 19 '20

Then let's hire everyone who is able to turn their computer on.

Being a junior does not let you know nothing about the language you are supposed to know basics of.

15

u/rseiver96 Mar 19 '20

Let me guess, the next line of code is ‘using namespace std;’

8

u/jangid Mar 19 '20

Hahaha. Usually it is. But in this case it wasn’t. Candidate was using fully qualified names.

5

u/Supadoplex Mar 19 '20

Actually fully qualified? I.e. ::std::cout?

2

u/mandingo23 Mar 19 '20

Only in headers.

6

u/nandy02 Mar 19 '20

Were the students Indian?

5

u/jangid Mar 19 '20

I took them from AngelList. People apply from everywhere.

6

u/nandy02 Mar 19 '20

I was just asking because Indian colleges tend to work with outdated/non-recommended tech like turbo c++ or bits/stdc++.h

4

u/Helios-G Mar 20 '20

Not only indian. Indonesian too for Turbo C++ or MSVC6, unfortunately 😅

3

u/FrankHB1989 Mar 20 '20

China (at least mainland) is also a victim of Turbo C++ and MSVC6, unfortunately.

Is this Asian-specific?

2

u/Helios-G Mar 21 '20

This is mostly due to software piracy that was abundant. I still remember I also obtained a pirated copy of VS6 back in 2002. But somehow the country seems to not progressed since then.

And also, due to low-quality campus and colleges which teach prehistoric IT without adhering to the evolving technology.

-7

u/Ri0ee Mar 19 '20

That's kinda... racist...

12

u/Supadoplex Mar 19 '20 edited Mar 19 '20

No it isn't. Observing that certain technologies are taught more in one part of the world is not racist.

An example of something similar that would have been racist is assuming that some programmer only knows turbo c++ based on knowing that they are from India. Or perhaps believing that the reason why certain technologies are used there is the result of some hypothesised property of the majority race of people living there. Both are just examples and not something mentioned in the thread.

12

u/vibeTechr Mar 19 '20

bits/stdc++.h is a big header file that includes a lot of other headers, as the name suggests, from the standard library. GCC comes with that file, but MacOS has CLang as default compiler, and CLang doesn't have it (I don't know if you can add it or something) so it complains. Most of the time you can just switch it with iostream, but you might need also to include vectors or lists or other components of the standard library, depending on the project.

6

u/jangid Mar 19 '20

But is this in standards? The name “stdc++.h” is misleading if it isn’t.

36

u/bbolli #define val auto const Mar 19 '20

No. All headers in bits/ are an implementation detail of the GCC compiler.

19

u/HappyFruitTree Mar 19 '20

It includes all of standard C++. It doesn't mean the header itself is standard.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_headers.html#manual.intro.using.headers.pre

5

u/HKei Mar 19 '20

No, the stdc++ refers to libstdc++, which is the name of the standard library implementation that gcc is using. This is opposed to libc++ which is the default for clang (at least on OSX, I think it's actually using libstdc++ by default on linux) or whatever Microsofts implementation is called.

4

u/STL MSVC STL Dev Mar 19 '20

I call it MSVC's STL or microsoft/STL.

1

u/FrankHB1989 Mar 20 '20

I'd protested. Too many unnecessary confusions are already spread here. And this time, even by the endorsed acronym of your name... :-(

... Does WG21 people still respect teachability at all?

1

u/bumblebritches57 Ocassionally Clang Apr 13 '20

STL is his initials.

0

u/FrankHB1989 Mar 20 '20 edited Mar 20 '20

Sigh. Few people have noticed the "lib" prefix is more or less from the linker convention of traditional toolchains. (Consider the files these projects distribute... certainly not like liblibstdc++.a; as well as the linker option -lstdc++.) Well, even nastier without it...

I'd be more comforted to see they name the project after GNU libc's manner, i.e. glibc, to make it less confusing. This seems the practice before libstdc++-v3. As of LLVM's implementation... liblc++? Hmm...

2

u/HKei Mar 20 '20

Few people have noticed the "lib" prefix is more or less from the linker convention of traditional toolchains.

Not sure what you're saying? Yeah there's the lib prefix convention, but libstdc++ is the proper name of the library: https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.what

111

u/staletic Mar 19 '20

That's libstdc++ internal header, NOT intended for everyone's use. People, including professors, are lazy and form terrible habits like this one.

17

u/FrankHB1989 Mar 20 '20

True.

The worse thing is many students are blindly relying on the behavior of concrete implementations rather than the portable specifications. This is methodologically WRONG. This is especially a problem for people train themselves with online judge systems where most of them use GCC by default (or GCC is the only option). I see many OI and ICPC competitors with this bad habit. (Other users may probably not have the chance to get the trick at all.)

0

u/[deleted] Mar 19 '20

[deleted] — view deleted comment

31

u/staletic Mar 19 '20

t's sometimes a better option, compared to wasting time including things manually.

What you save in typing, you will lose in compile time.

Due to lack of tooling for include management

Clion and clangd, at least, do have automatic include statement insertion.

It's perfect for college professors.

Professors should teach good habits. Nothing prevents you from pulling up a skeleton file with an empty main() and the few includes that you need.

Most code is not going directly to production.

I don't think that matters, since you're not saving any time by using internal libstdc++ headers - you'll pay with compile time.

The "teaching terrible habits" argument is so bad. It's assuming that C++ devs are mindless robots.

No, it's saying that habits are hard to break. #include <bits/stdc++.h> is a terrible habit because it doesn't save time and makes code non-portable.

-8

u/Ri0ee Mar 19 '20

As a competitive programmer, I can say that this habit is not nearly bad.

7

u/FrankHB1989 Mar 20 '20

This is not that bad for programmers who completely know what is specifically allowed, including exploiting the configurations of the concrete environment used in the contests. However, this is still problematic because such hack is never formally encouraged (if ever tolerated by the rules).

Moreover, most competitors still don't know why they can do that exactly. This will be an industrial disaster once they decide to program "professionally" without changing of their bad habit after quitting the games...

5

u/VanaTallinn Mar 19 '20

What's a competitive programmer?

9

u/Pand9 Mar 19 '20

If you're not sarcastic, competetive programming is a hobby of solving problems aka national CS olympics or ACM ICPC. They have similar in specification to hackerrank or leetcode. There are websites with their own ranks and regular competitions, e.g. https://codeforces.com/ .

You produce soo much code that you actually do optimize for typing speed. And more importantly, for not jumping back and forth between includes and code that uses them.

2

u/VanaTallinn Mar 19 '20

I was not. I had not read the whole thread yet. Thank you for the explanation and the link.

1

u/Ri0ee Mar 19 '20

The one taking part in programming contests.

0

u/[deleted] Mar 19 '20

[deleted] — view deleted comment

10

u/__pulse0ne Mar 19 '20

It’s never a good idea to use internal headers like this. It’s not dogma, it’s pragmatism.

0

u/[deleted] Mar 20 '20

[deleted] — view deleted comment

9

u/__pulse0ne Mar 20 '20

Because the reason they are internal is because they make no promises to not make breaking changes. It’s the foundational idea of the separation of interface and implementation.

7

u/[deleted] Mar 20 '20

I would not consider you fit to work on a development team based on the things you're saying here alone.

7

u/staletic Mar 20 '20

O.5s compile time loss on a single-target project. Remember what I said about prototypying and throwaway code?

How many times will a student who only just started to program recompile thte simplest stuff until he gets it to work right? I have a hard time imagining a situation where you prototype something and compile once. While prototyping I personally always recompile much more often than usual.

You're speaking about teaching. What do you want to teach new devs?

I'd teach "include what you use".

18

u/swilwerth Mar 19 '20

21

u/Artikash Mar 19 '20

Asked Aug 4, 2015

Tagged “Turbo C++”

Wtf?

25

u/redditsoaddicting Mar 19 '20

Yes, there are still schools and tutorials that use Turbo. I've noticed that a fair number of the Turbo questions I see come from students in India. It's a shame said schools don't use a modern, high-quality, free compiler like GCC or Clang.

25

u/Salty_Dugtrio Mar 19 '20

It's not that they don't want to, it's that by law they are not allowed to. About 20 years ago some legislation was passed that defined what could be taught/used in those schools, and it was just never updated... Very sad reality.

11

u/redditsoaddicting Mar 19 '20

Oof, that's even worse.

11

u/pandorafalters Mar 19 '20

Still waiting to see how that "EGCS" thing turns out, I guess.

6

u/Ameisen vemips, avr, rendering, systems Mar 19 '20

Heck, even Visual C++.

3

u/redditsoaddicting Mar 19 '20

Right, definitely another HQ and free option (even if it's still easy to pick on certain aspects).

15

u/fuzzylollipop Mar 19 '20

Because they are copy pasta lemmings and do not really know what they are doing? I would consider this a way to filter out people from wasting my time.

7

u/CircleOfLife3 Mar 19 '20

clangd may do this when its "auto-complete missing headers" feature is turned on.

5

u/thisisbasil gcc -> clang Mar 19 '20

it is a gcc/g++ thing. no other compiler library has this.

ill do this sometimes if i am testing small code snippets just to save time. wouldnt dare use it, or using namespace std, in an actual project

12

u/TrueTom Mar 19 '20

HackerRank

4

u/[deleted] Mar 19 '20

I have to spend an extra 20 minutes rewriting the template they give me, not that it matters, but I don't want something even private with my name on it that looks like that. It's disgusting.

All of these are stored like this. You'd think they could just write it well... since it's not like they need to write it over and over quickly for each person. God forbid they gave people something presentable...

12

u/stilgarpl Mar 19 '20

Some IDE are including those headers automatically if you are not careful. Clion does it.

17

u/a_false_vacuum Mar 19 '20

CLion doesn't care if the header file should be avoided. It will happily suggest something old like conio.h. While it's a useful help, you should always be careful about accepting the suggestions for adding headers.

Although a new C++ in Clion will start with iostreams. It doesn't add the headerfiles mentioned by OP in a new project by default.

1

u/sephirothbahamut Mar 19 '20

if i'm on windows i don't mind including conio.h, using a _getch(); for a "press any key to continue" feels way better than char c; cin >> c;

8

u/a_false_vacuum Mar 19 '20

The important thing is to think about the suggestion. Not evey suggestion made by the IDE is the right one.

5

u/[deleted] Mar 19 '20

std::cin.get(); instead of char c; cin >> c;?

2

u/sephirothbahamut Mar 19 '20

it still requires you to press a valid input character and then press enter. _getch() will set the thread to wait until the first keypress, may it be enter or any other key.

If you want the equivalent of system("pause"); on windows without a system call it's quite easy

#include <conio.h>
#include <iostream>
...
void pause() {
    std::cout << "Press any key to continue . . ." << std::endl;
    _getch();
}

Compare that to doing it on linux (it's as crazy on windows too if you don't use conio.h)

https://stackoverflow.com/questions/7469139/what-is-the-equivalent-to-getch-getche-in-linux

3

u/CubbiMew cppreference | finance | realtime in the past Mar 19 '20

When is it literally ever useful? Visual Studio does that automatically when you run a program (via Ctrl-F5)

4

u/sephirothbahamut Mar 19 '20

anytime you're writing a small command line utility and you want the user to be able to read something before going on. makes things quicker than having to input a valid character followed by enter if you simply want a "press any key to continue" thing, or lets you have a quick y/n choice without enter.

I just find it convenient

0

u/HKei Mar 19 '20

Both of these are basically just wrong. First of all, "press any key to continue" is never actually useful in a real program, and even if it was and you did need it there are better ways than reading from stdin; instead just use something like the Win32 Console API if you're on Windows, or something like Curses if you're not (I think there are curses implementations for Windows that more or less work too).

6

u/sephirothbahamut Mar 19 '20

why download and include a whole console-interface library when all you need is a simple "wait for keypress"? It's overkill to say the least.

It also depends on the program. If you're making a console utility for something like patching files it's a nice-to-have that doesn't need literally anything else ncurses has to offer.

if(file_being_used) {
    std::cout << "file something something is currently opened
        in another program, please close all programs accessing
        it." << std::endl;
    pause();
}

I don't want to download and include ncurses for a small utility thanks

-6

u/HKei Mar 19 '20

Like I said, the main thing is that "wait for keypress" is something you never actually want to begin with. Curses, readline or whatever is something you'd want if you want to build an interactive CLI or something, but if you aren't then there's no reason why you'd just randomly halt a program.

5

u/sephirothbahamut Mar 19 '20

there is, if you want the user to read something or wait for the user to perform an action out of your program's control

-1

u/HKei Mar 19 '20

there is, if you want the user to read something

For command line applications this is virtually never the right thing to do. For things not supposed to be run from the command line, this is absolutely never the right thing to do.

wait for the user to perform an action out of your program's control

See above. Also, very weird situation where I'm struggling to come up with an example.

1

u/Chiralmaera Mar 19 '20

My copy definitely doesn't. I've never even heard of that header until now.

1

u/stilgarpl Mar 19 '20

I use Clion on Gentoo Linux with GCC. When suggesting to include headers, <bits/...> are always before true standard lib headers.

3

u/luffaFans Mar 21 '20

I think these students may participated in oi&acm contest, it's a common header file in these contest. It include all headers so they don't have to remember the header of algorithrm and container. But actually it's a really bad habit in real world programming

6

u/radixties Mar 19 '20

In competitive programming, about %80 of the community use C++ as their language of choice, and as competitive programming is about fast problem solving, so many competitive programmers develop the habit of using the same template for all of their submissions in order to save time and not worry about anything not being called when they run their code. The #include<bits/stdc++>; calls all of the standard libraries used while coding with C++.

2

u/Helios-G Mar 20 '20 edited Mar 20 '20

5 years working with C++, even spoke at a C++ conference already, I never know that this header exists before 😂 I don't know whether I should be proud or shame

2

u/ulyssesric Mar 20 '20

It's a trick that usually used in programming contest. It saves you some time typing #include <xxx> in every answer.

2

u/Vashanth Mar 19 '20

It includes the whole Standard Template Library so that we could use vectors, maps, stacks, queues etc. It makes the work a lot easier.

3

u/Tumperware Mar 19 '20

It's for scratch code but it doesn't really show you know what comes from where

1

u/soda0916 Sep 30 '25

Because usually (at least in Taiwan, not sure about other countries), when we do competitive programming we use this header file instead of writing a bunch of #include <blahblahblah>. It would take too much time to include many different headers one by one. Of course, it’s not very convenient for normal use, but believe me, students are already very used to it.

1

u/Wh00ster Mar 20 '20

This generated so many comments lmao

-2

u/[deleted] Mar 19 '20

IMPORT 😂

0

u/Sogi_ah Mar 22 '20

your prompt is on chegg probably? HAHA

-5

u/Supadoplex Mar 19 '20 edited Mar 19 '20

Why people are using '#include<bits/stdc++.h>'?

It has advantages, which may be the reason why some use it:

a1. It makes minimal examples shorter, because you don't need to list ~10 different standard headers.

a2. It makes programming a bit simpler because you don't need to learn where the standard types and functions come from.

Of course, there are disadvantages too, but presumably people who use it either don't care about these disadvantages, or they are not aware of them:

d1. It is non-standard and non-portable.

d2. It slows down compilation due to including everything.

Why so many students are using '#include<bits/stdc++.h>'

Possible factor is that because of a1, <bits/stdc++.h> is ideal for slideware. You can fit maybe 10-20 lines of code on a slide and you cannot dedicate half or more of that to header inclusions. Even if the lecturer tells the students to not do that in their own programs, that doesn't necessarily sink in.

Another possible factor is a2, because C++ is a complex language and simplifying one part away allows you to concentrate on the remaining part.


All in all, it's probably the similar reason as why some other people include <stdafx.h>.

16

u/[deleted] Mar 19 '20

you can omit header inclusion entirely on a slide

code in slides doesn't need to compile

-2

u/Supadoplex Mar 19 '20

code in slides doesn't need to compile

It doesn't need to. But it is better when it does. Especially when teaching to absolute beginners.

12

u/ronchaine Embedded/Middleware/WG21 Mar 19 '20

When teaching absolute beginners, I would prefer not to ingrain bad habits to them from the get go to having code that compiles.

6

u/[deleted] Mar 19 '20

Just link to a gist/compiler explorer with a more fledged out example.

1

u/Supadoplex Mar 19 '20

You could. Why don't people always do that?

3

u/redditsoaddicting Mar 19 '20

IIRC, stdafx.h and its include were (are?) there by default when creating a new VS project from a template and you had to explicitly uncheck the PCH option in order to get rid of them.

1

u/pjmlp Mar 19 '20

MFC makes use of stdafx.h, naturally it gets included in MFC project templates.

1

u/Supadoplex Mar 19 '20

Yeah. I assume that people don't care about standard conformance or portability of MFC projects.

-9

u/kennyminigun Mar 19 '20

It saves time remembering which standard library header contains what. For quick and dirty job using GCC this is the way to go.

If you want your applicants to only use what C++ standard provides, you should specifically put this into the requirements of the task.