Hey Jow Forums, I'm currently learning c++ and I was trying to redo some of this year's AoC to get some practice. As babby's first program I redid day 1, originally done in MATLAB, and this is where the mindfuck begin. I know my MATLAB solution was retarded and there are much better and faster ways to find duplicate numbers (pls no bully). However, I wanted to first use a direct translation to compare c++ and MATLAB speeds. To my surprise, the ultra fast c++ was 10x-20x slower than Matlab. Here is the code (pls no bully): MATLAB: jprev=length(sum); iprev=length(sum); for i=1:length(sum) for j=1:length(sum) if sum(i) == sum(j) && i~=j if max(i,j) < max(iprev,jprev) result=sum(i); jprev=j; iprev=i; end end end end
C++: int imin = len * 150; int jmin = len * 150; int value; for (i = 0; i < len * 150/2; i++) { //find(freqact.begin(), freqact.end(), freqact[i]); for (j = 0; j < len * 150; j++) { if (freqact[i]==freqact[j] && max(i, j) < max (imin, jmin) && i != j) { value=freqact[i]; jmin = j; imin = i; }
} }
C++ was run through Visual Studio. What the fuck? I thought C++ was supposed to be the fastest
>I'm currently learning c++ Found your first problem. Learn anything besides that.
Joseph Cruz
C# ?
Lincoln Ramirez
You're probably running c++ in debug mode, try in release
Noah Johnson
Well microsoft Java is not a good choice either. Learn anything besides C++,C# or java.
Jonathan Moore
why not C++?
Sebastian Hughes
You know, I'm having my doubts about this as the learning curve is pretty steep and the documentation sucks, however I already know Matlab and Python, and i'd say they cover my scripting needs pretty well (MATLAB for academia, control systems and proprietary libraries, Python for its ease of use, syntax machine learning and open community). C++ covers my need for a lower level language and basically these three languages are used for 99% of the stuff in my field (automotive C/C++ is widely used in empbedded, ECUs, etc and i already know some C). However i'm not sure if a slight boost in my curriculum is worth the hassle of learning C++, as this is something i'm doing in my spare time while i study more strictly automotive related subjects
Ryan Parker
Oh forgot to mention that i also like programming to some degree, I know that anything besides MATLAB won't relly boost my curriculum that much to be worth putting up with unless you actually like doing that
Jaxson Gonzalez
And we have a winner. It is now 100x faster than MATLAB. Please excuse me for my retardation
Dominic Anderson
You know you can export matlab projects as C++ code, right? Then you don't have to confuse people with arrays that are 150 times larger in C++ code. And you should also compile with C++17 and -Ofast
David Powell
>automotive C/C++ is widely used in empbedded Just learn C, you'll need it sooner or later in that area anyway.
Jackson Young
C++ is the most overly complicated clusterfuck of a language ever concieved. The main "features" that it has which are supposed to make you choose it over C are classes and exceptions, which are both useless. Go look up what any famous programmer has to say about it like Linus, Stallman, or Rob Pike. Focus on C.
Carter Lee
If you want some more motivation to learn C++, I would encourage you to not use visual studio. Sure it is adapted to big projects, but one aspect of learning C++ I found really interesting (and useful) is its more low-level aspect, and the things you learn about how programs work (be it memory management, or threading, or even the compilation process). If you run Windows, it might be less practical, but even then, working via command line, with just a compiler and a make-like program; I found to be a really enjoyable way of learning C++. Do not worry about the "steep learning curve", except if you want to become godly proficient, C++ is actually quite easy to learn, do it slowly and enjoy learning how the whole machinery works :)
Daniel Smith
length(sum) is 150 *len
Nathaniel Martin
>C++ is the most overly complicated clusterfuck of a language ever concieved. It's the easiest language to write zero-overhead abstractions in. You can write different code that compiles to the same assembly, meaning you have more freedom of expression. It's only complicated if you're writing a compiler. Else, stick with the latest standard and you'll be writing as easily as in java. The syntax is dead simple. >classes and exceptions are useless Classes and namespaces enable more powerful static analysis and easier code reviews. Exceptions do what errno can't. >famous programmers Famous C programmers, hence irrelevant.
Basically, learn C++. You can do anything and everything. C expects you to care about lower level garbage but doesn't even let you allocate on the cache or register, so it's junk in the end.
Jacob Campbell
Well my uni has a mandatory C course and i aced it, so I already know something about that. I'm obviously not a pro or anything and the exam i took was something like 3 years ago, but i wanted to learn something new. Also outside of embedded systems C doesn't really have much use, while C++ is still one of the most used languages. Finally, game development interests me (even though i'm not really playing that much these days) but i'm not sure i can sustain it as a hobby.
Aaron Peterson
I have Manjaro on another disk with VScode and emacs but as a noobie i found Visual studio much easier to set up. Still planning to switch as it's retardedly complex for things like AoC or babby's learning programs
Xavier Flores
>classes and exceptions are useless so the only reason C got pretty much abandoned in embedded and high performance programs is useless?
>C got pretty much abandoned in embedded What are you smoking?
Ryder Turner
Okay but call me in 10 years when people start using it.
Hunter Wilson
>i_dont_have_a_job.txt
Caleb Nguyen
I would highly recommand it; at least at first to understand well the clusterfuck that is compiling multiple C++ files. I've tutored C++ exercise sessions at my uni for two years now, and this one of the topics I found really important to grasp correctly.
Joshua Harris
What shithole company do you work for that still trusts C?
I'm in school so I'm not looking for a job yet. Hopefully there are jobs out there for people who want to write in noncancer languages like C,Go or Python. Worst case scenario I'd take a job as a web developer writing javascript or even writing java before a job where I have to use C++.
Jacob Brooks
>1 safe program in C++ Whatever operating system you're running on was entirely compiled on a compiler written in C++.
Robert Price
>I'm in school >Gives advice on what programming languages to learn
Mason Martin
>hurr durr c++ clusterfuck
This was maybe true a decade ago, but since C++11 majority of the bullshit got fixed. And if you are starting a new project, no legacy codebase, there is no reason to not use C++17, which is pretty comfy. C++17 standard library + maybe some boost is lightyears ahead of C.
Liam Torres
But user, what if he's running Win10 or MacOS?
Easton Howard
What do you think those are compiled on?
Jose Ross
Yeah, so what? I use programming languages a lot even if I'm not getting paid for it yet.
Kevin Hughes
Your opinions are not valid because you're never participated in a project where the language matters. You've never had to sit down and think hard about the consequences of every design choice. For you, languages begin and end with runtime speeds and all projects are written in a few days and deleted.
Connor Scott
>reading comprehension I've written *safe* program, not *a* program. A safe compiler is CompCert, which is written in OCaml/Coq (unfortunately for you).
Henry Roberts
Okay, can you point me to some examples of unsafe code in GCC?
Aaron Torres
>C is actually safe.
Are you joking? C is constantly one forgotten buffer_size or pointer delete away from memory fuckups. At least C++ has RAII and size aware data structures that prevent majority of similar bugs.
m8 why the fuck are you giving advice then you literally don't know anything lmao
Andrew Evans
Put your the len * 150 value into into a variable in C++ and put the length(sum) into a variable in Matlab. In yout case, I think matlab keep the length(sum) in cache and C++ compute the len * 150 at each iterration
Michael White
Alright, explain why C#, C++, and Java aren't good languages to learn
Luke Moore
Sure can. All of it. A code is unsafe until you have proof that it is safe. You don't get this with C++, unless you restrict yourself to C (even then nobody bothers using C++ for safe code because the few details where it differs from C do matter). No. Only safe code i've seen is produced either by proof assistants, or C , Ada and fragments of assembly. Never seen any other language produce safe programs, chances are i never will. >RAII and size aware data structures that prevent majority of similar bugs Yeah, because firefox or chrome isn't a leaky gaping asshole riddled with memory bugs. To degree where firefox invented new language to fix their shit (unsuccsessfully).
Cameron Green
unfortunately c++ is used plenty in embedded, at least where i work bootloader is mostly c and some assembly, most firmware and base functionality is c++ its messed up, but its for muh abstraction and ease of use for the higher level developer retards making the application software (they use c++ and also simulink/matlab and convert it to c or c++) although enum classes are a gift from God, they're the only good thing about using c++ for this shit t. embedded software developer
>A code is unsafe until you have proof that it is safe. Is that a fact? Sounds like an opinion.
Cooper Wood
>muh leaks Check out the GSL not_null - no more nullptr deref owner - no more leaks (or use smart pointers) optional - no more crashes from exceptions span - range checked alternative to pair
And lots more. If your code passes unit tests, it's safe. If you think it's unsafe, tell me which unit tests are missing or which ones are wrong. Again, show me parts of GCC that are unsafe.
Isaiah Baker
that's an opinion, code is never safe
Joshua Lee
C++ is so complicated you'll never learn it. Java is verbose and slow. It forces you to use classes for everything you write which often makes you write a lot of stuff in a weird way and you normally have to write a whole of boilerplate code. It's just not fun to write programs in. C# is a clone of java.
Adam Wilson
>Only safe code i've seen is produced either by proof assistants, or C, Ada and fragments of assembly
The only actually safe code is the one from proof assistants, or extremely small toy fragments of other code. Anything else is only thought to be safe with some probability, and very often a bug is found later in such code you thought was safe. This applies to all code, including one written in C, Ada, Go, Rust and .
>code is never safe But what proof do you have. Every day, my kernel passes over the exact same code UINT64_MAX amount of times and no errors show up.
Carter Richardson
>your mental gymnastics skill has improved *safe* has a very specific meaning you webshitter. >If your code passes unit tests, it's safe. Oh and i was wondering why there are so many bugs in software these days. This unit test = safety mentality is frankly cancer. No, your code isn't safe unless you have proof that it is safe Passing tests doesn't constitute a proof, it's merely evidence. >code is never safe That's not quite right either. Code can be safe wrt. its specification + some simplified environment model. Which doesn't mean it will never fail (a cosmic ray flipping one bit in PC register can easily make it fail).
Benjamin Green
You're the one making colossal statements, you have to provide colossal proof. It's on you.
Cooper Price
Idiot. If your are developing for critical systems, where a mistake can end lives, or worse, having a capital meltdown, you would say you program is safe because a language compiler told you so? Because it looked well? These kind of programs go tjrough really rigourous testing, theorem provers are used ti prove their semantics, all their mem usages is evalutated etc. C++ is simply too complicated to go through all that. C eases the pain. Also the software that is on your comercial planes have to do thousand of hours in smaller private plains before getting there.
Gavin Gray
>Java is verbose true, although recent versions of Java have type inference which cuts down on a lot of boilerplate >Java is slow Slow when doing what? Compared to what? This sounds like the opinion of someone who hasn't used java in over a decade, so I assume you're parotting a teacher/someone on this board >Java requires boilerplate Literally where >C++ is complicated >Java is weird >Java isn't fun >C# is a clone of java Stay in school
Gabriel Flores
>You're the one making colossal statements No, honey. That would be you - claiming a program is safe is *quite* a colossal statement. See how much work went into SeL4 proof. By default, all code is unsafe. If you want to claim it's safe, provide proof for it.
Noah Robinson
>By default, all code is unsafe. If you want to claim it's safe, provide proof for it.
THIS.
Hudson Adams
Unity tests is not for safety. It's a way to specify use cases. It only passes or fails the tests you specified. Which means it's a bunch of crap. It has it use in big software houses because of refactorings, if you checkout the big promores of TDD they all say the big reason is refactoring, with those tests you get to understand clearly what the original code was there for, and what use cases the original author thought of. Nothing to do with safe. If you ever had some decent math class you should know uçthat you don't prove something is right just by giving examples. Giving examples is the only thing unit test does.
Daniel Baker
nearly every single thing you've said is wrong.
Easton Campbell
>If your are developing for critical systems, where a mistake can end lives, or worse, having a capital meltdown, you would say you program is safe because a language compiler told you so? Because it looked well? Static analysis on C++ is good enough to warn me about potential overflows, dangerous conversions, and general lifetime uncertainties. Standard and GSL containers and functions already do range checks and RAII guarantees proper automatic lifetime management. By all means, none of this is achievable in C. I can use your struct without initialising it and nothing will ever warn me. Can't do this in C++ because of RAII. C is simply dwarfed by C++'s compile time feature set. It's not complicated, you just don't have the brains to understand it. >provide proof All done by itself nowadays. C++17 is an order of magnitude beyond C's default capabilities. I just have to write a bash script to go over large permuations of inputs, and bobs your uncle. There is just no place an error can pop up from with proper C++17 code written by professionals.
You're just being grumpy about firefox's use of naked new and delete and other garbage left over from C's legacy days.
Ayden Clark
>true, although recent versions of Java have type inference which cuts down on a lot of boilerplate Didn't have that last time I used it but that isn't enough to get rid of all the verbosity I remember. >Slow when doing what? Compared to what? This sounds like the opinion of someone who hasn't used java in over a decade, so I assume you're parotting a teacher/someone on this board Compared to languages like C and Go it's slow. I know it's not as slow as it used to be though so maybe I should have said that it's not fast. >>Literally where Aren't you supposed to use gettters and setter methods just to change and retrieve the value of a classes variable?
Jordan Cruz
>decent math class I've taken all the math classes you have, guaranteed. What I'm saying is C++17 (along with static analysis and other automated processes) eliminates entire domains of errors. Unless you discover some entire new class of bug, code that's currently being written is A-OK. There's just no place for errors to pop up.
Jayden Rogers
All those things given by C++ must properly be tested and proved as well. I won't run on a comercial plane any time soon.
Zachary Scott
>given by C++ Not my abstraction, not my problem. That's why I'm asking you for examples. >commercial plane That's okay, C++ powers the F-35 and other air vehicles
Adrian Watson
>C++17 is an order of magnitude beyond C's default capabilities.
This is true, Modern C++ is much safer than C, or the old "C with classes" C++ style (which was the worst of both worlds).
But
>There is just no place an error can pop up from with proper C++17 code written by professionals.
Is not true. Properly used C++17 indeed makes whole classes of bugs impossible, but not all of them. And this assumes proper usage, even professionals can still make mistakes.
Nolan Smith
>All done by itself nowadays. Where? >C++17 is an order of magnitude beyond C's default capabilities. Maybe wrt. expressivity. >I just have to write a bash script to go over large permuations of inputs, and bobs your uncle. *proof*, not _evidence_ you mongoloid. >There is just no place an error can pop up from with proper C++17 code written by professionals. And you know this how? Show me the proof. >You're just being grumpy about firefox's use of naked new and delete Chromium, clang, whatever c++ project. It's all the same - none is safe. This goes for rust too - until there is proof of correctness for borrow checker, rust is not a memory-safe language.
Benjamin Perry
>C++ powers the F-35 Oh finally we're in my domain. The safe code in F-35 is still written in Ada and fragments of assembly. There are severe restrictions on what you can do in C++, effectively making it about equivalent in features to the subset of C in JAS 39. Sure, all of the new supporting tools were written in C++, i give you that.
Aiden Fisher
>Where? Already mentioned. >expressivity Auditable correctness. >proof, not evidence Yes, unit tests provide proof your program works for that use case, retard. >Shwo me the proof. Okay, standard library containers have range checked accessors, and have automatic lifetimes, for instance. >none is safe. Proof?
You can't shift the burden of proof like that and you're yet to provide a single shred of evidence that GCC is unsafe.
Jose Russell
So you agree with me that proper C++ is not unsafe, yet still believe all C++ everywhere is unsafe? Retard.
John Miller
>Aren't you supposed to use gettters and setter methods just to change and retrieve the value of a classes variable? In the same way that you're supposed to use them in any OO language, yes. Don't like it? use Lombok.
Hunter Allen
>Already mentioned Nowhere did you mention proof. I don't care about evidence, i want proof. >Auditable correctness. [laughing_emoji.tiff] >Yes, unit tests provide proof your program works for that use case, retard. No, they don't. They *prove* that your program worked for given input *on given machine, and given run*. >Okay, standard library containers have range checked accessors, and have automatic lifetimes, for instance. Afaik none of these were proven. See rust borrow checker. >Proof? Axiom. Code is unsafe by default, if you want to claim safety, prove it. >proper C++ If your idea of proper C++ is "strict subset of C", then still no. It is unsafe by default, but it's possible to prove its safety. At this point we're talking about C though, so... None of the C++ features can be used if you want to feasibly verify your program, so you're basically writing forward-flowing C with strictly stack-allocated data and dozen other restrictions that allow model-checkers to finish verification within lifetime of our universe. >C++ everywhere is unsafe? Indeed. C++ that's not written as C is unsafe everywhere. There are instances of C++ written as C that are safe, but i take those as C since they are effectively C.
Ethan Lopez
what a cringe fest, youre both retards
Caleb White
Hush, adults are talking. Go eat some crayons.
Jacob Thompson
>so you're basically writing forward-flowing C with strictly stack-allocated data and dozen other restrictions that allow model-checkers to finish verification within lifetime of our universe.
Such small toy programs can indeed be proven to be correct, even in C. You just cant expect to write any serious application that way. Its an academic exercise completely disconnected from 99% of real programming practice needs.
Grayson Ross
>on given machine Not my problem, blame the compiler if anything happens. >given run You suspect standard container behaviour changes between startups? >none of these were proven Proven to be what? It's all open source, retard. >code is unsafe by default That's not an axiom because you say so, it's an opinion. If that were slightly true, you would have some shred of evidence to at least slightly convince anybody that, for instance, GCC contains unsafe code. >C++ written as C There's literally nothing stopping me from randomly massacring your crappy structs by calling whatever whenever wherever. C++ forbids domains of bad code about 25ms after you write it, that's before any human touches it. And it works on megabytes of files at a time and on human-unreadable code.
Samuel Butler
>Such small toy programs can indeed be proven to be correct, even in C I wouldn't say 100kloc is a small toy program. That's the order we're talking about. >Its an academic exercise completely disconnected from 99% of real programming practice needs. I'd say aerospace is pretty damn big industry with a very real programming practice needs and we usually use model-checkers that require us to resort to these restrictions. SeL4 went with theorem provers and built quite formidable platform for it though, so you can definitely do it for a "usual C". And with languages like Idris, it's becoming pretty realistic to write safe programs (wrt. reasonable specifications, not quite safety-critical levels yet, but a very reasonable high-level specification). >Not my problem Oh so you actually have no proof that it works. >blame the compiler if anything happens So the compilers you tout as safe can actually fail and you *count with that*. Huh, where did all the safety go? >You suspect standard container behaviour changes between startups? Yes, especially in multithreaded environment. I had my dose of verifying concurrent (lockfree) structures in those environments and let me tell you, it will happen. Also, you have given no proof that it won't. I have to assume the worst about code that has no proof attached. >Proven to be what? Safe. >It's all open source, retard. And i haven't seen them include any proofs, unfortunately. So it's still unsafe. >it's an opinion It's a fact. A matter of definition. Safe code needs proof that it is safe, without it it can't be called safe. >evidence to at least slightly convince anybody that, for instance, GCC contains unsafe code. I'd say any reasonable software engineer knows that code without proof is unsafe. But the bugs in gcc over the years should be enough to convince you that gcc indeed is not safe. >C++ forbids domains of bad code It's compatible with C, so it certainly doesn't. I can massacre your classes in C++.
Kevin Hughes
asking here instead of in a new thread: anyone have the final aoc calander pic for this year
Nicholas Smith
>Oh so you actually have no proof that it works. I'm completely neutral and ignorant, and want you to show me proof or at least evidence it's unsafe. >can actually fail Not that it's been reported for the current version of GCC by the smartest people on the planet. >multithreaded Procedural code is statically checkable code is safe code. If you need speed, get a better processor. >have to assume the worst about the code Oops here's that word. It's on you, you have to go and prove whatever you're assuming. >proofs Literally proofs about what retard? std::vector::at() checks your access. >a fact. A matter of definition. If you turn on the most pedantic flags and use the most popular static analysers, it simply won't compile. >I'd say That's a yikes from me. I'd say code that passes unit test that largely outnumber everyone's usecases is safe enough. >over the years Well don't use an old version of GCC. >I can massacre your classes in C++ How, reinterpret cast? Yikes, your entire line is now underlined red.
Lucas Reed
>currently learning c++ weird flex but ok
Isaiah Clark
samefag
Angel Reyes
lmao
Joshua Sullivan
You're full of shit, you're just parroting opinions that you've heard on here and on reddit. C++ is a legitimately good language if you don't abuse some of its unusual abstractions, STL or Boost. RAII is seriously underrated by a lot of C programmers and it is something that has saved me a shitload of times. If you haven't finished school you shouldn't have these strong opinions, you should be learning as much shit as possible and targeting some of the different programming languages to learn how to do stuff in languages that don't allow you to do shit the way you normally do it. Haskell and Rust are pretty cool to learn even if there aren't any jobs in it and the more I've been looking at Racket the more I want to code some shit in it. >Python Honestly outside of extremely high level tasks I hope that people who write large amounts of dynamically typed code fucking kill themselves.
Julian King
This thread is a complete disaster
Austin Perez
The only thing missing was (you)
Nolan Hill
I'm OP. I'm fucking bumping my own thread because an extremely autistic samefag ruined it.
Gabriel Parker
>show me proof or at least evidence it's unsafe Here goes: your code lacks proof of safety, so it's unsafe. >Not that it's been reported for the current version of GCC by the smartest people on the planet. You haven't seen its bugtracker i suppose. You call that safe? >Procedural code is statically checkable code is safe code. Even in single-threaded programs, nondeterminism is easy to introduce. Without proof, you can only ever get evidence. Evidence doesn't suffice to claim safety. >If you need speed, get a better processor. Not possible in certain environments. There are ways to prove multithreaded programs are safe, too. No need for restrictions there, except budget. >It's on you, you have to go and prove whatever you're assuming. Not by definition. Safe code can't be called safe without proof, so no proof is needed to assume that code without proof is unsafe. It's unsafe by default. >Literally proofs about what retard? Literally proofs of correctness, retard. >std::vector::at() checks your access. Proof that it gives correct results is missing. Therefore it's unsafe by default. Also, if bounds-checking is that killer feature of C++, i have bad news for you. Tinycc has bounds-checking for C and it there actually is proof that its bound-checking is correct. >If you turn on the most pedantic flags and use the most popular static analysers, it simply won't compile. Wrong. C++ is notorious for being resilient even to the best static analyzers. I can easily confuse PVS-studio and coverity ("idiomatic" C++11 and C++14). It's not that easy to confuse Frama-C. >Well don't use an old version of GCC What guarantees me that gcc doesn't contain unsafe code still? >How, reinterpret cast? extern "C". Yikes, now my entire line is no longer red. There are other ways, too. My favourite is templates being fairly effective at hiding mistakes.
Jaxon Rivera
actually I am OP, i got my answer (retardation) and don't reallly care about the autists also, sage
Benjamin Cruz
while this thread is up(not op), i was wondering if there is a nice way to do summation in matlab something like this:
result += new result but this doesnt work with mat lab syntax.
MATLAB doesn't have += or ++ or any equivalent. The only otion is a=a+
Eli Parker
>tl;dr I know what bad code looks like >I can write bad code >I can write bad code that looks like good code >But I can't point out really bad code in other people's projects Yikes dude. All bark, no bite. If you really think you're so hot, contribute to static analyser projects.
Jordan Baker
>But I can't point out really bad code in other people's projects If they pay me, i'll do it. It's not fun to me to go look at other people's bad code. I do plenty of that at work. >If you really think you're so hot, contribute to static analyser projects. I did during university, both BSc and MSc results were at SVCOMP. I don't care about it anymore, i don't see future in fixing shitty languages like C++, Java or C. I see the future in using non-shit languages for higher-level systems and biting the bullet for verification of low-level systems (because i don't think we can do significantly better than Ada) and that's where i put my time. So no thanks, not interested in preventing you or me or anyone like you from doing mistakes in a shitty language, publishing hordes of books on how to not write an utterly shitty code in this or that shitty language, giving talks about that one time i didn't write an utterly shitty code and that other time i actually did even though everyone including me thought otherwise. There already is Frama-C if you're interested in writing safe C. It works quite well, easily interfaces with Coq so you can write your proofs as you write your C. If you're a webshitter, nobody really cares - people are used to your shit failing all the time, but go take a look at Idris.
Charles Rogers
K. have fun spending your life doing something machine learning will do in a few years.
Daniel Smith
>unironically throwing ML meme at verification You should spend less time on ycombinator. But again, not like anyone expects things you webshits write to work, unlike other industries where we're actually liable for damages if our shit fails.
Sounds like a "not mine" problem you chose to work for jews. Not a webshit but living the easy life doing the exact opposite you do. I do low level optimisations and generally allow shit to break to an allowable level. Have fun raising your blood pressure every day.
Kayden Sanchez
>C++ is hard >scripting languages are not cancer nu-Jow Forums, ladies and gentoomen kill yourself you useless sack of shit, technology would be better off without "programmers" like you