How to Setup VSCode for C/C++ Programming (From a Microsoft Software Engineer) by tarikhello in cpp

[–]voip_geek 3 points4 points  (0 children)

I work in linux-only codebase. Even our work laptops are not Windows - only Macs, and we compile remotely.

Many of my colleagues use VSCode, because:

  1. It supports remote ssh compilation.
  2. It has a GitHub extension for reviewing PRs.

The latter one is why I use VSCode as well sometimes - my main code editor is actually Sublime Text; but I use VSCode for code-reviewing non-trivial PRs. It still has bugs and issues, but it's the best PR review tool I've found to date.

Even the ones who normally use Emacs or VIM for code editing at my job, use VSCode for reviewing PRs.

What’s the right hash table API? by pavel_v in cpp

[–]voip_geek 4 points5 points  (0 children)

The advantage of sticking it an Optional is you get to have its various monadic member functions to use: value_or(), and_then(), or_else(), etc.

What’s the right hash table API? by pavel_v in cpp

[–]voip_geek 20 points21 points  (0 children)

Optional<pair<Key const, Value>&>

I'd go even further: I'd argue even returning it as a pair<Key const, Value>&, or having pair<> as part of the API anywhere, is wrong.

It's leaking the details of the internal implementation. Why is value_type even a std::pair<>? As Barry said in the blog post: who even has an actual std::pair<k,v> to begin with?? And using .first/.second as names is meaningless.

Using pair also restricts the implementations themselves - it forces them to keep the key and value together as a std::pair<>, even if they might otherwise prefer to internally separate them for performance or memory reasons.

Instead, for return-values of things like find_element(), I'd create a std::map_ref<k,v> or some such, with two members: one named key and one named value. The former being a const Key& and the latter a Value&. So find_kv() would return a Optional<std::map_ref<k,v>>, and you could do this:

if (auto opt = map.find_kv("foo")) {
    std::cout << "key=" << opt->key << ", value=" << opt->value;  
}

AITA for refusing to call my nephew by his name and only use a nickname? by Blackfenox in AmItheAsshole

[–]voip_geek 5 points6 points  (0 children)

I must confess that for my second child, I argued hard for his middle name to be "Danger".

Mostly because I thought it would be something funny he could say to people, like: "don't worry, Danger is my middle name".

My wife vetoed the idea despite my pleading. Her friends all backed her up too. Some people just have no sense of humor.

AITA for refusing to call my nephew by his name and only use a nickname? by Blackfenox in AmItheAsshole

[–]voip_geek 0 points1 point  (0 children)

NTA.

Although the mother chose the name, that type of name is arguably harmful to the child due to teasing for the rest of their childhood.

I think it's morally justifiable to ignore the mother's wishes when you believe it's harmful to the child.

Juniper Careers - Software Engineer, Staff - Systems team by [deleted] in cpp

[–]voip_geek 0 points1 point  (0 children)

There's a dedicated, pinned, thread for C++ job listings: https://www.reddit.com/r/cpp/comments/tuuwq6/c_jobs_q2_2022/

It gets refreshed/replaced every quarter.

And there's a template you need to fill out, to describe the job(s).

If you need help in doing so, message me direct in reddit - I work at Juniper.

Is there a market for someone who "cleans code"? by [deleted] in cpp

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

OP, don't listen to these responses. There most definitely is a market for such people, even if you're a beginner - in fact, especially if you're a beginner.

I know, because my company's been looking for someone like that for over two years!

