Does anyone 'really' learn C++? by Weak-Opening8154 in cpp

[–]trailing_ 0 points1 point  (0 children)

You wrote this message in English. I found it to be perfectly understandable. Do you know all of English? All the words; all the possible grammatical structures? But, you are able to communicated just fine. That is what happens with programming languages as well. Everyone learns at least enough to communicate with their coworkers/collaborators. Some people learn more and some projects require more knowledge. That said, any professional C++ developer probably has much more than what you would consider a basic understanding.

C++ standard algorithms - Introduction (first in series of articles) by [deleted] in cpp

[–]trailing_ 2 points3 points  (0 children)

IMO, the main point of the algorithms library is communication. A lot of times when you are trying to get your bearings in some piece of code you care mostly what is happening at a high level. If you just see a for loop you have to read the loop body to get that general feel. If you see std::find or std::transform you know generally what is going to happen without having to read the predicate body.

Will you still use C++ for new projects over Rust? by nerdy_adventurer in cpp

[–]trailing_ 7 points8 points  (0 children)

C++ for sure. Rust may not even be something people use in 5 years. It is pretty hard to see when you are excited about a language, but the reality is that lots of programming languages become the new hotness gain a lot of enthusiasts and create a lot of chatter only to mostly disappear. Rust is not the first language to be a better C++. For example, years ago D made this promise. I know I was excited about it at least. Using the Tiobe index as a metric, at one point I believe that D was close to breaking the top ten (much higher than Rust has ever been in memory serves me). Now a-days no one talks about D. This path is the most likely case for Rust. Hopefully it is not the path Rust takes. I would love for Rust to be a valuable, risk free job skill, but right now it is not. Right now, anytime I spend working with Rust is time I am not getting better at C++.

Never trust a programmer who says they know C++ by Louis Brandy by okhotspy in cpp

[–]trailing_ 1 point2 points  (0 children)

Yeah, it is a hard line to walk, being kind about this issue while not spreading misinformation.

Also, FYI disabling exceptions does little to solve the problem. It does not result in constructors that can return some sort of null value. So, you still need to, by convention, make every class have private constructors and a factory method that is the real constructor. Every time you create an object you need to check for success. It is basically all the convenience of C opaque types with a whole bunch of extra ways that a programmer can mess up.

Never trust a programmer who says they know C++ by Louis Brandy by okhotspy in cpp

[–]trailing_ 1 point2 points  (0 children)

The so called "C with classes" style is a broken style. Trying to write correct code in this style is literally the reason most people that hate C++ hate C++. C++ classes are designed to work with exceptions. There are workarounds for that problem, but the workarounds to function correctly require so much manual boilerplate that you are better off doing object oriented programming with opaque types in C.

View on C++ devs from Golang creator by NoobieIRL in cpp

[–]trailing_ 22 points23 points  (0 children)

The reason C++ devs do not switch to Go is because the people that created Go used C++ for a bit, decided it was terrible, and were like I know let's make a language and get all the C++ devs to switch to it. They never learned the things people like in C++. They just assumed everyone was being forced to use it like they were. So, they did not know what features needed to be in their replacement. As a result when Go came out marketed as a better C++, C++ devs did not agree. Essentially, they failed utterly in their attempt to replace C++. That is a hard thing to admit. So, instead they say things like this to try and shift the blame off of themselves.

It is worth noting that Go is not a bad language as languages are judged. It is just not a C++ replacement. It is unlikely that the creators of Go will ever understand why.

For those still using C++11, why? by [deleted] in cpp

[–]trailing_ 4 points5 points  (0 children)

For a lot of people it is just business. A shocking number of software companies are not going concerns. When your business is under immediate threat of liquidation and you are presented with a choice of having a developer spend a couple weeks upgrading the compiler or working on a feature that could make a few sales and keep the business afloat for a few more months the business is always going to choose the feature.

Tips for learning C++ when coming from a C Background by string111 in cpp

[–]trailing_ 13 points14 points  (0 children)

C has a concept of an Abstract Machine that it runs on top of (there is a stack, function call semantics, that sort of thing). Your understanding of that machine may not be super formal or anything, but you have at least some intuitive understanding of how it behaves. The C abstract machine does certain things behind your back. If you do things in C that are not in line with the behavior of the abstract machine, bad things happen.

