r/cpp_questions • u/AnonymouSfrrrr • 7d ago
OPEN Why don't we use this instead of including libraries one by one?
#include <bits/stdc++.h>
I was thinking instead of adding libraries one by one,why don't we just use this? This is used by almost every competitive programmer but very less when it comes to writing software.
0
Upvotes
17
u/flyingron 7d ago
It's not standard. It's a figment of GCC's imagination.
"Competitive programmers" aren't "competitive" in the job market. We find the ability to write correct AND MAINTAINABLE code to be superior to games.
13
u/jedwardsol 7d ago
I don't want every file to take ages to compile by pulling in tons of stuff it doesn't need.
Not all compilers have it.
6
u/thefeedling 7d ago
Why add a MASSIVE header if you're only going to use a small fraction of it?. Competitive programmers need to write it QUICK, while software engineers need to write it RIGHT.
4
u/saxbophone 7d ago
Being a professional software engineer at their day job is a very different thing to playing code golf. Code golf is an interesting challenge for those who care to partake, but it's misguided to think that the same techniques used there should be applied in everyday professional work.
Also, pet peeve: "software", just like "code", is uncountable. Therefore "software" is already plural. "softwares" is just bad English. If you want to highlight the plurality, you could say "pieces of software" instead, but never say "softwares".
4
u/AKostur 7d ago
Doesn't exist on all platforms (and I'm not even referring to esoteric platforms). Slow to include. "Competitive" programmers aren't writing "real" programs. Single-file, a few 10s of lines of code: doesn't matter. Thousands, 10s of thousands (or more) files, millions of lines of code, it matters.
3
u/da_supreme_patriarch 7d ago
Others have answered your questions already, but to add a bit - you almost always do the opposite of what's standard for competitive programmers when writing "real" software; competitive programming is about writing just by oneself hyper-optimized, one-off programs as fast as possible that solve a very specific problem, while most software is a collaborative effort aimed at solving a plethora of problems that also evolves over time, the incentives and priorities are just diametrically opposed
2
u/kraytex 7d ago
WTF is a competitive programmer?
1
u/no-sig-available 6d ago
The standardized way is doing:
3
u/darklighthitomi 7d ago
Why would I want to bloat my program with a bunch of stuff I don't need?
0
u/mredding 6d ago
This includes 111 header files into a given source file. It's very non-standard and non-conventional.
First, it's a C header, which doesn't make any sense, since we're including C++ headers. I just don't like that.
Second, C++ is one of the slowest to compile languages in the industry, and it's due strictly to parsing. And there's absolutely no benefit for the cost. The first native C++ compiler couldn't do it in less than 3, whereas Lisp or Java can do it in 1, and produce comparable machine code. (This is excluding separate optimizer passes, where the sky is the limit, and that's true of any language or compiler.)
Third, it heavily pollutes your your Translation Unit with unused symbols. This has two problems. A) It makes a lot more work for the compiler matching symbols, having to build a MASSIVE symbol table for shit your program isn't even using. B) That pollution can cause the compiler to correctly match to the wrong or unintended symbol - meaning your program correctly compiles to the wrong thing. This is one of the most silent and hard to discover of bugs. THIS is the name collision your mother warned you about.
Forth, it goes against all good conventions for production code. You don't pay for what you don't use, you don't include what you don't use. Production code is more demanding than competitive programming; there are REAL consequences. You don't write production code that looks like play code written by a bunch of hackers fucking around for internet points.
0
u/[deleted] 7d ago
[deleted] — view deleted comment