[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology

View post   

[ Toggle deleted replies ]
>> No.79709751


>> No.79710025


>> No.79710067

The obsolete way:
#include <limits.h>
int x = INT_MAX;

The modern way:
[code]#include <limits>
int x = std::numeric_limits<int>.max();

so this... is the power... of C++...[/code]

>> No.79710092

No but certainly this is the most overused shitpost ever

>> No.79710094

It's literally C with optional expansions for more features. You don't have to use those features if you don't want to. It's literally just fucking C with some optional stuff. No more brother wars.

>> No.79710331


>> No.79710364

yes it's better because you can write generic code

>> No.79710371

if you look at any actual successful C++ programs you will see not only do they HARDLY use c++ features but when they do its older syntax not this gay new faggot c--11

>> No.79710376

>int x = std::numeric_limits<int>.max();
looks better desu

>> No.79710411

>should've been C with classes and templates
>is a complete clusterfuck of half-assed features instead
99% of the time I still have to use the operating system's APIs, for networking, filesystems, threading, etc. The committee literally has the greatest minds, time and money of the world available to them. Why not use any of that?

>> No.79710425

what even is "C with classes" to you guys?

>> No.79710441

That's how C++ was called before people more intelligent than >>79710411 figured out it wasn't gonna cut it

>> No.79710475

ya, but I never heard a concise definition of what it even means. like, what are we cutting? CPP only for macros? No operator overloading? I'm assuming we'd still have constructor/destructor, etc? WHAT DOES IT MEAN?

>> No.79710872

For me, it's C - with classes, templates and generic data structures and algorithms.

It took about three decades before it was possible to open a long-path file with a UTF-8 encoded name on Windows without having to code against Win32 yourself. The committee really needs to go back to the drawing board and figure out what hosted C++ for application development is and should be.

It does not mean adding a complete networking stack and probably even 2D graphics in C++23. It means ditching 90% of the domain-specific features, including I/O streams, threading and regexes. After the purge, re-evaluate and fix what's left. Make a Unicode-aware string type for example. They aren't going to, but I have yet to see an argument from any fucking committee member against this.

>> No.79711031

whats wrong with iostream

>> No.79711369

>For me, it's C - with classes, templates and generic data structures and algorithms.

so.... C++?

>It does not mean adding a complete networking stack and probably even 2D graphics in C++23. It means ditching 90% of the domain-specific features, including I/O streams, threading and regexes. After the purge, re-evaluate and fix what's left.

ok, but CRTs do all of these effectively by design. having the abstractions as a part of C++ potentially decouples it from C. So basically, you just want C++, but all the same broken platform specific CRT C bullshit?

we're never "purging" anything and you know it. I still don't quite understand what "C with classes" means.

>> No.79711507

>Terrible performance
>Responsible for both I/O and formatting
>std::ios_base::sync_with_stdio is true by default
>No measurable advantage over quick hand-made RAII wrappers over C I/O
>Hard to extend and use in more complex scenarios because of their Java-style OOP design
>You probably need to give them like 4KB worth of internal buffer by yourself because chances are std::cout is completely unbuffered
For more information, see: https://stackoverflow.com/questions/4340396/does-the-c-standard-mandate-poor-performance-for-iostreams-or-am-i-just-deali

>> No.79711574

Nah, but it's a pretty good filter for separating script kiddies from programmers

>> No.79711697
File: 505 KB, 640x862, jbd6q1xfgya61.png [View same] [iqdb] [saucenao] [google] [report]


>> No.79711811

If you're writing code for a library, even half of that is acceptable, because you want your library to be easily extendable and safe.
If you're writing code for your own program, your autistic and should write the first one, at most have const correctness and templates to prevent reuse of code.

>> No.79711851
File: 564 KB, 800x430, (9).gif [View same] [iqdb] [saucenao] [google] [report]

>PascalCase for functions
Like a true sandnigger who can't be bothered to look up standard library names
>typename = std::enable_if<std::is_arithmetic<T>::value, T>
That's not even how you're supposed to use enable_if lmao
>gimping a function to arithmetic types
Because who cares about classes which overload operator+
You put this thing in a class? Are you a pajeet by chance?
>passing cheap-to-copy arithmetic types by const reference
Ok, definitely a pajeet

>> No.79711864

Please update this to use concepts, reddit user.

>> No.79711904

Ok and? (You) me when the STDs are fully capable. Right now, MinGW works like a fucking beast nigger.

>> No.79711906

>write macros that function as generics
LOOOL please get a job and write good efficient code without linked lists fag, nobody ever creates shit like a + b when using generics in C++, C and C++ are 2 different languages anyway. When you write a huge codebase sadly OOP is an acceptable way to maintain, try creating something besides snake in C and see where that gets you. Unless your writing operating systems, portable libraries, or embedded devices code, C++ is very useful for what you need

>> No.79711933

everytime i post this a bunch of sepplaton personality programmers get mad and i love it

>> No.79711937

the smugness and stupidity in one post. so are you that moron going on about "c with classes?" I think I understand what it means now. you faggots just want closures basically.

>> No.79711939

Stupid nigger when did I say I write C

>> No.79711951

>Ain't nothin you can't write yourself using system calls.
the idea is to finish a project before all developers die of old age

>> No.79712036

Use whatever language you want anon, doesn't bother me, but don't shit on it if you haven't really used c++ besides what nerds on this site say. Only shit on c++ when you've worked with it for a few years, because it isn't the best language and I accept it. I am so glad I haven't had to reinvent the wheel what the std offers that a decent language should've had years ago. Write a program besides hello world then you'll see what we mean

>> No.79712049

I flip a coin. Heads I use classes, tails I use structs.

>> No.79712058

c++ has fairly low cost abstractions. Use them instead of wasting your life on small premature optimizations. The equivalent abstractions are more costly in other languages.

>> No.79712067

can you give an example of a reasonably large and important piece of software written following your mentioned ideals?
also, you have a wrong idea about what the standard library actually is. if the standard containers, iostreams, etc. don't fit your performance requirements, don't use them. either use 3rd party libraries or create yours for your specific application, or, hell use C.
do you think you can write large GENERIC pieces of code that happen to be the best fit in all SPECIFIC domains?

>> No.79712154

If I was writing software to those ideals I would just use C.
>do you think you can write large GENERIC pieces of code that happen to be the best fit in all SPECIFIC domains?
Yes because I'm not the C++ committee.

>> No.79712171

You will never be the gender opposite to that you were born as.

>> No.79712176

Maybe not the most overrated, considering it gets lots of criticism even from popular and influential programmers, but certainly the most overused.

>> No.79712194

>Yes because I'm not the C++ committee.
ok, post a few examples.
also, do you not realize that anyone can contribute to the standard? what stops you from submitting your own proposals or just deprecating the STL by showing us your remarkable algorithms/containers and implementations (post the git links).

>> No.79712198

honestly, I don't even know who's whoing who anymore and I agree with you. Most people get hot air up their ass about stupid shit that generally doesn't matter, and when it does, you just fix it, WITH REAL FACTS AND EVIDENCE (Profiling, etc).

I don't really like C++, but I hate C so much more and get pissed whenever I have to work with any C API.

>> No.79712227

nothing. he's a moron who probably already forgot how laden with shit his existing tooling has comparatively. Only shit thing about Rust is C++ already exists and permeates, that's Rust's only real fault.

>> No.79712250

the people that wrote it don't understand the fundamentals of compiler design. Its extremely slow and can't be fixed without a rewrite.

>> No.79712272

rust was de-funded right? Mozilla saw no value in it. Now its limping a long on public donations. I suspect will die in 5 - 10 years.

>> No.79712327

Since you are so dead set on seeing my work, here you go, a bit array:
If I removed the abstraction, it would be even faster if it was data orientated.

>> No.79712350

That's funny because shills like you can only talk about how bad C++ is instead of actually presenting some arguments in favor of Rust

>> No.79712404

Fuck you. so many reasons it would take too long to list.

>> No.79712508

rust tooling cannot scale in its current form

>> No.79712518

oh I remember you, you're that moron who complained about LTO

>> No.79712630

?? Not me. But it doesn't surprise me that a vast amount of people would find the tooling unsuable to any reasonable scale.

The tooling is good if you just want to make cute projects to put on your github page. It's not good when you're writing real software of significant size.

>> No.79712689

Quote >>79712250 says is exactly what I was gonna say, it's show as shit and takes ages to compile stuff. Also I'm not a fan of package managers but thats only my opinion, I like decentralization. C++ is also slow but rust is always much much slower.

Yep, nobody likes c++, not everyone truly hates it but nobody likes it, even C++ devs hate it sometimes.
look at most profile reports comparing C, C++ and Rust, they all tend to be similar, so similar, its usually nanoseconds off, C is indeed the fastest usually but its so close compared to C++ that you aren't really losing anything, and C usually has smallest filesizes.
The only reason to make a C api is to benefit both C and C++ devs. Make a library in C++ and C devs cant use it, but make it in C and everyone is happy, sort of. C++ definitely has better and easily extendable libraries, but it fucks most C developers in the ass who want or even need the library.

>> No.79712861

I'm not implying Rust tooling is not much better, it probably is.
What I'm pointing out is whenever someone brings this language up on /g/, the discussion immediately devolves into flinging shit over to the other side of the fence and LOOK HOW BAD C++ IS IT DOESN'T HAVE X.
>Well with rust I don't need to use CMake, LLVM tools and Nix
That's fine, that's the advantage of Rust. Next up we have
>muh c++ is not memory safe
>muh double frees
>muh c++ doesn't have a borrow checker
>muh better language benchmark game performance
That's literally all the collective known as rust shills on /g/ has. And you can disprove almost all of it too.

>> No.79712899

Srry, but how is not using CMake, LLVM, and Nix an advantage? You'd rather use a less developed buggy solution with a smaller community. kek

I agree with the other points.

>> No.79712992

Let me guess, you NEED more?

>> No.79713126

The anon's question was about writing generic code usable in all domains.
As it turns out, generic C++ libraries like Boost are widely used and in demand.
You don't even write any sort of tests for your bitarray.
Even without them I can tell where your class will leak memory
You don't provide a destructor for a class managing memory resources
Your class shouldn't even be called an array as you provide no operator[] overloads or any other way of accessing its specific elements
You don't even put this thing in a namespace to avoid potential symbol collisions
You're a fucking larper and you just outed yourself as one

>> No.79713205


>> No.79713320

There will be a lot of it in your memory since you can't even manage it

>> No.79713381

Miniscule for a bitarray. If I'm constantly allocating and reallocating, I'll notice :)

