[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: using namespace std;.png (237 KB, 1170x1822)
237 KB
237 KB PNG
Why does this make midwits seethe so much?
>no, dont write import java.util.ArrayList;, you have to refer to every ArrayList as java.util.ArrayList with the full namespace
Why does no other language get this butthurt over using statements?
>>
midwits think verbosity = smart
and c++ is crawling with midwits, just like c
only difference is c doesnt have namespaces so you dont see this
if you prefix everything with the fully qualified name it makes you look like a genius to these fags
meanwhile java, c#, and rust users just dont care about being pretentious
if the code works it works
if it looks simpler by adding the names to current scope so be it, easier to read for everyone
>>
Get rid of header nonsense and then maybe people will be more willing to use using.
>>
>>106433484
We have modules, just use modules, simple as.
>>
>>106433396
You should not import the entire namespace. It does not matter the language, importing all names from a namespace into your own is retarded. You can import specific names, however C++ has shitty syntax for this since you need to write using declarations for every single name you're importing.
>>
>>106433648
In C# you have to write using System;, how is that different from using std::*; ?
>>
microsoft actually has the balls to use using statements
Microsoft won
>>
>>106433460
Well it is caused by C++ having headers and using statements crossing translation units but this is probably true anyway
>>
boomers doing boomer things
>>
>>106433396
You're the midwit.

Using namespace std is considered bad practice because it can cause conflicts between libraries that use similarly named functions and keywords.

You'd have to be a vibe coder, a rustard, or a jeet to not know that.
>>
File: girugamesh.png (122 KB, 452x391)
122 KB
122 KB PNG
just

std::pair<int, int> getCoordinates() {
using namespace std;
return make_pair(1, 2);
}


or

namespace {
using namespace std;
pair<int, int> getCoordinates() { // header-private
//...
}
}


just don't
using namespace std;
everywhere or in exported scope within headers
>>
c++ is so ass
>>
>>106433460
> Java
> Force every field to be private but need getters and setters instead of having a public field must dumbass language users imaginable
> But guys we got very cool records now (it's a class with a public field)
>>
>>106433396
you can even do
import module java.base;

since Java 25, which gives you everything you need
>>
>>106435787
> But guys we got very cool records now (it's a class with a public field)
the fields are private but you get a public method with the same name as the field to access them. comes in handy for method references and such, the jvm gets rid of that indirection anyway
>>
>>106433396
i used that phrase solely to have less to write while jacking off in godbolt. that said, i feel this isn't "correct" usage so i refrain from doing so in any real-er projects of mine.
>>
>>106433396
because the c++ standard library sucks so much that people use reimplementations with the same symbol name
if you don't have external dependencies then there is no reason not to import the whole std namespace
>>
>>106434262
Without using statements
import std.collections;
import com.company.util;

std::collections::HashMap<std::core::String, std::collections::Vector<com::company::util::People>> getPeopleFromCode(std::core::StringView s) {
// body
}


With using statements
import std.collections;
import com.company.util;

using std::collections::HashMap;
using std::collections::Vector;

using com::company::util::Person;

HashMap<String, Vector<People>> getPeopleFromCode(StringView s) {
// body
}

Who is the jeet now? Do you think the first is more readable?
>>
>>106436321
this is literally rust
what are you talking about
>>
>>106436321
Sepples fags never use nested namespaces, they dump everything into a single namespace
>>
>>106433696
>Microsoft won
won what?
have you used any of their products in the last 20 years? it's all shit
>>
>>106437099
C# is pretty good, I prefer Java better but C# has a lot of quality of life features
>>
The committee is pajeet
>>
>>106436321
I used to think using statements were bad, but this is a reasonable comparison, even if extreme. I think C++ users put up with it because std:: is five extra characters and everything just gets put in there, so there are no std::collections namespaces like Rust or C#. It also probably has to do with headers always exporting using statements causing namespace pollution even where you would not want it, which is a problem modules solve. In my ideal C++ I think std should be broken up into better namespaces like std::collections, std::core, std::text, std::net, std::math etc. like basically every other language does, and quite frankly it never made sense why everything is just haphazardly thrown into namespace std. You also have to note that a lot of classes are really poorly named (std::map refers to a TreeMap in Java, not an abstract map class, and std::unordered_map refers to a HashMap). This is why I would rather just work with Rust, because C++ is built on rotten foundations
>>
>>106434262
Rust doesn't pollute the global names pace like cnile brain rot language, we have actual modules and encapsulation.
>>
>>106436321
I thought the problem from the OP was importing the using the whole std library namespace, drilling down to the specific class with using statements is fine.
>>
>>106433396
the best reason to not do it is because nobody else does, and that will make your code easier to understand at a glance. if i see a string or vector without the namespace, my assumption would be that you are using your own class, not the standard library, and would force me to waste time checking if there is a using namespace statement somewhere. even worse if you put it in a header.

if you are not working with anybody else, then you can do whatever you want.
>>
you "use" types.
you do not "use" individual naked functions.
I do `std::cmp::max(a, b)`
I do `use std::collections::HashMap; HashMap.new()`
one uses aliases for conflicts between type names
>>
>>106437750
There is nothing wrong with that either
using std::chrono::*;
using std::filesystem::*;
>>
import std.filesystem;
import std.io;

using std::filesystem::*;
using std::io::IOException;

Expected<String, IOException> aggregateInformation(const Path& p, GlobPattern g) {
File f{/* something here */};
// …
}

Seems reasonable to me if you want everything from std::filesystem anyway
>>
>>106438001
Or you could do
use std::cmp;

fn main() {
let a: i32 = 3;
let b: i32 = 5;
let c: i32 = cmp::max(a, b);
}

But otherwise I follow the Java conventions, never static imports (always have functions associated with a class/namespace).
>>
So this is the power level of the cnile and his slightly less retarded brother the sepplesfag... sugoi
>>
>>106433396
>caring what redditors think
kys OP
>>
>>106433648
>importing all names from a namespace into your own is retarded.
why?
>>
>>106438149
This is stupid. Free functions are perfectly fine
>>
C++ is so fucking ugly. Why would you choose :: as a syntax for anything.
>>
>>106438937
As opposed to what?
>>
File: 1754950228548952.png (32 KB, 780x783)
32 KB
32 KB PNG
This is what you get for arguing with jeets on reddit.
>>
>>106433396
>java
>>
>>106439513
The argument applies to rust and every other language with namespaces as well
>no, you cant write use std::collections::HashMap, you have to write the fully qualified std::collections::HashMap<K, V> each time you want a HashMap
>>
>>106433648
You can do this with Racket, but even if the symbols aren't all loaded, the whole library is anyway. There's not much point in importing some library and only importing specific symbols unless there's a naming conflict (which, now that I think about it, I have encountered).
>>
>>106440036
This is basically import in C++, it just loads the library into the translation unit but does not add it to the current scope. For that you have to use using to import the symbol into scope. Does Lisp have such features? I want to try Clojure because it uses JVM but I wonder how it handles Java namespaces.
>>
>>106434072
how dare you
>>
>>106441545
wat
>>
>>106433593
>just use modules
go away bjarne nobody is using modules
>>
>>106442353
I want modules, headers suck ass, simple as
>t. not bjarne
>>
>>106433648
Yes but what if OP was a faget. Then what?
>>
>>106433648
Not completely. It's retarded if done in you header file. It won't matter if done in the matching source .cpp file because as a compiled unit it's isolated from all downstream header includes.
>>
When devs insist on typing std everywhere, it looks like they’re std-std-stuttering.
>>
All this never would have been a problem if C++ just had proper encapsulation and no header bullshit.
>>
>>106443653
Well it was trying to be a band-aid over the same limitations of C by being backwards compatible. You could say the handicap was forever locked in from this underpinning.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.