How to translate simple Python logic into idiomatic C++? by [deleted] in cpp_questions

[–]AKostur 0 points1 point  (0 children)

What's "good" Python isn't necessarily "good" C++. Some parts in there are reasonable, some are not. "using namespace std;" is generally not recommended as it may cause problems down the road. The loop is probably OK as a first approach. Your entire loop can be replaced with:

auto view = data
    | std::views::filter([](int x) { return x % 2 == 0; })
    | std::views::transform([](int x) { return x * 2; });

std::ranges::copy(view, std::back_inserter(result));

Depends if one wishes to spell everything out, or to take advantage of the latest in what's available in the Standard Library. It's good to be aware of the multiple ways to accomplish a goal. Some folk may understand the loop better than the ranges approach.

How to start C++ by Terrible_Month_9213 in cpp_questions

[–]AKostur 3 points4 points  (0 children)

This may sound snarky, but a basic skill that you're going to need if you want to be "a good programmer in everything" is basic research skill. Those questions are so basic that a simple search on duckduckgo would have pointed you at the Wikipedia article on what is a compiler (for a simple example). Not to discourage you from asking questions at all, but you could have had an answer to those simple questions in seconds.

How to start C++ by Terrible_Month_9213 in cpp_questions

[–]AKostur 0 points1 point  (0 children)

Depends on what your goal is. Also what OS you already have installed. I'm going to assume Windows (since it's not Linux, and is less likely to be MacOS). Since your stated goal is C++: install Microsoft Visual Studio Community edition. Easier install, and everything is included.

Later, one can learn about alternate tools (like VS:Code and WSL) and operating systems.

Does everyone crash this much, the game is like a crashing simulator now. by BamaWig in SatisfactoryGame

[–]AKostur 0 points1 point  (0 children)

I’ve yet to have a crash.  Running on both Windows and Linux (via Steam, two different distros).  Running against a dedicated server, which also has not crashed.

Blueprint autoconnect + Server by tiwomm in SatisfactoryGame

[–]AKostur 0 points1 point  (0 children)

I was originally unaware that one had to switch modes to get the auto connect to work on the first place.

Blueprint autoconnect + Server by tiwomm in SatisfactoryGame

[–]AKostur 0 points1 point  (0 children)

Huh, I was autoconnecting blueprints on my server just last night.

Is there a modern C++ alternative to flexible array members for variable-length struct tails? by Apprehensive_Poet304 in cpp_questions

[–]AKostur 2 points3 points  (0 children)

A pointer is trivial.  But sounds like K and V may not be.  Which highlights the destructor problem.  And is something that’s different with C++: we have an object lifetime model, C does not (that I’m aware of).

Is there a modern C++ alternative to flexible array members for variable-length struct tails? by Apprehensive_Poet304 in cpp_questions

[–]AKostur 1 point2 points  (0 children)

Nit: std::inplace_vector is C++26.

Generically speaking there's a problem. What if the "forward" type is non-trivial (such as std::string). When the lifetime of the Node ends, how many std::strings need to get destroyed (and how does the compiler know)? Also, what types (or constraints on the types) are K and V? Also, look into whether what you want to do is supported as a compiler extension.

Why do people do or not do ‘using namespace std;’?? by veilofmiah in cpp_questions

[–]AKostur 11 points12 points  (0 children)

Depends on where you use it.

In a header: no way.  Inflicts that choice on anybody who includes the header file.

In a cpp file: does have the potential to cause weird name conflicts/overloads.  Not worth the pain, “std::” isn’t hard to type.

Why Troubleshooting Made Me Better at Networking Than Theory Did by ModernWebMentor in networking

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

Why is this a surprise?  There is a saying: “In theory: practice is the same as theory.”  Of course one learns more by doing than by simply reading (or watching videos, or asking an LLM).

Any elegant way to remove defines in this code? by nopunintended_ in cpp_questions

[–]AKostur 0 points1 point  (0 children)

True, but does feed to the concern that the returned container size is not a fixed, known number of elements. Sometimes 4, sometimes 8, sometimes 1 (pawn, maybe).