>> No.79713489

yeah, how about something conducive to a relevant piece of software? not something that proves you can indeed reinvent the wheel for a shitty school project

>> No.79713542

What useful generic code can you write that involves numerical limits?
You can't expect to use a foo<int>() and foo<long long>() the same way anyway.

>> No.79713876
File: 72 KB, 1390x1088, 314167436134.png [View same] [iqdb] [saucenao] [google] [report]

Fix it you nigger
And start using CMake already

>> No.79714169

this but unironically

>> No.79714210

It’s not strictly C though. Fucking Objective-C is closer to C than this shit.

>> No.79718651

41% chance.

>> No.79718728
File: 161 KB, 1446x1462, 1492726136759.jpg [View same] [iqdb] [saucenao] [google] [report]

just scroll and look at the fucking code samples

>> No.79718733

cute Katze, desu.

>> No.79718755

that ((nodiscard)) is fucking ridiculous
Couldn't it just be a plain keyword ? why add extra shit

>> No.79718796

>template<typename T, ...>
declares a templated function, that is to say one that can accept arbitrary T. the part in the ellipsis constrains the possible types of T but that version is a bit of a hack and replaced more elegantly with concepts in C++20.
enforces that the returned value must be assigned somewhere or otherwise used
indicates that the code can be executed at compile or runtime
deduces a type using information the compiler has
>const T& a
accepts a value named "a" of type T by constant reference, which is the preferred way to pass values in C++ (helps cut down on unneeded copies)
this function is declared to not throw any exceptions
> -> T
trailing return type. some prefer it for readability/style reasons, but it's also required in some cases for templated functions

