4 ms·
God, C++ even today is still horribly verbose. I get that being "explicit" is being "better" but there are limits. Even after auto removed a lot of verbosity th
by noobermin 4y ago
God, C++ even today is still horribly verbose. I get that being "explicit" is being "better" but there are limits. Even after auto removed a lot of verbosity there still is a lot there just to get it to do exactly what you want.
- nikbackm 4y agoWhat is verbose about that? (The first case, not the second, special case) Seems hard to make it any shorter. Well, I guess you could remove "const" if you want.
- jeroenhd 4y agoHere's how it looks when you write readable C++: for (const auto &[x, y]: zip(a, subrange(begin(b), unreachable_sentinel))) { /* Do something with x and y */ } I'm not sure why C++ programmers don't like using `using`, it's as if Java programmers insist on typing out java.util.ArrayList every time because you may have an ArrayList of your own in the future. So much C++ code can become readable by adding `using namespace std::something`.
- cmovq 4y agoThe reason is header files. If you do `using namespace std::something` in one file and it gets included in another, the other file now has std::something in the global namespace which it may not have excepted. Other languages like Java have imports scoped a to a single file, so this is not a problem.
- jeroenhd 4y agoI see, but that's only a program in header files, isn't it? Most code will end up in .cpp files which don't get included (usually). It makes sense to use std::vector in a .h(pp) file, but in the .cpp you should be able to `using namespace std`, right?
- titzer 4y agoThe word "antiquated" comes to mind, but it's worse than that. An age-old self-created fractal hell of dumb problems created by a simplistic view of code reuse based on the simple mechanism of text inclusion that constantly restrains future evolution. It's antediluvian and just plain backwards.
- twic 4y agoWe are at least getting modules real soon now: https://en.cppreference.com/w/cpp/language/modules https://en.cppreference.com/w/cpp/language/modules
- xigoi 4y agoWe've been getting them real soon for… about 5 years now?
- ninkendo 4y agoThey were supposed to be part of C++11, back when it was called C++0x, before getting punted. So more like almost 20 years now (since some time after C++03.)
- duped 4y agoThe only compiler that seems to care about implementing modules is MSVC. It'll be "real soon" when GCC stops crashing.
- tragomaskhalos 4y agoUsing in a header file => complete no-no. Using in a cpp file => absolutely fine.
- jcelerier 4y ago> Using in a cpp file => absolutely fine. definitely not as soon as you want to do unity/jumbo builds (which are in my experience the n°1 thing to do to get fast CI builds)
- lenkite 4y agoIt should be completely fine to use `using namespace std` inside a function body right ?
- twic 4y agoC++ doesn't have a lot of namespacing below 'std', so if you go around using everything you need, you end up with a lot of short, possibly conflicting names in scope. Java avoids this somewhat because functions are always in a class, so there is a little bit of extra namespacing, even if you've imported the class.
- winrid 4y agoYou can still import fully qualified static method on a class: import someclass.doThing; Or maybe that's what you meant by somewhat :)
- gautamdivgi 4y agoDon’t the boost libraries use a bunch of namespacing? And I think you need boost to be decently useful in c++.
- cutler 4y agoI see the same thing in PHP. Example code full of inline namespace-qualified paths and a lot of array() instead of [] as if nothing changed since PHP4.
- jcul 4y agoIn an actual .cpp compilation unit, I'd probably write it like that. In a header it's generally advised to not add using namespaces. However, I appreciate the grandparent comment including the namespaces in the example, so I can see exactly where things are coming from.
- pdntspa 4y agoI don't do C++ but if it's anyting like my Java IDE most of that stuff pops up in autocomplete and you just tab through it all