News for hackers. Stuff that matters.
Re:I am sick and tired of hearing tech companies complain ab... by MattGaiser on Tuesday May 18, 2021 @11:55PM (#27204346)
> Furthermore, if you really want a C++ developer you can just expect a developer to learn C++ on the job if they have any adjacent experience with any other language.

Is this really accurate? C++ is a very different language than even Java, not to mention Python or JS. Languages have their own quirks and attributes that often matter at some point. Especially C++.

I am on a team where we are constantly building stuff with new technologies that nobody on the team has learned, so a certain extent I understand the sentiment, but we are under no impression that we are doing that good a job at it.

Re:I am sick and tired of hearing tech companies complain ab... by flatline on Wednesday May 19, 2021 @12:03AM (#27204417)
C++ is one of those languages where people have deep expertise. They are on standards committees, they have a high profile in the industry. But yes if you have general programming experience you can certainly pick up modern C++ and not make a complete mess of things. It’s a multi-paradigm language with lots of gotchas that take a while to learn and require a career to memorize and stay on top of. But I think if you are an average developer in, say, a functional and OO language, you can be expected to become an average C++ developer with a little effort.
Re:I am sick and tired of hearing tech companies complain ab... by jonas21 on Wednesday May 19, 2021 @12:51AM (#27204696)
Maybe... if there are other experienced C++ developers around who can show you the ropes. But C++ has enough footguns that I wouldn't want the only C++ developer on a project to be someone who just picked it up. That's just asking for trouble.
Re:I am sick and tired of hearing tech companies complain ab... by vgatherps on Wednesday May 19, 2021 @12:23AM (#27204556)
I think if you want somebody to learn the syntax of C++, and more/less understand some code, then that would work.

But many places are using C++ only because something about the problem domain requires it, often performance. Understanding C++ and cpu architectures well enough to write high performance code is a completely different beast than just understanding c++ well enough to write code.

Understanding C++ syntax is a long ways from writing C++ that's not full of memory corruptions, as others have mentioned.

So it's not just "train somebody in C++", it's "train somebody in C++ and writing memory-safe C++ and writing fast C++".

Re:I am sick and tired of hearing tech companies complain ab... by Godel_unicode on Wednesday May 19, 2021 @12:01AM (#27204402)
Yeah, hiring someone with no c++ experience and expecting them to OJT is a great way to farm memory corruption vulnerabilities...
Re:I am sick and tired of hearing tech companies complain ab... by JAlexoid on Wednesday May 19, 2021 @12:06AM (#27204436)
I have been told multiple times by C++ advocates, that C++ (whatever year is latest) doesn't have memory management issues... Is that not true?
Re:I am sick and tired of hearing tech companies complain ab... by midnightclubbed on Wednesday May 19, 2021 @12:26AM (#27204578)
Yes and no. You can write c++ code that handles memory in a safe and consistent way. Or you can write code which silently leaks and corrupts as it goes. The language doesn’t care and unfortunately even if you do everything correctly another programmer can mess with your allocated memory and silently break everything.
Re:I am sick and tired of hearing tech companies complain ab... by esrauch on Wednesday May 19, 2021 @12:16AM (#27204510)
It can be pretty safe, but it requires restraint and selecting a good subset of the language. There's still plenty of footguns that an inexperienced person might hit.
Re:I am sick and tired of hearing tech companies complain ab... by amluto on Wednesday May 19, 2021 @12:27AM (#27204583)
And footguns that an experienced person might hit. One family of such footguns is:

    const auto &foo = something(args);
    …
    other_thing(foo);
Depending on exactly what you’re doing and what type something(args) returns, this can be entirely correct and idiomatic. In other circumstances it accesses a reference after its lifetime.

One can debate whether the const belongs there and how many &’s to use, but, unless something has changed dramatically in the last couple years (I’ve been focused on things that aren’t C++), there is no answer that is universally safe and efficient.

Re:I am sick and tired of hearing tech companies complain ab... by rightbyte on Wednesday May 19, 2021 @06:41PM (#27215446)
The temporary's reference is valid until the temporary is destroyed by falling out of scope, swapped etc. Or have I missed something?
Re:I am sick and tired of hearing tech companies complain ab... by amluto on Friday May 21, 2021 @10:50AM (#27234743)
The reference itself is indeed valid, in the sense of existing, until it falls out of scope. But the object it references may not be, so using the reference can be UB. Consider an std::vector v with length known to be at least 1:

    const auto &ref = v[0];
    v.push_back(42);
    cout << ref;
That works fine until push_back reallocates out of place, at which point you may start to notice that it’s actually UB.

Rust will not permit this problematic usage. GC languages tend not to offer this pattern — you can reference a boxed vector element with different semantics than the above C++ code, and you mostly can’t reference an unboxed element. C++ lets you do things like this but has little ability to statically verify correctness.

(Doing the above maneuver with a vector is a bit silly: it saves typing, and indexing a vector is extremely fast. With a map, though, indexing is not so fast, and keeping an iterator or a reference around may be a big performance win. At least if you keep an iterator around, dynamic checkers have a better chance of noticing errors.)

Re:I am sick and tired of hearing tech companies complain ab... by esrauch on Thursday May 20, 2021 @09:34AM (#27220917)
I think the point is just that unlike Rust there's no compiler enforcement that you only use refs in their lifetimes: you can easily accidentally cause a use after free.

Some times it can be pretty indirect: eg if the ref ends up pointing into some std container then it might need invalidated by making an otherwise unrelated change to the container.

Re:I am sick and tired of hearing tech companies complain ab... by pas on Wednesday May 19, 2021 @01:01AM (#27204763)
Could you please explain this? I remember something about rvalues but it was as ages ago apparently :)
Re:I am sick and tired of hearing tech companies complain ab... by swader999 on Wednesday May 19, 2021 @01:20AM (#27204847)
First time I've ever heard the term 'footgun'
Re:I am sick and tired of hearing tech companies complain ab... by josephg on Wednesday May 19, 2021 @01:35AM (#27204952)
It’s a reference to a decades-old quote from Bjarne Stroustrup, C++’s creator:

“In C++ it’s harder to shoot yourself in the foot, but when you do, you blow off your whole leg.”

Re:I am sick and tired of hearing tech companies complain ab... by zmmmmm on Wednesday May 19, 2021 @02:02AM (#27205119)
It's not even so much that the footguns exist but that the consequence of hitting them is "undefined behavior" ie: anythign from core dump to reformatting your hard drive. Compare to Java where the consequence is one thing doesnt work right and someone has to debug it. Rarely it takes down a whole server side process but even then you get a lot of instrumentation and diagnostics to manage it and / or figure out what happened.
Re:I am sick and tired of hearing tech companies complain ab... by UncleMeat on Wednesday May 19, 2021 @08:23AM (#27207595)
C++ is a nightmare language but this specific complaint is completely overblown. The compiler isn't going to format your hard drive (I know that one blog post exists - that is a deliberately constructed example).

A C++ program with UB is just buggy. Same as a java program with bugs. The program does something you don't want it to do. That's what a bug is. The compiler isn't going to maliciously introduce code that you didn't write to order pizzas.

Re:I am sick and tired of hearing tech companies complain ab... by esrauch on Thursday May 20, 2021 @11:54PM (#27230325)
I think there is a factor of UB that makes it have a steeper learning curve than the corresponding issues in other languages: with Java a lot of that category of bad code will throw exceptions and you'll get useful stack traces. UB often results in some seemingly nonsensical runtime state (eg something being null immediately after a null check, or a null dereference only leading to a segfault later in a place that locally has no pointers).

Compare mutating a container in a way that invalidates a live iterator: in java it's a specific exception that you can read on stack overflow, and in C++ it's just a use after free that might still appear to work correctly a random percentage of the time.

Re:I am sick and tired of hearing tech companies complain ab... by vgatherps on Wednesday May 19, 2021 @12:24AM (#27204561)
It's not that true... newer c++ features did go a long way in reducing memory management bugs but there's still a ton of footguns.
Re:I am sick and tired of hearing tech companies complain ab... by alaties on Wednesday May 19, 2021 @12:29AM (#27204589)
That greatly depends on use case.

I think if you're looking to write a simple HTTP server with some API functions that talk to some RDBMS at less than 100 requests per second, yeah, C++ is pretty hygienic and safe these days.

If you need to play around with memory management strategies like non-default allocators then yeah, the knives are still very sharp and will cut you if you're not careful. This comes up a lot when writing C++ extensions for scripting languages like PHP, Python, etc and you have to interact with objects managed outside of your C++ code.

Re:I am sick and tired of hearing tech companies complain ab... by virgilp on Wednesday May 19, 2021 @01:06AM (#27204784)
> C++ is pretty hygienic and safe these days.

C++ these days still supports all the syntax and programming style of C++ in the 70s. You probably mean "you can program in a hygienic and safe way in C++", which is true, but also is not necessarily a feature of the language but of the programmer (just a few years ago I interacted with some theoretically senior C++ programmers who claimed mixing raw pointers with smart pointers is fine because they're senior and know what they're doing).

Re:I am sick and tired of hearing tech companies complain ab... by UncleMeat on Wednesday May 19, 2021 @08:26AM (#27207612)
> C++ is pretty hygienic and safe these days.

Ask developers to safely define a string constant that is accessible outside of that translation unit. Now do it without C++17, which many companies aren't using yet.

Things have gotten a lot better, but even these incredibly basic needs can be really tricky.

Re:I am sick and tired of hearing tech companies complain ab... by wutbrodo on Wednesday May 19, 2021 @01:45AM (#27205026)
Leaving aside the hyperbolic fringe, I'd guess that what you've heard is that it's possible for a team with discipline and experience to develop in such a way that they sidestep C++'s memory pitfalls. The situation being discussed here is the exact opposite.

For example, while I'm not particularly fond of Python as an engineering language, I've never worked on a team with poor enough process that we deal with (eg) production runtime failures due to typo-ed variable names that would have been caught by the compiler. And yet I'd never claim that it's impossible for such a problem to exist, given arbitrary levels of talent composed in arbitrary teams and processes.

Re:I am sick and tired of hearing tech companies complain ab... by namdnay on Wednesday May 19, 2021 @02:35AM (#27205310)
Does a 911 with traction control off handle well? Definitely. Would you give the keys to someone who’s just passed their test? Definitely not
Re:I am sick and tired of hearing tech companies complain ab... by Animats on Wednesday May 19, 2021 @12:14AM (#27204498)
It's not true. Go look at security advisories that mention "buffer overflow".
Re:I am sick and tired of hearing tech companies complain ab... by bigblind on Wednesday May 19, 2021 @12:12AM (#27204490)
I can't comment on whether this holds for C++, but I've experienced it at my current position with Elixir. While it's a high level language like most programming languages I know, it's still a large paradigm shift to a purely functional language. And yet, I could get to the level where I could make useful contributions to our backend within a few days. I went through Elixir's "Getting Started" guide, and afterwards, I just learned concepts as I needed them. Yes each language has its quirks, and I guess C++ has gained quite a few of them over the years, but you can get quite far with a basic understanding of a language, and an existing code base to learn common usage patterns from as well.
Re:I am sick and tired of hearing tech companies complain ab... by rantwasp on Wednesday May 19, 2021 @12:24AM (#27204560)
normally i would agree with you but no. not for C++. having worked with C++ in the past I would not venture to say I know C++ today (it’s been a while) or have high hopes that I would just pick it up in a few weeks like any other normal language
Re:I am sick and tired of hearing tech companies complain ab... by akg_67 on Wednesday May 19, 2021 @12:24AM (#27204563)
People undervalue other people’s skills and contributions and overvalue their own skills and contributions.

I notice this more and more in hiring process. Teams expecting new member to perfect fit wrt hard skills over soft skills. Frankly, hard skills can be taught, soft skills can’t be taught and take long time to modify behavior.

Re:I am sick and tired of hearing tech companies complain ab... by tomp on Wednesday May 19, 2021 @02:39AM (#27205343)
As someone who studies math (one pf the hardest skills), no, sometimes skills just can’t be taught. Some people just don’t get it. Unfortunate, but that’s the way it is.
Re:I am sick and tired of hearing tech companies complain ab... by akg_67 on Wednesday May 19, 2021 @04:48AM (#27206070)
You can teach someone math who already graduated with basic science degree in much shorter time than it will take to teach a math whiz to consider opinions from someone else’s point of view.
Re:I am sick and tired of hearing tech companies complain ab... by pm90 on Wednesday May 19, 2021 @01:21AM (#27204861)
I haven’t been able to articulate it as succinctly as you did, but this is so true and Ive used the principle to push for many hires who didn’t do so hot in their technical round.

If a person is excited about technology and is familiar with translating ideas into code, that’s really all that I’m really looking for. Writing good code, understanding OS, networking etc are things that can be looked up and learned by people who are motivated to do so… there are so many resources to learn from.

One caveat here is that for “senior” hires, the expectation is opposite: not that they write perfect idiomatic code, but they’re able to write solutions. I think the practice of less technical interviews for higher level seems somewhat paradoxical: you want your Software architects and Principal Engineers to be able to code with a degree of competence.

Re:I am sick and tired of hearing tech companies complain ab... by imstate on Wednesday May 19, 2021 @12:03AM (#27204416)
Yes and no. A good programmer could learn it, but it exposes concepts that python and java abstracts from the programmer.

C++ requires you to think quite a bit about memory. Modern C++ not so much. However the kind of job that requires C++ will probably require you to know some hardware / embedded which is a completely different domain than web devs and could make java / python transitions even more difficult.

Re:I am sick and tired of hearing tech companies complain ab... by dheera on Wednesday May 19, 2021 @12:12AM (#27204485)
Depends a lot on how you use it.

You can pass everything by value, write very child-friendly C++ code, using std::map like Python dict and std::vector like Python list, and still VASTLY beat the speed of an interpreted, weakly-typed language like Python.

But nobody does that. Chances are someone on the team takes a shit about unnecessary memory copies, the code will be littered with a smattering of pass-by-reference and pass-by-pointer, there will be std::shared_ptr, std::weak_ptr, std::unique ptr everywhere, and if you're lucky some intern will have committed some C-ish C++ code that will leave you gift of memory leaks, and now all of a sudden you need everyone to understand all the nuisances of the language and how memory works.

Re:I am sick and tired of hearing tech companies complain ab... by amluto on Wednesday May 19, 2021 @12:30AM (#27204599)
> But nobody does that. Chances are someone on the team takes a shit about unnecessary memory copies

It’s not just performance. In any moderately complicated C++ program, you will want a function to mutate its argument, and this falls apart.

Sure, you can write in a pure functional style with immutable data structures, but I wish you luck implementing an immutable data structure with asymptotically reasonable performance without using pointers of some sort.

Re:I am sick and tired of hearing tech companies complain ab... by pkolaczk on Wednesday May 19, 2021 @01:20AM (#27204843)
Unfortunately many programmers underestimate the speed at which computers can copy flat regions of memory these days and overestimate speed of code littered with pointers and indirection. Often using pointers to avoid copying a few bytes leads to worse performance.

In my experience a combination of pass-by-value with move semantics provides good code readability and almost optimal performance in most cases, so that's my default. Unless a profiler disagrees in specific cases, of course.

Re:I am sick and tired of hearing tech companies complain ab... by amluto on Friday May 21, 2021 @10:43AM (#27234622)
> copy flat regions

A map or pretty much any nontrivial data structure is not a flat region.

In any event, waiting to optimize until a profiler tells you to is a reasonable practice as long as you pay attention to scaling. It’s very easy to write, for example, a JSON parser that performs fine in small tests and has a nice small n^2 coefficient. And then someone throws in a bigger input than you tested and your game takes ten minutes to load.

Re:I am sick and tired of hearing tech companies complain ab... by pkolaczk on Friday May 21, 2021 @11:18AM (#27235164)
> A map or pretty much any nontrivial data structure is not a flat region.

Not necessarily. A hashmap can be implemented in a way it stores both the keys and values in a flat memory region, as long as keys and values are fixed size, and such a structure is way more efficient that traditional array-of-pointers implementation, where fetching each key requires following a pointer and getting the value requires following another pointer.

Re:I am sick and tired of hearing tech companies complain ab... by amluto on Friday May 21, 2021 @03:38PM (#27238906)
The resulting code will still be asymptotically slow.
Re:I am sick and tired of hearing tech companies complain ab... by cupofcoffee on Wednesday May 19, 2021 @12:10AM (#27204475)
In any decent CS school they actually teach you low-level stuff. Transitioning from Java to C++ for such a person is trivial.
Re:I am sick and tired of hearing tech companies complain ab... by JAlexoid on Wednesday May 19, 2021 @01:25AM (#27204884)
Low level stuff, I happily code off the top of my head in pure PIC and AVR assemblies, is not same as C++ low level stuff.

(IMO) C++ is quickly becoming that middle ground language that is destined to be a niche language in a decade. It's not low level enough and not high level enough to give people dealing with assembly code or business logic code a reason to switch.

Re:I am sick and tired of hearing tech companies complain ab... by pas on Wednesday May 19, 2021 @01:03AM (#27204769)
Certainly not trivial if all you have is school Java experience.
[dead]
Re:I am sick and tired of hearing tech companies complain ab... by johnnyanmac on Wednesday May 19, 2021 @01:35AM (#27204955)
I think the above comment bears repeating:

>A good programmer could learn it, but it exposes concepts that python and java abstracts from the programmer.

Education varies wildly, and overall in industry you will not apply 100% of your learnings. I'm sure I forgot plenty of algorthms that others use daily. Likely, others forgot plenty of low-level memory management than I use daily.

Let's not turn this into a programmer measuring contest. They are different concepts and tools done for the purpose of solving problems, not flexing IQ's. coments like this are no better than the ones you complain about.

Re:I am sick and tired of hearing tech companies complain ab... by FpUser on Wednesday May 19, 2021 @12:13AM (#27204494)
I develop business backend servers in C++, no problems there and no hardware / embedded is required. I also happen to be familiar with electronics and do develop firmware every once in a while but I mostly use plain C for that.
Re:I am sick and tired of hearing tech companies complain ab... by JAlexoid on Wednesday May 19, 2021 @01:32AM (#27204929)
That sounds like you're trying to stab yourself in the face...

The unfortunate bit is - there is a lot of people that are learning Python or TypeScript that can develop that business logic as fast as you at a fraction of the cost.

Re:I am sick and tired of hearing tech companies complain ab... by FpUser on Wednesday May 19, 2021 @03:57AM (#27205800)
>"That sounds like you're trying to stab yourself in the face"

Sounds like you have no idea what are you talking about. It was exactly Python project I've recently completely rearchitected, rewrote and greatly improved. Client can't thank me enough as it performs hundreds of times better than the old one. And from what the client told it was developed in less time than the original Python version.

In general I use multiple languages including Python. I just do not see anything in Python that noticeably speeds up development of big and complex projects vs modern C++ ( or any other decent language for that matter ).

You just have to know what are you doing. Language is secon

Re:I am sick and tired of hearing tech companies complain ab... by ackfoobar on Wednesday May 19, 2021 @12:49PM (#27211196)
Here's what I expect will happen when an average developer is "to learn C++ on the job":

The inexperienced developer will write code that is subtly wrong. The senior developers will spend more time debugging than the time would take to write the code themselves. The new hire will effectively have negative productivity. And when the new hire has learned enough, s/he will get a new job. The comapny will not have recouped the investment on the developer.

Re:I am sick and tired of hearing tech companies complain ab... by huggybear on Wednesday May 19, 2021 @01:37AM (#27204969)
I've been writing C++ for like 15 years now and still need to visit Stack Overflow 500 times a day to do my job. It is not a language somebody picks up on the job.
Re:I am sick and tired of hearing tech companies complain ab... by UncleOxidant on Wednesday May 19, 2021 @12:57AM (#27204737)
I tend to agree with him that it's pretty easy to pick up adjacent languages... But not C++. Too many footguns & dusty corners.
Re:I am sick and tired of hearing tech companies complain ab... by xapata on Wednesday May 19, 2021 @12:02AM (#27204403)
Depends on whether you have any experienced C++ folks on the team who can mentor, review, and hack out the tricky bits.
Re:I am sick and tired of hearing tech companies complain ab... by MattGaiser on Wednesday May 19, 2021 @12:03AM (#27204415)
But if that is the person you need, expecting them to already know C++ is entirely reasonable.
Re:I am sick and tired of hearing tech companies complain ab... by blihp on Wednesday May 19, 2021 @03:14AM (#27205546)
Yes, for typical corporate development tasks which is the bulk of the tech job market. As long as they are reasonably seasoned vs what you need done and you don't throw them in to the deep end on day one. Every language has quirks and corner cases but after you've learned enough of them, the oddities don't tend to trip you up for very long. Learning the specific frameworks and business knowledge tends to be the lions share of the learning that needs to happen... takes longer but also not a big deal.

Realistically, the majority of developers spend their days doing rather mundane work with CRUD/data-munging probably being a good description for most of it (regardless of whether it's server/desktop/mobile/web) which isn't rocket science. Now if you need an expert to write a memory management system for language X on OS Y, that's a different story.

Re:I am sick and tired of hearing tech companies complain ab... by unnouinceput on Wednesday May 19, 2021 @01:46AM (#27205030)
Coming from Pascal/C/C++ to Java in early 00's I really hate it the style of non-existing global variables. To use global variables I had to declare another class? Such heresy!! To this day I still hate Java, personally, but when it comes to a real challenge I really don't care the programming language. Programming languages are tools, each fits better for a particular problem and my clients pay me to solve their problems, not to bitch why one language is better than other.
Re:I am sick and tired of hearing tech companies complain ab... by rmk on Wednesday May 19, 2021 @02:32AM (#27205287)
That ain't happening with C++ unless you have a very good understanding of the bazillion things C++ lets you control. Just deciphering the STL errors when you compile is a headache. C++ gives you way too much rope to hang yourself with, compared to even languages like C, which is already a tough thing for someone who's never worked with a language where there is no garbage collection and typing is not strict.
Re:I am sick and tired of hearing tech companies complain ab... by UncleMeat on Wednesday May 19, 2021 @08:17AM (#27207541)
I think this really depends.

If you are at a company with highly automated style checking, strong developer education resources, and a culture of using sanitizers all the time - you can let people learn C++ on the job.

But if you are just writing code with code review from other team members as your only option? Oof. C++ is a barrel of knives. Incredibly safe looking code can actually be filled with horrible horrible nightmare bugs.

Re:I am sick and tired of hearing tech companies complain ab... by vkou on Wednesday May 19, 2021 @12:54PM (#27211268)
The problem with C++ is that every firm has their own flavour of C++ that they use.

Someone experienced in C++ will be able to pick it up a lot faster than someone transitioning from the Java world, but there's always going to be a fair learning curve for a new hire.

Re:I am sick and tired of hearing tech companies complain ab... by fpig on Thursday May 20, 2021 @06:03AM (#27219308)
I've probably spent ~1000 hours writing C++ in my life (admittedly, years ago) and objectively speaking I wouldn't hire myself even as a junior C++ dev.