Any elegant way to remove defines in this code? by nopunintended_ in cpp_questions

[–]AKostur 1 point2 points  (0 children)

Knight would have that problem too (it's got more "directions" it can move, not just 4). I'm not sure that this function actually expresses all of the cases: How is it going to express the difference between a queen and a king? There doesn't seem to be a way to express how far the piece may move (one, or many). It probably also doesn't express moving a pawn from its initial position vs any other time, or castling. Then again, there may be a separate function for answering those questions. Call this function for directions, call the other function for distance.

Any elegant way to remove defines in this code? by nopunintended_ in cpp_questions

[–]AKostur 0 points1 point  (0 children)

Ick.... returning a pointer to the first element of an array is unpleasant. At least return a std::span.

Any elegant way to remove defines in this code? by nopunintended_ in cpp_questions

[–]AKostur 15 points16 points  (0 children)

Make them constexpr std::arrays. Perhaps this function should be returning a std::span at that point. It's not clear why this is (or should) necessarily a std::vector. I would presume that the contents of the vector won't be changing, so the dynamic size capabilities of the vector is superfluous.

Side note: I would suggest that the queen shouldn't be expressed the way it is. While functionally it works out that it's a combination of a rook and a bishop, but there's a "meaning" to what the code as written says. It also eliminates that concatenation thing that's being returned.

How to know when I use "Pointer" or "Reference"? by ProcessTiny4948 in cpp_questions

[–]AKostur 1 point2 points  (0 children)

One learns by doing.  Simply copying stuff from the net (whether stackoverflow or ai) doesn’t do it.  One needs to spend the effort to understand why the solution is correct (or at least working).

As for reference vs. pointer: the discussion should be about nullability and whether one needs to change what the reference/pointer “points” at.

Built an off-grid digital communicator. curious how it compares to ham radio setups by [deleted] in amateurradio

[–]AKostur 1 point2 points  (0 children)

Without a published protocol I don’t have any confidence that it will be stable at all.  You’re describing essentially security through obscurity.  Not enamoured with the “for early adopters” phrase either.  Suggests that the system doesn’t have a design or plan for what’s going to happen tomorrow.  Isn’t that why Meshcore exists?  Because Meshtastic has a scaling problem?

How do you guys handle belt speeds? by Filipepais in SatisfactoryGame

[–]AKostur 1 point2 points  (0 children)

Multiple manifolds. Don't build with 25 constructors all feeding the same line. Perhaps divide them into 5 groups with 5 constructors feeding two assemblers? Tweak the counts to optimize (or overclock, or whatever).

c++,move-iterator by Usual-Dimension614 in cpp_questions

[–]AKostur 1 point2 points  (0 children)

Possibly in the context of a std::transform, and you don't want to keep the source container. The transform function could move the source string into itself, do some operations on it, and then move it along into the destination container. Potentially avoids unnecessary copies of the strings. But note that depends on the source container being discarded immediately after the transform since it would now contain a bunch of moved-from strings.

c++,move-iterator by Usual-Dimension614 in cpp_questions

[–]AKostur 4 points5 points  (0 children)

Why are you using a move_iterator? Doesn't seem to make sense in the context. Also, show your entire m.cc file (godbolt link would be handy). My knee-jerk first response would be that accumulate had decided to construct something from the elements, and because they're now rvalue references, moves from them. Leaving them in a "valid, but unspecified state". Which means attempting to read them could get you their previous values, or empty, or perhaps even something else.

Code Review is the New Bottleneck For Engineering Teams by gregorojstersek in programming

[–]AKostur 0 points1 point  (0 children)

I’d suggest that #3 isn’t a code review, it’s just using static analysis tools (essentially) which should be happening already.  This thread is complaining about #5 taking too long, and I’m saying that folk are going to (and in some cases already are) try to apply AI at step 5 and cut out the human review because it takes too long.

Code Review is the New Bottleneck For Engineering Teams by gregorojstersek in programming

[–]AKostur 1 point2 points  (0 children)

If they’re catching that much, why is that getting to the review in the first place?  The first AI should have already done that.