Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you want to compare the verbosity of both languages, why not use 'using namespace std' ?

Why write:

> std::vector<unsigned> counts; counts.resize(sevens.size());

When you can write:

> auto counts = vector<unsigned>(sevens.size());

Doesn't seem like a fair comparison to me.



I don't agree on the general usage of "using namespace std", so that part does not bother me.

For an even shorter init:

> std::vector<unsigned> counts(sevens.size());


Bringing namespaces into scope is perfectly idiomatic C++, just don't do it in your headers.


IIRC, importing an entire namespace into scope is a feature that was added exclusively for backwards compatibility and is not idiomatic modern C++.

What is idiomatic is explicitly importing individual symbols into a name peace.

    #include <iostream>
    #include <vector>
    #include <string>
    
    using std::cout;
    using std::vector;
    using std::string;

    int main() { 
    
      vector<string> v {"explicit ", "is better ", "than implicit\n" };

      for (auto p: v) cout << p;
      
      return 0;
      
    }
I'm on mobile so please forgive errors.


Wow, I never knew about that. I always hated having std:: everywhere, just so I could have "correct" C++. But I also hated referencing to std implicitly. This is the perfect tradeoff: explicitly state intentions in the beginning, then implicitly reference them as you go. (works until you use eighty five billion lines just to import your symbols)


Sure, sure, but I don't know, personally it feels sloppy. Renaming namespaces to shorten them feels ok, as is importing specific names. Bringing in the whole shazam gives the impression that the person who was writing didn't really care very much.

But again, personal opinion - it can definitely be used in some contexts (just be consistent in your project!).


> I don't agree on the general usage of "using namespace std", so that part does not bother me.

It should: we're comparing to Rust, whose namespace system seems very similar to a "using namespace std".


Rust only provides short reexports for a stable set of a few dozen items, rather than the "entire universe" of `using namespace std`. The only types that have a default reexport are `Option`, `Result`, `Box`, `String` and `Vec`.


To be even more specific, http://doc.rust-lang.org/std/prelude/


> we're comparing to Rust, whose namespace system seems very similar to a "using namespace std".

Not at all; only if you use globs ("use foo::*"). D's namespace system is like that, but not Rust's.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: