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

View all comments

Show parent comments

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/[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 (0)