[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 / qa] [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: c++.png (69 KB, 1200x1349)
69 KB
69 KB PNG
/g/ Help me out here. I'm trying to learn C++, but it just seems needlessly complex for no good reason.

Why is printing done with such in such a fucked up way?
Why do I need to define everything twice?
Why is everything a pointer or reference?
Why are lists called vectors?
Why does every line need a semicolon?

I can't beleive anyone uses this shit in real life.
Is it literally just so that C++ programmers can feel like le 1337 hackerman because they have to remember every little useless character they need to add?
>>
>>101362512
l'filtracion
>>
File: humiliation ritual.png (191 KB, 1228x1150)
191 KB
191 KB PNG
>help me /g/, there are 43 different types of hammers and this is so convoluted, I cannot figure out which one to pick just to hammer in a nail, aaa I'm going insane
maybe you should leave it to people who can memorize few dozen things, dumb jeet
>>
>>101362512
>it just seems needlessly complex for no good reason.
the reason is job security
>Why is printing done with such in such a fucked up way?
more complicated (oop) = more jobs
>Why do I need to define everything twice?
so it breaks more and you have to fix it more (more jobs, see above)
>Why is everything a pointer or reference?
memory used to be expensive
>Why are lists called vectors?
ye olde math jargon, the pseuds go nuts for it
>Why does every line need a semicolon?
ye olde parser logic
>I can't beleive anyone uses this shit in real life.
neither can I, and I bet secretly Bjarne can't either
>Is it literally just so that C++ programmers can feel like le 1337 hackerman because they have to remember every little useless character they need to add?
moar cryptic and fragile = moar jobs, simple as
>>
>>101362560
So why is it still used today? It seems like all this was because computers were shit 20 years ago.
>>
>>101362531
>maybe you should leave it to people who can memorize few dozen things, dumb jeet
Why should i have to memorize
std::cout << "fuck you" << std::endl;
when
print "fuck you\n" works just as well and is 10x easier to read
>>
you don't have a use case for using c++. try java instead.
>>
get better bait/brain
>>
>>101362619
>you don't have a use case for using c++
Does anyone?
>>
>>101362623
>Can't defend his shit language
>calls it bait
>>
>>101362635
yes. C programmers who want to invent C++ but worse can use C++ instead
>>
>>101362512
vectors are not lists, vectors are resizable arrays. You can use a list if you want with std::list.

They also finally added a formatting library, so you can use println() in C++23 now.
>>
File: 20231026_140141.jpg (1.03 MB, 3468x4624)
1.03 MB
1.03 MB JPG
While the thread is up, I'm learning C++ on my own (and I actually understand it), how do I turn this into a paying job without having to spend 4 years grinding out college to prove I can do it
>>
>>101362670
>vectors are resizable arrays.
Why not just call them arrays then?

>you can use println() in C++23 now.
How did it take until 2023 for them to add like the most basic shit? 100% unserious language
>>
>>101362602
out of all things you could pick to have filtered you, you chose to post weak bait
>>
>>101362722
>How did it take until 2023 for them to add like the most basic shit? 100% unserious language
I'll give you a hint: serious programmers who care about performance will never use this.
>>
>>101362759
It's not filtered me, I just want to know why they decided on the most retarded way of printing to the console.
>>
>>101362531
>he actually thinks it's good to have 43 ways to do hammer(nail)
Mental illness
>>
>>101362711
this, and checked.
>>
>>101362771
>the most retarded way
such as relying on standard library, white people will just use write syscall, and no, other operating systems are not relevant in HPC.
>>
>>101362792
You can't tell me this is anything but mental illness lol
>>
>>101362512
>Why is printing done with such in such a fucked up way?
Something something safety and extensibility, seemed like the best way to do it at the time, but the latest cutting-edge implementations now provide std::print/std::println as an alternative
>Why do I need to define everything twice?
Because this allowed C compilers to use less memory back in 1970
>Why is everything a pointer or reference?
Because much of the point of languages like these is to have tight control over memory. You need to be able to know where values are actually stored and what does and what doesn't copy or move them to other locations
>Why are lists called vectors?
Alexander Stepanov fucked this one up in the 90s
>Why does every line need a semicolon?
Resolves ambiguity, e.g. so that when the next line is enclosed in parentheses you know whether it's intended as a function call or whether they're just used for precedence

>>101362722
>The name vector in STL was taken from the earlier programming languages Scheme and Common Lisp. Unfortunately, this was inconsistent with the much older meaning of the term in mathematics and violates Rule 3; this data structure should have been called array. Sadly, if you make a mistake and violate these principles, the result might stay around for a long time.
>>
>>101362722
I agree that vector is a retarded name. but calling it an array wouldn't tell you anything about its added behaviour (there is std::array which basically adds bounds checking to the c-style array), and calling it a list implies a linked list.

>How did it take until 2023 for them to add printing?
I think mainly to keep up with new languages becoming popular in the same space that have nicer ergonomics. I don't think it's that important of a feature for most people using C++.
>>
>>101362824
mental illness is pretending to be a programmer while you cannot even setup your own buffers, your own buffering logic, and your own flushing to stdout or whatever using API provided directly by your OS.
>>
>>101362865
Been there done that but in most projects I don't need to do this because I/O isn't the interesting part
>>
>>101362884
>bottleneck in 100% of programs isn't the interesting part
hello nocoder
>>
>>101362512
>I can't beleive anyone uses this shit in real life.
There are people who still have to work with COBOL. Companies don't wanna bother with code that already works so you can't do a whole lot about that.
>>
>>101362896
It's a bottleneck in 20% of my programs at most. But when it is I pull out write(2) and writev(2) and mmap(2) and splice(2), don't you worry
>>
>If a programming language's semantics, that is, its keywords and built-in functions and so on, offer more than one way of doing the same thing, in the sense that the output of the code is identical with the same side-effects, it is in fact poorly designed. But if only the side-effects differ, I would argue the design is even worse. I have yet to encounter a single production language with no more than one way of doing any one thing.
>Now if you are young you may find this line of thought odd, after all, isn't diversity good? The answer is: seldom.
>>
>>101362948
did you know that even fizzbuzz is bottlenecked by I/O? But ok, tell us about your unicorn programs that are so slow that even I/O is faster
>>
>>101362512
>Why are lists called vectors?
The creator of vectors fucked up. He apologized, don't give him shit for it.
>>
>>101362983
Vectors aren't lists
>>
>>101363003
Nor they are vectors.
>>
>>101362983
>>101363010
std::vector has terrible performance, nobody serious would use one, why do you care?
>>
>>101363003
How would you call a relocatable contiguous piece of memory that holds many instances of the same structure?

>>101362830
>calling it a list implies a linked list
No, calling it a list implies a list. Only linked list implies the link part of the list, otherwise linked lists would be called lists.
>>
>>101362865
>having a sane print() in the standard library means you can't also use syscalls directly if you want
This is how C++ users actually think. That is, they don't think at all. No matter how many times they are shown working solutions for these things (even in their own language with c++23) they still cannot understand these basic things.
>>
>>101363063
Nobody mentioned their performance.
>>
>>101363063
I've heard this before but never looked into it. Do you mean the standard allocator or is there another reason?
>>
>>101363063
So the standard library has all this garbage in it, but it's also incorrectly named, so it cancels out and it's actually good?
>>
>>101362602
std::println("fuck you");

Stop reading outdated tutorials.
>>
>>101363089
if you don't care about performance, you aren't C++ programmer and should fuck off from this thread, nocoder
>>101363094
not only is default allocation pattern retarded, but every time the vector grows, it moves elements (memcpy with unnecessary and bloated overhead).
>>101363105
standard library is what separate boys from men, boys follow adultbabble like it's some holy grail of life, men do whatever they please.
>>
>>101363116
>standard library is what separate boys from men, boys follow adultbabble like it's some holy grail of life, men do whatever they please.
Ok, but surely you realize that you can have a sane good standard library that you can use when it's ok to do so, but also choose to not use it and do whatever you want when it actually matters? It seems like you'd obviously get the best of both worlds.
>>
>>101363199
>but surely you realize that you can have a sane good standard library
never experienced this in my entire life despite tinkertrannying with over 30+ programming languages in my life and deciding to stick to C++ and reinvent things when I need them.
>>
>>101363063
It's better than whatever retarded shit anyone on this board can shit up in C.
>>
>>101363506
so this is your best cope, it's better than equivalent in a language that has no features?
How about this: I program in C++, and I don't use std::vector, because my implementation is better? Seethe faggot.
>>
>>101363534
Prove it.
>>
>>101363615
just stick to std::vector and don't worry about it, your fizzbuzz will never need more
>>
>>101363624
Post code or scurry off.
>>
>>101363630
which implementation do you want me to post?
>>
>>101363634
The fastest one.
>>
>>101363638
what is that supposed to mean? They're all fastest in their usecase.
>>
>>101363634
>which implementation
it's a fucking list you retard, you're not god for doing bespoke list implementations nobody gaf how "blazingly fast" your fizzbuzz is
>>
>>101362512
you're not supposed to write code you're supposed to write templates that make the code for you
>>
>>101363657
and yet you can't make it good and fast, not even people who implemented std::vector, curious
>>
>>101363670
you're cumming your pants; premature optimization. this is not a difficult problem and if you're 'implementing' anything you're the slowdown brother, you are not more cracked than vector primitives
>>
>>101363725
>premature pessimization
good morning sar
>>
>>101363670
wow you're so nice at c++! so smart! have a gold kind stranger!!
>>
>>101363743
>premature pessimization
look dude if spamming bespoke list implementations makes you feel smart instead of using stdlib or faster vector primitives go for it, just know you write unreadable unmaintainable code and nobody likes working with you
>>
>>101363799
there's nothing fast about constantly copying memory as the list grows
>>
>>101363814
stop doing that then retard
>>
>>101363814
And yet deque is always slower, curious
>>
>>101363831
yes I stopped using std::vector
>>101363835
it was implemented by same retard who implemented std::vector so I wonder what's the problem
>>
>>101363814
>wahh my list so fast
>is growing the list
???
>>
>>101362602
Because c++ is retarded.
Use C
puts("Fuck you");
printf("Fuck you\n");
>>
>>101363839
you're too autistic to give up a few ms in places where it doesn't matter and too retarded to use vector primitives when speed actually matters
>>
>>101363856
yes, my list grows infinitely without copying
>>101363884
>doesn't matter
ok wagie, go back to java
>>
>>101363116
Thanks anon, just wanted to clarify: Does it literally memcpy each element individually? If not, and it just copies the entire block, what would be the better way to account for reallocations?
>>
>>101363897
it doesn't use memcpy, it moves each element individually and that includes running constructors and destructors for each when all you wanted to do is to add data at the end of the list
>>
>>101363896
>list grows infinitely
no it doesn't you're coping
>ok wagie, go back to java
either a sophmore cs student or jobless cause you refuse to make your code follow convention, maintainable or readable
>>doesn't matter
you are obsessive and unlovable, probably unemployable too
>>
>>101363896
lmao no but at least java devs ship shit instead of sperging out over list implementations and getting it wrong anyways
>>
>>101363994
>getting things wrong
I see you have a lot of experience with this...
>>101363983
>muh conventions of code being slow and unmaintainable mess
>>
>>101364023
>I see you have a lot of experience with this
you use a bespoke implementation for speed; that's getting it wrong. you are not faster than vector primitives, just more autistic
>unmaintainable mess
yea man im sure spamming bespoke list implementations is so maintainable, way better than a standard library to be sure
>muh conventions
it came free with your fucking language with a syntax dipshit. you just use your own retard conventions unique to your autism cause you refuse to cooperate with other people
>>
>>101363896
>>101363814
is he sperging over how fast he can GROW a list???
>>
>>101364153
>>101364142
my implementation grows as fast as my kernel can resolve page faults, I don't care if this filters you, cope you worthless nocoder
>>
>>101364153
lmfaoo C++ wizard
>>
>>101363920
Are you pretending to be retarded or a dunning Kruger?
Vectors, like any dynamic array implementation, maintain a private memory buffer larger than the public "size", if you append an element, it only does a malloc + memcpy if it needs more memory than the internal buffer.
If you call .reserve() with a size, you can manually specify how big to make that internal buffer if you know up front.
It only calls move constructors when its not trivially copyable, ie a vector<int> will just be a memcpy. How about learn about stuff before saying stupid shit about it.
>>
>>101364183
my implementation never needs to do malloc + memcpy, how about learn about real programming before you project?
>>
>>101364209
You made a dynamic array that doesnt use dynamic memory allocation or memcpy?
I'm literally laughing rn
Post it please, I cant wait to laugh even harder about your profound invention
>>
>>101364231
Yes, I have, are you going to shit your pants and seethe just because you're so low IQ you cannot fathom how?
>>
>>101364236
Still didnt post it
Go on, we're waiting, dont be shy
>>
>>101364166
taking pride in writing code so unreadable you think you're filtering people with a fucking list just to make it slower than vector primitives
>>
>>101364244
there's nothing to post, as my OS provides it natively
>>101364254
my code has same interface as std::vector, so I'm not sure how it's unreadable, sorry that different type name filtered you this hard
>>
>>101362512
>Why does every line need a semicolon?
How the fuck do you expect the parser to know when your statement ends?
>>
>>101362512
>Is it literally just so that C++ programmers can feel like le 1337 hackerman because they have to remember every little useless character they need to add?

exactly like this . Its like a cult. Get some retard t invest enough time in to figuring out garbage language. After he invests huge amount of time he will be emotionally tied to it and will never admit there could have been a better way.
>>
>>101364263
>filtered you
you're imagining things. You haven't posted any code to filter anyone
>my code has same interface as std::vector
thinks the implementation doesn't matter hehe

still slower than vector primitives retard
>>
>>101364306
>there could have been a better way.
I'm still waiting for better way, until you make a language better than C++ I won't care
>>
>>101364316
>redditspace
I accept your concession.
>>
>>101364319
>until you make a language better than C++
presented without commentary
>>
>>101364263
>hurr if I just provide page table size memory blocks to every array no matter how small, I never copy memory!
Absolute galaxy brain invention, bravo. Never mind the overhead of system calls every time you create an array lmfao
>>
>>101364340
>every time you create an array
I did some basic thinking (I know, it's hard, but bear with me) and I noticed that this happens very rarely as I am intelligent and can just reuse them.
>>
>>101362531
jeets can actually memorize. Memorization is used by persistent midwits to filter creative logical poeple.
>>
>>101364330
newfag thinks everythings a redditspace. it's called a linebreak, it seperates ideas from eachother.
>>
>>101364330
how

this

make

you

feel

white

boy
>>
>>101362781
sepples handyman needs a truck to carry all of his tools.
>Tries to pick up a screwdriver
> 4 hammers drop on his foot
> screwdriver is actually a big tweezer
>>
>>101364330
>all it takes to end a reply chain is shift + enter
I've been here for a decade and its so fucking retarded any discussion will boil down to this a sum 30 IQ enters the thread
>>
>>101364407
you don't have to do shift + enter to put a linebreak you can just hit enter
>>
>>101364407
yes, I will judge your intellect on your inability to avoid doing reddit thing
>>
>>101364474
stop reddit breathing
>>
>>101364495
You just lost the game newfag, see you next decade.
>>
Newfags whine about le reddit spacing to try to fit in.

Fuck off.

Appreciate the gold, kind stranger.
>>
>>101364474
HOLY FUCK NOT EVERY LINEBREAK IS A REDDITSPACE fucking tourists ruining this damn website
>>
>>101364522
Indeed, I like some linebreaks.
Just not reddit ones.
>>
>>101364541
You sir have won the internet for today!

Anonymous! Wow he really is posting anonymously! Username checks out!!!

Here have a gold, kind stranger!
>>
>>101364578
Is it really so hard to not redditspace?
>>
>>101362512
This is original
#include <iostream>

int main() {
// Write C++ code here
std::cout << "hello world" << std::endl;

return 0;
}


to remove std just do this

#include <iostream>

using namespace std;

int main() {
// Write C++ code here
cout << "hello world" << endl;

return 0;
}


here now you don't have to complain.
>>
File: 1720028265457295.jpg (59 KB, 1049x737)
59 KB
59 KB JPG
>>101362560
>>
>>101362512
semicolon because why not and even if you forget compiler will tell you.

vectors question is brainrot.
If you get filtered by pointer leave computers alone and go buy iPhone that's enough for you.
>>
C is better. Anything you can do in C++ you can just rewrite in C.

Faggots will tell you to use C++ selectively but this is wrong and using the shortcuts of C++ will only give you bad habits and a poor understanding of computer science.

My arrays are called arrays and my vectors are called vectors. Fuck you Bjarne.

Rust does everything C++ does but better and it's still shit.
>>
>>101364671
Rust is for troons and forever will be.
>>
>>101364606
trying to fit in still, just obsessive and retarded
>>101364646
found another linebreak, come derail the thread again faggot
>>
>>101364686
Cry more rust troon.
Your shitty crap troonish language isn't going to get better.
>>
>>101364680
you a real dumbass if you still think this in current year
>>
>>101364698
People even track troons like you.
https://rustroons.netlify.app/
>>
>>101364694
wrong reply gang
>>
>>101364703
this is just a random website with 10 github links and some pronouns.
seems kinda creepy and obsessive, are you the chaser that wrote this?
>>
>>101364703
>contributions
> trannies + tranny lovers = 40%
Kekkkk
>>
>>101364750
it's not even the funny number are you retarded
>>
>>101364750
troo troo TROOON
REDDIT TROOOOOON
>>
>>101364703
oh my god this is a manually compiled list, i can't look at this without imagining the most mad guy ever furiously typing this shit up
>>
>>101364754
TROON TROOOOOON TROOON YOU ARE SOOOO TROOONY THERE ARE ONLY TWO GENDERS !!!!!!! YWNBAW
>>
>>101364793
I'm glad to.see you understand
>>
File: jej.png (11 KB, 640x734)
11 KB
11 KB PNG
>>101364777
>>101364793
we did it anons, we mindbroke xer
>>
>>101364793
???
>>
>>101364777
that is very much me
>>
>>101364799
jewish hi-five!
>>
>>101364646
>If you get filtered by pointer leave computers alone
If your language makes something retardedly simple as pointers difficult even for a kid then your language is garbage.
>>
>>101365049
>if your language cannot be used by sub 60IQ sub-saharan niglet whose body is shutting down due to starvation
sorry I live in first world country and I am highly educated adult with IQ above 130
>>
>>101365073
and you're using it to write fizzbuzz with memory leaks
>>
>>101365290
>fizzbuzz implementation that allocates memory
?
>>
>>101362602
>std::cout << "fuck you" << std::endl;
that's wrong btw you don't use std::endl at every print because std::endl flushes the buffer and that's bad for performance
you shoud do
>std::cout << "fuck you" << '\n';
or better yet do what
>>101363108
says and use a newer C++
or better yet use the fmt library on which this was based on, but it still yet has more features

>>101364615
absolutely retarded
never do using namespace std;
the whole point of creating the std namespace was to avoid collisions with the global namespace
>>
>>101362512
>needlessly complex for no good reason
Low level languages are more complex because they give you the freedom and opportunity to control virtually every aspect of your program. You can plan out exactly how your data is structured in memory, how it is allocated and destroyed and to what degree you want to involve abstractions that cause random access vs linearly structured data.

Basically everything javascript doesn't care about doing efficiently C/C++ allows you to control. If you don't want that control, stick with javascript.
>>
>>101362583
>So why is it still used today?
Because efficient code is extremely valuable. From both a UX and a business perspective.
>It seems like all this was because computers were shit 20 years ago
20 years ago computers were already powerful as fuck. The difference 20 years ago was that the javascript ecosystem was in its infancy.
>>
>>101367132
Rust troon.
>>101365049
Rust troon.
>>101364799
Absolute Rust troon.


Absolute state of /g/ 3/4 quarters of this fucking board are troons i can't ... it's literally fucking over.
>>
>>101362711
>how do I turn this into a paying job without having to spend 4 years grinding out college to prove I can do it
Build something in C++ and show it off. Doesn't really matter what you build as long as you make it visible and can talk about it at different levels of technical depth.

If you have an idea of what kind of C++ you want to be writing (OS development, game development, native windows apps, etc) then that makes the project decision a little easier.
>>
>>101362722
>Why not just call them arrays then?
Arrays are already a defined concept in the C world. Vectors are a wrapper on top of C arrays. C arrays are not dynamically allocated and cannot dynamically grow.
>>
>>101362583
>>101362512
C++ is supposed to squeeze every bit of performance possible while still allowing very complex programs through OOP etc
There is absolutely no need to learn it for an average programmer/webshitter, only if you are in a field where max performance is critical
Yes it is hard compared to python, but if you were in such a field, you would realize the least hard part about it is C++ syntax

It is a whole different world of programming where you actually need to know everything by heart and understand it perfectly
Not just copy pasting shit and tweaking it till it works like common webshitting
>>
>>101363063
>>101363534
>>101363624
>>101363634
>which implementation do you want me to post?
>>101363652
>>101363670
>>101363743
>>101363814
>>101363839
>>101363896
>>101364023
>>101364166
>>101364263
>there's nothing to post, as my OS provides it natively
>>
>>101362560
tpbp
It's basically a thing still because of baby duck and it was a thing back when because C is objectively worse for most actual applications.



[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.