Hacker News new | ask | show | jobs
by adityamwagh 14 days ago
> It seems to me that the C++ Standards Committee is doing a decent job maintaining the language, and introducing useful features when it makes sense to do so.

This can’t be further from truth. C++ is essentially Frankenstein’s monster.

4 comments

All mainstream languages that survive 1.0, have a bit of Frankenstein into them.
And the real monster was the one who created it all along!
An articulate creature that hounds its creator for abandoning it?

If anything it is more of a Chimera

I believe one of the main goals of whatever shadowy organizations are behind the "standards committee" is to sabotage the language to help clear the way for Rust.

If these people really have a great idea for what the future C++ should be like, then they should introduce that language all at once. Let us see their grand vision in one big package that can be embraced or rejected. This steady drip-drip-drip of half-baked features every few years is creating one hellish language.

I spend a lot of time in the Chromium source code and have seen plenty of boneheaded code, especially in places like Autofill where they seem to turn the newbies loose, but also in surprising places like V8, due to newbs using newfangled C++ "features" to do what worked perfectly well before in older idioms and was easier to read also.

Take for instance the function TryReduceFromMSB in v8/src/compiler/turboshaft/wasm-shuffle-reducer.cc -- do you see any reason that std::optional<uint8_t> max; couldn't just be a regular uint8_t? Let's name it 'max_used' also so the name is more descriptive and doesn't clobber the namespace.

>do you see any reason that std::optional<uint8_t> max; couldn't just be a regular uint8_t?

It's so that

    if (max)
is truthy iff max has been assigned (including the case where it's been assigned zero).

I don't know if it's possible for max to be assigned zero in this specific context, or what the correct behavior is if max==0. However, the good thing about this code is that it clearly communicates that the intended check is 'has been assigned to' rather than 'is nonzero'.

The function, for reference:

    void WasmShuffleAnalyzer::TryReduceFromMSB(OpIndex input,
                                               const Simd128ShuffleOp& shuffle,
                                               uint8_t lower_limit,
                                               uint8_t upper_limit) {
      DemandedBytes demanded = GetDemandedBytes(&shuffle);
      std::optional<uint8_t> max = {};
      for (unsigned i = 0; i < demanded.bytes(); ++i) {
        uint8_t index = shuffle.shuffle[i];
        if (index >= lower_limit && index <= upper_limit) {
          max = std::max(static_cast<uint8_t>(index % kSimd128Size),
                         max.value_or(uint8_t{0}));
        }
      }
      if (max) {
        // input can be reduced.
        TRACE("Can reduce Op %d based upon max used index: %d\n", input.id(),
              max.value());
        demanded_byte_analysis_.Add(
            input, DemandedBytes::LowFromMaxShuffleIndex(max.value()));
      }
    }
The same organisations are behind Rust Foundation, and are responsible for the LLVM and GCC compilers, written in C++, rustc depends on.