|
pseudorandom name posted:C++ turned away from the face of god when it stepped beyond C With Classes.
|
# ? Apr 7, 2023 14:11 |
|
|
# ? Jun 8, 2024 06:17 |
|
roomforthetuna posted:This but the exact opposite. Classes suck, smart pointers are good.
|
# ? Apr 7, 2023 15:16 |
|
go play outside Skyler posted:I use C++ a lot because you can mix and match it with C, and C has interoperability with tons of languages like Swift, Objective C, Kotlin, Golang, etc. This makes it still a top choice for anything that needs to be cross-platform on the long term. The standard library is less rich and more a dumping ground for random poo poo that some time person half thought through and convinced a bunch of other people we need it Then it doesn’t interact with other bits of the stl and you’re left wondering if anyone bothered to use the new feature before adding it The answer is no, no one used it. Even if they import things from already existing things they cut out useful stuff, see: ranges
|
# ? Apr 7, 2023 17:20 |
|
RAII is the only good part of c++, even then it’s kinda poo poo because you can’t error a constructor other than throwing lol kill me
|
# ? Apr 7, 2023 17:21 |
|
Xarn posted:Templates are awful, and I don't know anyone who really likes them. But then you use the modern replacement like Rust's traits and suddenly realize that you flat out cannot do things that would be simple in C++ (see e.g. variadic template packs). I count trying to use a variadic template for something back in 2013 before they'd really ironed out the bugs in all the different compilers as literally one of the most timewasting mistakes in my entire career. Pages of my brain are devoted to asinine bullshit about how compiler x said they supported variadic templates, but really implemented them as faux variadics, etc. etc.
|
# ? Apr 7, 2023 19:49 |
|
Those early MSVC variadic template implementations were really, really bad. Legacy of the incredibly broken template model where templates worked by re-parsing the template body with template parameters substituted with their arguments. (This is deeply incorrect, and it also makes a lot of things extremely annoying to implement because you have to construct valid token sequences even when e.g. a pack expansion completely disappears.) The other compilers had a few bugs, but they were more like weird corner cases.
|
# ? Apr 7, 2023 20:00 |
|
VC++'s awful old template implementation also had the unfortunate problem of accepting a lot of things which shouldn't work and couldn't possibly work with a sane implementation, which made porting code written for it to other platforms painful. Sometimes you just had to add typename all over the place, but other times you had code which unintentionally relied on that msvc didn't actually parse the body of templates and just did brace matching.
|
# ? Apr 7, 2023 20:19 |
|
that said, I just hit a problem while porting a program to Scala that necessitates something equivalent to variadic templates, so either Scala's a bad language (like C++) because it won't let me do the thing I think I want, or it's a good language (like C++) because it won't let me do the thing I think I want
|
# ? Apr 7, 2023 20:29 |
|
Volte posted:I have some bad news about smart pointers
|
# ? Apr 8, 2023 00:34 |
|
C++ template smart pointers gave us nft_ptr, so we can all agree they were a mistake.
|
# ? Apr 8, 2023 01:10 |
|
roomforthetuna posted:Yeah yeah, alright, the constructor and destructor part of classes is good too.
|
# ? Apr 8, 2023 01:20 |
|
Computer viking posted:C++ is a nifty expansion of C if you just limit yourself to the right parts. It can also be a fairly clean modern language if you just stick to those parts. The problem is that nobody agrees on which parts are the good ones, and you can't entirely avoid the rest. I think this speaks more about your personal preferences and experience than any worth of C++ - for me it's the best language to use for almost anything that's not either bare metal, web/GUI-heavy or that can be done by a quick python script. It does have some issues and a steep learning curve but I don't think there is any so-called "modern" systems language that is genuinely superior - sure if you need to do web/heavy GUI then there are languages in which you can do that much faster and if you need to work in a environment where you can't rely on a proper OS then C involves much less of "okay I can use these few bits but not the other 70% of normal C++", but for writing complex high-performance code there really isn't anything better. Rust maybe comes close but it has that hobby language flavour to it. Private Speech fucked around with this message at 03:10 on Apr 8, 2023 |
# ? Apr 8, 2023 03:08 |
|
roomforthetuna posted:Yeah yeah, alright, the constructor and destructor part of classes is good too. https://www.youtube.com/watch?v=afDB4kpYnzY
|
# ? Apr 8, 2023 11:09 |
|
I recently made a change that broke our tools build. We're getting an old project up and building with VS2019 on a new platform, and some code that had previously compiled fine was now breaking due to using uint32 (no _t) style integral types that had been defined for a previous platform but not for this, blah blah. No problem, add the _ts and move on. Except the tools solution is in VS2010 and compiles as C++03. I really don't miss C++03 at all.
|
# ? Apr 11, 2023 17:59 |
|
Incidental thing, absl::AnyInvocable is great and it's aggravating that there's not something like this in stdlib until C++21 or something. Finally I can docode:
code:
|
# ? Apr 11, 2023 23:50 |
|
Oh god drat it compilers. They let me do this:C++ code:
Wasted 2 hours of my life on this.
|
# ? Apr 14, 2023 04:11 |
|
Volguus posted:No complains. No warnings. No ... nothing. At least an "hey moron, are you sure you don't want to publicly inherit that? It's kinda useless otherwise." would have been appreciated. And compiled with Wall, pendantic, everything and cherry-on-top. Clang was happy as a clam.
|
# ? Apr 14, 2023 11:36 |
|
roomforthetuna posted:Can you elaborate on what's wrong with this? It looks okay to me, assuming the Foo was instantiated with make_shared or similar. It should have been C++ code:
|
# ? Apr 14, 2023 12:05 |
|
There isn't really any way to express in the language that the inheritance needs to be public, so any warning for that would have to be a very special-cased thing and those usually go in clang-tidy. I'm kinda surprised that clang-tidy appears not to have a check for it as it's a pretty common problem for people to run in to.
|
# ? Apr 14, 2023 19:59 |
|
Plorkyeran posted:There isn't really any way to express in the language that the inheritance needs to be public, so any warning for that would have to be a very special-cased thing and those usually go in clang-tidy. I'm kinda surprised that clang-tidy appears not to have a check for it as it's a pretty common problem for people to run in to. Oh, I understand this but it should, drat it. On the other hand, to be fair, public inheritance should be the default imo, with one having to specify explicitly that they want private inheritance. Then again, a ton of things should "be on by default" in C++, which will never happen, for good or bad reasons (usually compatibility and neck-beards).
|
# ? Apr 14, 2023 20:21 |
|
For better or worse, inheritance visibility defaults follow the visibility defaults of everything else. So struct inherits publicly by default, while class inherits privately by default.
|
# ? Apr 14, 2023 20:50 |
|
Volguus posted:It should have been
|
# ? Apr 15, 2023 00:15 |
|
Anyone have advice for helping someone transition from Java to C (not C++, just vanilla C)? We have a new hire straight out of college whose only experience is with Java and Javascript but our codebase is C89. They seem to be struggling with the concept of pointers especially. So far I've been having them run through hackerrank C exercises to build skills and confidence while I kibitz and advise. It seems to be going okay during our 1-on-1s but translating that into being able to make changes in our codebase has been pretty slow. The obvious thing would be to go over examples from our codebase with them, but that was the first thing I tried and they weren't able to read a simple 5 line function that returned the sum of a specific array in a passed in struct. We spent most of an hour on it and while they made enough progress to be able to make the necessary one line change, they didn't really internalize it. The codebase I inherited uses lots of pointers to global structs.
|
# ? Apr 19, 2023 16:33 |
|
LLSix posted:Anyone have advice for helping someone transition from Java to C (not C++, just vanilla C)? This is tough - I worked in a c++ job with plenty of new grads who came on with only Java experience and they all were able to pick it up on the go. Sure, they took longer to get stuff done at first and code reviews revealed plenty of issues, but people were able to teach themselves over time. I don’t remember a case like yours in my personal experience. I’d probably give it another month or so and then honesty consider letting them go if they still show no progress. I feel like you’ve already gone above and beyond with tutorials and walking them through code side-by-side. If that doesn’t work, idk what will.
|
# ? Apr 19, 2023 16:48 |
|
I would probably start on just the concept of memory. Get some graphing paper, tell them that every box is a byte, and start numbering them. Show how bytes, shorts, ints, longs, etc are stored by blocking out multiple boxes. Show how a simple struct is stored. Then explain that a pointer is just a 32/64 bit integer. Block out an integer in the boxes and write in a number that logically represents the id of a different block on the sheet. Maybe erase the number and change it to show how changing the pointer is changing the box it is pointing to. Then explain that the data type associated with the integer just tells the compiler how to interpret the data it sees at that point. Say that the pointer is a byte, then a short, then an int, and show how it reinterprets what it sees. I think that as long as they can conceptually identify that a pointer is just a normal integer and the compiler interprets it in a special way, it would go a long way to helping them understand some of the most complicated parts of C.
|
# ? Apr 19, 2023 17:14 |
|
Yeah, maybe they just need a basic systems programming course. There’s online courseware for that, I think.
|
# ? Apr 19, 2023 18:22 |
|
IIRC, what actually helped me understand the idea of C was to read some history of it, from BCPL to B to C - something like this. Seeing the history and design rationale (if any) of some of those features made them easier to understand to me, but it may well just confuse your poor new hire further.
|
# ? Apr 19, 2023 20:19 |
|
LLSix posted:Anyone have advice for helping someone transition from Java to C (not C++, just vanilla C)? Don't.
|
# ? Apr 19, 2023 22:29 |
|
I can’t believe you are using c89, you couldn’t spring for the extra decade and use c99?
|
# ? Apr 19, 2023 23:53 |
|
Sweeper posted:I can’t believe you are using c89, you couldn’t spring for the extra decade and use c99? Not if you're on windows :V
|
# ? Apr 20, 2023 00:49 |
|
leper khan posted:Not if you're on windows :V 3.1?
|
# ? Apr 20, 2023 00:59 |
|
leper khan posted:Not if you're on windows :V Visual Studio supports the non-optional bits of C17 reasonably well these days, I believe, and you can also use clang for compiling if you want. Can also use gcc on windows if you’re willing to jump through some extra hoops.
|
# ? Apr 20, 2023 01:00 |
|
Volguus posted:3.1? https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-160#c-standard-library-features-1 Didn't have most of C99 until VS2015
|
# ? Apr 20, 2023 01:04 |
|
VS2015 came out eight years ago.
|
# ? Apr 20, 2023 02:40 |
|
Thanks for all the suggestions everyone.Sweeper posted:I can’t believe you are using c89, you couldn’t spring for the extra decade and use c99? Unfortunately not. Sales are idiots and promised customers we wouldn't change compilers. We have one customer I know of that's still got a contract for c89 and I got to find out we had such a contract clause when we had to do release for them earlier this year. The lead dev before me upgraded all the developers to c99, and it was a multi-week effort to go back and fix all the code they had written that wouldn't compile on our c89 release pipeline (of course I set up a c89 CI pipeline after I found out). So yes it's stupid, but yes, we really are stuck supporting c89 for at least another 3 years
|
# ? Apr 20, 2023 03:25 |
|
I'm working through data structures and algos for the first time so I'm a little baby with this stuff. I'm having an issue with a very specific exercise using doubly linked lists, maybe someone can give me an idea. I'm working with doubly linked lists that are represented as headers with pointers to the first and last nodes, like so.code:
I'm trying to concatenate two lists in constant time in a new list, then free the memory of the input lists. I have to implement it that way to follow the problem text correctly. I think I'm going through the idea properly: if either input list is empty, return the other as the concatenated list, otherwise something like: code:
Tosk fucked around with this message at 12:24 on Apr 23, 2023 |
# ? Apr 23, 2023 12:21 |
|
If you wanted to split a list in half, how would you disconnect the first part of the list from the rest of it? Can you apply a similar technique to disconnect the list header from all the nodes you've moved to a different list?
|
# ? Apr 23, 2023 12:45 |
|
Tosk posted:I'm working through data structures and algos for the first time so I'm a little baby with this stuff. I'm having an issue with a very specific exercise using doubly linked lists, maybe someone can give me an idea. I'm working with doubly linked lists that are represented as headers with pointers to the first and last nodes, like so. How many lists can a node be an element of?
|
# ? Apr 23, 2023 13:25 |
|
I apologize in advance for continuing to post about such a simple issue. Thank you both for your help! I haven't been able to get my lists to concatenate yet. I was trying to use the advice you both gave me - a node is an element of one list at a given time, given its pointers to the previous and next nodes in the same list. I've been trying to use temporary nodes, thinking of the inverse case of splitting a list like Jabor helpfully mentioned. So I'm doing something like code:
Tosk fucked around with this message at 15:35 on Apr 23, 2023 |
# ? Apr 23, 2023 15:32 |
|
|
# ? Jun 8, 2024 06:17 |
|
If you're taking all the nodes out of the old lists, what should the headers for the old lists be pointing at?
|
# ? Apr 23, 2023 15:44 |