>> No.79718951

>that version is a bit of a hack and replaced more elegantly with concepts in C++20
topkek that has been the same shit for the last 10 years at least

>doing this is a bit of hack but we'll fix it in next version
>next version is even more bloated

>> No.79718978

it's getting fucking retarded
at that point it's becoming just a meta-langage where you are describing how to define function rather than actually doing any shit

All these template shit make code reuse always fucking hard and usually not even possible anyway

>> No.79718981

well in C++'s defense nobody expected the upgraded macros to be turing complete, so a good chunk of work has gone into making language features that replace all of the abuse

>> No.79719048
File: 16 KB, 200x189, 1394241036255.jpg [View same] [iqdb] [saucenao] [google] [report]

>barely up to date with C++11
>now have to learn all the way to C++23

>> No.79719089

You’re a brainlet

>> No.79719094

>What's the point besides muh type safety
well it's mostly this; concepts are a bit easier to read and provide coherent error messages (some arcane instantiation error 15 calls deep in a template vs "this needs to be a number" up front)

>> No.79719107

template <std::integral T>
auto foo() {
auto x = std::numeric_limits<T>::max();

program more

>> No.79719153

C++ is just C trying it's hardest to be Ada and failing.

>> No.79719415

>if you look at any actual successful C++ programs you will see not only do they HARDLY use c++ features
LOL most successful programs are CLOSED SOURCE. You have no fucking clue what you're talking about.

>> No.79719529
File: 121 KB, 792x560, 1609502477317.jpg [View same] [iqdb] [saucenao] [google] [report]

What I dislike with C++ is how big the standard is.
There are so fucking many rules it's ridiculous
look at this shit : https://en.cppreference.com/w/cpp/language/constexpr
It's ok when the rules makes it not compile when you fail to comply, but then you have TONS of shit that you think are OK that are actually undefined behavior. You can temporaly remember all this shit but then you soon forget, and god forbid you are on a team of several members with different seniority level
It's probably why most project stick to "C with classes" shit, it's much safer than trying use whatever C++20 feature you don't really understand and that compilers fail to implement properly anyway

>> No.79719583

can't the "preprocessor" thing that computes constexpr value just try to compute them and fucking fails if it does any of this

>> No.79719651

your compiler has always been allowed to make guesses about optimizations like that (simple e.g. fold "2 + 2" into 4), but it's expensive.

>> No.79719682


>> No.79719732

it's the most (bloated+efficient) programming language yet released, and that includes c and rust. too bad.

>> No.79719737

just use C++ but don't go full autism with it
If you REALLY REALLY need performance just dissamble the code that was generated and try to understand why the generated assembly was shit

>> No.79719769

but he still spent
>30% of time trying to make it run and compile
>10% of time trying to navigate through files (top jej)
>30% of time adding constexpr autistically
>30% of time doing useless surface-level work

>> No.79719770

it's likely a breaking change. if there's anything i can really criticize C++ about it's being too autistic about backwards compatibility instead of telling people using C++98 to just upgrade their shit if they want to compile in 202X

>> No.79719779

Yes, because it was written in pre-standard C++.

>> No.79719801

>shittons of keyword to allow you to compute shit at compile time
who even does this? I mean, for non trivial shit
all I see is "muh factorial"

>> No.79719809

you may look into combining C++ and lua but don't fall into the trap where you end up using C++ just as bindings and you could have just written the whole thing in lua from the start. study other projects that use lua for modding or an extension language to see some good patterns

>> No.79719856

Lua is a bad choice, it is better to a single language.

>> No.79719880

"Computation at compile time" in practice actually means emitting specialized code based on the properties of types. The factorial example is always dumb because most people aren't doing things like that other than if they have some magic constants and want it to be clear how they were computed without any runtime overhead.

>> No.79719920

It's useful for prototyping or configuration that needs to be slightly more advanced than JSON/YAML but yeah don't throw that shit in a tight loop

>> No.79719976

>I still don't quite understand what "C with classes" means.
My interpretation of this is as follows, as someone who does embedded stuff in C++:
> Allows use of raw pointers instead of smart pointers
> Use of nice C++ features such as const correctness, references etc
> Use of classes with member functions to avoid passing `&my_fucking_struct` ala C around everywhere
> Use to templates for generic code
Basically code that still looks kinda like C, but is obviously C++. Check out the Haiku source tree, that's the closest I can think of that has a "C with classes feel"

Name (leave empty)
Comment (leave empty)
Password [?]Password used for file deletion.