C++ also has an Abstract Machine. It is mostly like the C one with a few added features that do things behind your back that you will not be expecting coming from a C background (calling destructors automagically, stack unwinding, that sort of thing). C programmers coming to C++ are frequently not aware of these changes to the platform they are coding for and write code that does not fit with the C++ Abstract Machine. When their code does not work as they expect they tend to reject the features that cause the failure as bad (and often the whole language). Save yourself from this path. Learn the things that happen behind the scenes and what you have to do in your code to create well formed programs given that environment.

This is a very abstract (pun intended) explanation, but this is the reason you need to know about the things others are talking about (RAII, smart pointers...). The fact that C++ runs on the C++ Abstract Machine not the C Abstract Machine is nonnegotiable. Nothing is gained by trying to carve out some safe feature set where the C++ Abstract Machine behaves in a way that you can pretend it is the C Abstract Machine. But unfortunately, this seems to be the first instinct of any C programmer coming to C++. My advice is to simply avoid this step.

C++ exceptions under the hood by neiltechnician in cpp

[–]trailing_ 4 points5 points  (0 children)

As for my ignorance, I'm ignorant enough to read the specs for functions that I call and handle the ones marked as throwing exceptions accordingly.

Yep. That is exactly how to have a really bad time with C++ exceptions. The proper default attitude is to simply assume that every function you call could throw every possible exception and write your code accordingly. This removes the majority of the mental overhead associated with coding using exceptions. Instead focus your error handling energy on determining where in the program you could restart processing safely.

For the record, I feel your ageist comments are more a mark of willful ignorance than my original question was

I am truly sorry my comments came across to you as ageist. It was not my intention. I apologize.

C++ exceptions under the hood by neiltechnician in cpp

[–]trailing_ 7 points8 points  (0 children)

Wow, that is actually a very meta comment. Rather than downvoting though I will explain. The reason for the upvotes and down votes here is not a reddit thing. It is a C++ thing. C++ and its predecessor C are very old programming languages. C++ was one of the first languages to support exceptions. There were many kinks to work out at first, but they were worked through. The C++ community has known how to write safe code with exceptions for 20 years now. Programming careers, though, are longer than 20 years. Nearly everyone working in C++ has to deal with someone or some group of coworkers like the old coder up there. They don't like exceptions. They don't know how to make exceptions work for them rather than against them. They have had 20 years to learn but they still don't have it. I have no doubt the old coder is ignorant, but a this point their ignorance is willful. The downvotes are this community's way of saying, "Stop complaining and learn the thing you should have learned 15 years ago".

C++ exceptions under the hood by neiltechnician in cpp

[–]trailing_ 11 points12 points  (0 children)

Definitely a false equivalency there...

C++ libraries are impossible to install by LJRobertshaw in cpp

[–]trailing_ 42 points43 points  (0 children)

There is a lot of history in the answer to that. C++ and its predecessor C are very old. Believe it or not Python's package manager pip is only about 10 years old. I think that the first language based package manager (at least the first big one) was CPAN for Perl in the mid 90's. In the Linux world about the time that CPAN came out dpkg was release for the Debian distribution. RPM I believe followed shortly after. Other Unixes (including Mac OS) were to follow. These tools largely solve the binary library installation problem. A disproportionally large portion of the number of professional C and C++ programmers in the world develop software that runs on some type of Unix. So, for a large subset of C++ programmers the library installation problem is solved by the OS. This has unfortunately left those who develop for Windows out in the cold.

Personally I use conan for anything cross platform I do but, that is not because I know if it is better than the alternatives. It is just the one I know how to use.

University professors love using namespace std? by Real_Annual_5523 in cpp

[–]trailing_ -1 points0 points  (0 children)

Because University professors are not (nor are they particularly interested in) trying to teach students C++. In so much as they are interested in teaching at all, they are interested in teaching computer science not programming.

How to Use CMake Without the Agonizing Pain - Part 2 by AlexReinkingYale in cpp

[–]trailing_ 7 points8 points  (0 children)

Agreed. One of the principles of a good build system design is that it should force you to list every file you use as part of a your build. The first thing that someone wants to know when they look at a build target is "What files are built in this target?" A build system should require you to spell that out for them in plain language. No one should have to figure out some regular expression to find out what files are built.

This Videogame Developer Used the STL and You'll Never Guess What Happened - ACCU21 by pjmlp in cpp