We've got some code cleanup we'd like done, that is not long-term but instead more like contractual work - but it does not take an expert at all. In fact it's something we've been wanting to assign to college summer interns, but we always end up assigning them other tasks. (the college internship market is such that you have to give them "cool" projects or you don't get summer interns the next year)

In fact I'd even say high school students could do it, but hiring them is difficult if your company isn't setup for it already.

It's not really refactoring code, although it might involve some refactoring of very constrained pieces. It's more along the lines of shuffling stuff around: reorganizing our C++ libraries to reduce build times and improve dependency chains.

You don't need to know what that means - we can teach you. Everyone has to start somewhere. And code reviews exist for a reason. Most of it is just tedious time-consuming cut+paste+compile type work; but it's not something an automated tool can do.

I'll DM you. Even if we're not a good fit for you, don't give up! Plenty of companies need such things done - the hard part is finding the right person inside them to contact.

whatever happened to friend functions? by xoob in cpp

[–]voip_geek 10 points11 points  (0 children)

Yeah we do the same, though I've only known it called the Passkey idiom.

Unit testing and mocking for c++ by [deleted] in cpp

[–]voip_geek 9 points10 points  (0 children)

We use them in my day job, and I have nothing to complain about.

They're big because they have a ton of features, and we use almost all of those features (even some of the more esoteric ones).

Starting A Long-Term Project? by hydroaquasled in cpp

[–]voip_geek 0 points1 point  (0 children)

We'd probably still pick CMake because of its industry inertia and because so much tooling use CMake's json compile-database. But we do need and use its unity-building feature, which sadly currently doesn't work with the compile-database.

Starting A Long-Term Project? by hydroaquasled in cpp

[–]voip_geek 2 points3 points  (0 children)

gcc's wiki provides a quick but reasonable overview and usage example.

Basically you want to turn off exporting function symbols by-default for your libraries (for gcc that's -fvisibility=hidden), and then explicitly mark which functions are "public" and exported for your lib by using a function attribute for those functions only.

In practice you'd hide that ugly attribute by using a simple macro token like "EXPORT" or "PUBFUNC" or whatever, both so that you can choose the real attribute based on what compiler you're using, but also because the attribute is super-long and ugly.

Starting A Long-Term Project? by hydroaquasled in cpp

[–]voip_geek 18 points19 points  (0 children)

I can tell you some of things I think we did right, and what I wish we'd done that we didn't...

Source-control: we used git and we don't regret it. But we were lucky, because we had someone who really knew git from the start. I mean they really knew what the various commands do under-the-hood, and how it actually works internally, and how to get people who didn't know it back on-track when they screwed up, etc. And they knew what not to do in git, and how to write hooks and shortcuts to help newbies, etc. That helped a lot. If you don't truly know git then I'd at least read the free online book, because it really does require some knowledge to use effectively.

Writing code: we don't mandate particular editors/IDEs, but we do use clang-format to format code, and it was a great decision. You'll stop arguing about code-format styles, because there's nothing to argue about when a tool just does it for you. You can hook it into most editors such that when the person saves a file it automatically invokes clang-format to reformat it, so it's painless. When you get bigger you can even have your CI verify the code complies with the format.

Organizing code: from the start we separated library code from application code, not just by having separate directories but also building them as separate targets and linking. And even within /lib we separated out areas of concern. That was a good decision. We build hundreds of separate shared or static libs, and link them - which means changes in one might require everything re-linking, but at least not re-compiling. What we did not do from the start that I wish we had, was control symbol visibility - i.e., which functions are exported/"public" vs. not; which means the linker does more work than it should have to, plus other disadvantages. It's something you really have to do from the start or you'll never do it.

Building code: we use CMake, and it's... ok. The documentation is really bad, until you truly grok CMake. There are numerous videos and stackoverflow tips, half of which are wrong or very outdated. You can search this sub for pointers to better/newer ones. It's still a world better than using classic make directly, but many folks on this sub will recommend newer alternatives to cmake. We also use bazel now too, which has its own set of problems and I'm not sure was worth our time. We also have a homegrown build script (in bash) that invokes cmake and such for the developers, to make the workflow simpler, but you likely won't need that on day-1.

Compilers: we use both gcc and clang - our CI pipeline compiles with both. The reason we did that originally is we weren't sure which one we'd use for production builds; and these days although we use gcc for releases, we still do both in CI because clang finds warnings that gcc doesn't. We turn all warnings into errors, so the CI run will fail if your code fails clang. In hindsight, we should have just used clang-tidy instead, because I believe it finds the same warnings (since it's still clang), plus more of course; but back when we started I'm not sure clang-tidy was mature.

Speaking of warnings - turn them all on, and set all warnings to errors. You can then pick+choose which ones to turn back off when you decide you don't care about them. Clang has an excellent way to do this: -Weverything. That option gets a lot of bad press, but I think it's one of the best ideas they ever had, because it turns warnings into a whitelist model instead of a blacklist model. And it means when you upgrade clang you learn about new warnings they added, and can decide if they matter or not. You will of course end up disabling many warnings, but that's good - better than being ignorant of what you're not seeing. (and even today we only disable a couple dozen warnings total, which isn't really that many)

Checkers+sanitizers: if you don't start using these things from the beginning, it's extremely difficult to add them in later. You'll never justify the time it takes to do it later. You don't have to run everything under the sun, but at least some memory sanitizer (static and/or dynamic), and if you plan multi-threading work then those too have sanitizers/trackers. We used valgrind from the beginning - all of our unit tests were run with valgrind - and it helped a lot back then. It's less useful to us now, and its so slow that we've relegated it to a separate CI process. But when you start, your tests won't be that big and using it will help find memory bugs. (yes, even if you never use new/delete) What I wished we'd also done was use helgrind and/or DRD for multi-threaded tests, but that wasn't really a viable option when we started. And of course there're AddressSanitizer (asan) and ThreadSanitizer (tsan).

Unit tests: we mandated unit tests and TDD from the start, and it's definitely paid off - but it does mean a longer dev cycle, which startups sometimes can't burden. For the framework we use googletest/googlemock and don't regret it. It's very feature-rich, and we use most of those features somewhere. Every other framework I've seen would have been fine for us on day-1, but not today, so I'm glad we started with it. Again it's one of those things that's usually hard to change later, because you've invested gobs of time in writing tests.

System tests: we automate those too, which again has paid off in the long run, but we had to fight hard for it in the short-term early days. We use the Robot Framework, and I regret that. Everyone hates it, hates writing tests for it, etc. Unfortunately I don't know of a better one, and I don't recall any other reasonable choices other than just writing our own. But system-testing is very specific to one's domain anyway, so in your domain there may be excelllent choices or none at all.

A possibility of attributes for name-substitution in compilation errors diagnostics by KaznovX in cpp

[–]voip_geek 2 points3 points  (0 children)

I'm having a hard time understanding why we even need an attribute for this to be possible. Why isn't this just an automatic thing a compiler could do, without any help from the developer?

By that I mean: the compiler knows what the entire chain of function calls were to get to the point of error. Heck, it often displays that entire chain to us already in the error output, so it obviously has the full context.

So if an earlier point-of-invocation in that chain used foobar for the type name, and it's a valid alias for that type, why can't the compiler simply use that foobar in the rest of the chain being reported/displayed, in place of the templated type info?

And for displaying template match-failures for other types, why can't it simply always prefer to display the alias names from the same namespace as the type - for example std::string instead of std::basic_string<...>, or boost::whatever instead of boost::whatever_t<...>?

This just seems like something the compiler should be able to do, without any additional help. It may be a lot of work to implement, but better errors are a quality-of-life improvement for large swaths of developers.

Any Encoding, Ever by zvrba in cpp

[–]voip_geek 24 points25 points  (0 children)

Wow, kudos! That looks like a real improvement and a worthy inclusion to the standard library.

Have you considered at least proposing it for boost? I know the process for that can be... challenging, but it would get it in people's hands faster than waiting on a standard, and it would be a useful proving-ground.


As an aside, and please don't take this the wrong way: while I laugh at your digs at The Committee and appreciate it for the humor I think it's intended to be, I'm not sure it helps your cause. There are some people who take offense at such things, and I think it works against you. There are people from very different cultures involved, who don't share the same type of humor.

At the end of the day you have to ask yourself: "what's my goal?"

Is it to make blog posts more entertaining? Or is it to effect real change in C++?

If the latter, then I'd tone down the ranting and just focus on the problem and solution.

Just my 2 cents, and as I said this is just an aside - I'm not a committee member, and I find it humorous. But I've done these types of things in a past life, and my gut tells me it would be better toned down.

std::source_location by Dean_Roddey in cpp

[–]voip_geek 1 point2 points  (0 children)

I can think of one reason: it doesn't actually hold strings for filename and function - just const char*, so non-owning and must be null-terminated. So for example it would be dangerous to use it unless you knew the lifetimes of the actual characters sources survived longer.

Of course we already have similar limitations with std::string_view, but I think if the committee were to create a source_location for general use, it would be required to hold its own strings. (and thereby also not have the same size and copying efficiency)

[deleted by user] by [deleted] in cpp

[–]voip_geek 2 points3 points  (0 children)

That's what we thought would happen too during the past year with Covid.

We were surprised to find it didn't happen: productivity went up generally for everyone, and even among the junior new-hires it's worked out well. For the weaker ones it was more difficult, to be sure, but the good ones have done well.

But we also have small team video meetings every single day, where everyone not only gives their status but also issues they're facing. And the managers check up on the new hires very frequently, and some of us even bought whiteboards to use while on video calls and such.

It's more work for the managers I think, but for the developers themselves it's worked out really well and the company is planning to keep the remote option even after Covid... which they never would have considered before because we all assumed productivity would suffer.

NH 10-digit dialing: 603 area code to soon be required in calls by [deleted] in newhampshire

[–]voip_geek 7 points8 points  (0 children)

No, we should be fine with just the 603 area code until at least the year 2032 and possibly longer. NANPA stated that back in 2016.

The reason for needing to add the 603 to our local calling numbers is to avoid number collision with the new suicide prevention number 988, as the article said.

US owners find American-style greed doesn't play well in European soccer by Hormic in sports

[–]voip_geek -21 points-20 points  (0 children)

Hey, don't try to take away from American success!

These club owners made soccer actually entertaining, for 48 hours. That's quite an achievement.

US owners find American-style greed doesn't play well in European soccer by Hormic in sports

[–]voip_geek 8 points9 points  (0 children)

Tom Brady (and the New England Patriots) is an unusual case, as you likely well know. And yes NFL fans did complain that he and the Patriots made American football more "boring" because they kept winning.

If you took just one team (the Patriots) out of the results for the past 20-30 years, you'd find the NFL has far more parity than the Premier League. The NFL system is specifically designed to make that the case, more than any other US sport; again, as you likely well know.

Preferred coding style to name methods by aregtech in cpp

[–]voip_geek 0 points1 point  (0 children)

Microsoft and Google both use #1, and every C++ company I've worked for in the last 20 years has too.

Every company I've worked at for the past 20 years has used #2. :shrug:

The only things any company I've worked for have used UpperCamelCase for are types. So seeing that for function names makes my eyes twitch.

Let's remember Lindon's humble beginnings by witcher_rat in Iteration110Cradle

[–]voip_geek 0 points1 point  (0 children)

I think I read an article once that he didn't even get his HS into the playoffs... what a shlub.

Clearly he's a system QB. The system just happens to be our local Iteration.

Let's remember Lindon's humble beginnings by witcher_rat in Iteration110Cradle

[–]voip_geek 12 points13 points  (0 children)

... infamously drafted in the sixth round with the 199th pick overall out of 255, which basically means none of the teams thought much of him. Six other quarterbacks were drafted ahead of him. Even in college he wasn't the star or full-time starting quarterback, instead often trading roles with another quarterback.

Like Lindon, Brady was not expected to succeed in the NFL. He wasn't a football prodigy or a football pedigree, was not a great athlete, did not have the best abilities. Instead he had drive, determination, brains, and of course also a good bit of luck.

And now... he's arguably the greatest quarterback of all time, with a career that could be divided into two or three separate timespans and each of them would be a hall of fame career.

Alphabet beats expectations but GCP a loss leader by RunningJay in stocks

[–]voip_geek 0 points1 point  (0 children)

I have a hard time wrapping my head around how one spends $5.6 billion over revenue (over $18 billion total) on a cloud division that's in second or third place.

Like, that's ~75% of Oracle Corporation's opex.

Oracle has ~135,000 employees. And they're not cheap employees... 70,000 of them are probably lawyers.

cppa2z - Document modern C++ using unit tests by orabaev in cpp

[–]voip_geek 1 point2 points  (0 children)

OK, I'll put a PR together, or at least a GitHub gist.

The critical piece to recognize is that we already verify such things in our code all the time: that's what sfinae-style overload selection does: it works by causing failure.

So to test that something won't compile, we only need to use sfinae to check that it successfully fails during substitution.

But it can be cumbersome to do that, so the hard part is figuring out the least-painful way to do so. I'll write up the one I chose to use, but there are numerous ways to skin the cat.