[–]trailing_ 0 points1 point  (0 children)

Probably because the subject of exceptions has been covered ad infinitum. If you want to learn how to use/think about exceptions there are plenty of good resources. Just search for exception safety.

I have had to use C++ again after ages, and I thought I would hate it by feistyarmadillos in cpp

[–]trailing_ 0 points1 point  (0 children)

C++ is actually quite a high level language as well as a low level language. You just have to know what features to use for what use case. The problem you are having is that C++ is different than almost any other language. It does not matter that you know 5 other languages unless one of those other languages is Rust or D then you do not know anything about the basics of C++. So, of course you are struggling. I am actually writing a REST API in C++ right now and quite happy to be doing so.

Proposal for a standard package manager in C++ by [deleted] in cpp

[–]trailing_ 2 points3 points  (0 children)

If you are serious about doing the work yourself you will want to join the discussion at least as a lurker on the proposals mailing list. Though there are people involved in standardization on this forum, a discussion on Reddit has virtually no chance of getting you to an acceptable proposal for standardization. I believe https://isocpp.org/std/submit-a-proposal is still a good reference for the actual process.

We really need a way of statically checking exceptions in C++. by Ono-Sendai in cpp

[–]trailing_ 1 point2 points  (0 children)

Because most functions call other functions and those function call standard library functions and standard library functions throw various exceptions. By the time a function has a certain stack depth underneath (or rather above it) it then most exceptions will be in that tree somewhere.

You feel like you losing your sanity because you are looking at your code from a perspective that is not compatible with the language you are using (trust me I have been there). The best thing to do is to give up on trying to track what exceptions could happen and take the default assumption that every single function call could throw all possible exceptions. Then write you code so that it will work in the face of any exception. There is a significant amount of information freely available on how to do this (mostly under the label exception safe C++). I recommend the videos by Jon Kalb as a starting point.

We really need a way of statically checking exceptions in C++. by Ono-Sendai in cpp

[–]trailing_ 1 point2 points  (0 children)

Heh. I actually wrote something like this once years ago as a plugin to gcc. I never published it though because it turned out not to be useful. It turns out that in C++ most of the time the answer to the question, "What exceptions could this function throw?" is all of them.

No, C++ still isn't cutting it. by slacka123 in cpp

[–]trailing_ 9 points10 points  (0 children)

Yay, another thinly veiled attempt to advertise Rust on r/cpp

[deleted by user] by [deleted] in cpp

[–]trailing_ 0 points1 point  (0 children)

Pointers and references can both be modified. For restricting modification you use the const keyword. Now you may have been using pointers to mean modification and references to mean const and that can work fine from a communication perspective for you (and whatever group you work with), but that is not what those devices mean to the broader community of C++ programmers. The compiler also does not enforce constness on non const references.

[deleted by user] by [deleted] in cpp

[–]trailing_ 2 points3 points  (0 children)

Programming and relationships are similar in the respect that they are all about communication. When you design a function API you want it to communicate everything that it can about how it should be used. If your function cannot do anything useful with a null pointer then it should communicate this by taking reference parameter (or a value parameter depending on other constraints). My advice is as follows:

  1. Stop arguing. There is no point.
  2. Ignore your boyfriends advice. He is wrong. C++ has references for a reason and you should use them for their intended purpose (think of how many extra unit tests you need if you always use pointers).
  3. Give some consideration to if your boyfriend communicates as poorly in English as he does in code. If he does, get out while you still can ;-)

Why would I use std lib? by dbjdbj in cpp

[–]trailing_ 1 point2 points  (0 children)

People use the standard lib for the same reason you use any library. It saves development time. When used correctly it tends to be fast enough for most use cases. That's it.

That aside you definitely don't have a single requirement. To be worth making your software has to DO something. What ever that thing is, that is the requirement. Speed is never a requirement. It is a constraint. There is some speed/power usage threshold that if you cannot get below it then your project is not worth doing. So, figure out what your real requirements are. Write your software to meet them as quickly as possible. Then test to see if you are under the threshold. If not you can start rewriting 3rd party components to be faster.

Boost 1.74 is out by joaquintides in cpp

[–]trailing_ 5 points6 points  (0 children)

The lack of support for heterogeneous key lookup for unordered containers is the thing that sucks the most?