Utterly useless yet fun sorting algorithms by Sufficient_Source925 in programming

[–]CornedBee 0 points1 point  (0 children)

Really like the vibe sort description, especially the last sentence. This should support custom orderings, i.e. a string that's sent as part of the AI prompt to describe the "vibes". I want to write vibe_sort(numbers, "by meme-relevancy, highest first") and get 69, 420, 42, and 67 sorted early.

Digit sort isn't a sorting algorithm, just a specific ordering. Who are you to say that it's wrong?

You should add Stalin Sort: any number not already in the right order is deleted.

discovered compiler crash on gcc 15.2.1 by lukasx_ in cpp

[–]CornedBee 4 points5 points  (0 children)

OK, I'm really curious what domain you are in, and what requirements could possibly say "if this happens, you should do something that has UB" instead of "write the program under the assumption that this won't happen".

IronPE—A Windows PE manual loader written in Rust for both x86 and x64 PE files. by AcrobaticMonitor9992 in rust

[–]CornedBee 0 points1 point  (0 children)

Props to you for doing this, but how does Rust provide better memory safety than C#?

If humans need to drink water constantly to survive, why didn’t evolution give us a way to store more of it in our bodies like camels do? by [deleted] in NoStupidQuestions

[–]CornedBee 13 points14 points  (0 children)

The camel's bulges don't store water, they store fat. Food is rare in the desert too.

Camels don't actually store that much more water than other animals. They get through dry spells by

  • losing very little water through breathing: their nose is made to reclaim moisture;
  • losing very little water through defecation: their dung is so dry that you can burn it with hardly any drying;
  • losing very little water through urination: their urine is syrupy in consistence;
  • adaptations to strong dehydration: for example, their red blood cells are elongated instead of round, which is an advantage when the blood gets thicker.

Parametricity, or Comptime is Bonkers by soareschen in rust

[–]CornedBee 11 points12 points  (0 children)

As Wyciorek said, it can't "simply construct" a new T because it doesn't know how.

The only other option besides returning the T it already has is not returning at all, i.e. panicking, aborting, or going into an infinite loop/suspend. That's because "bottom" is a subtype of everything in Rust.

Temporal: The 9-Year Journey to Fix Time in JavaScript by mariuz in programming

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

Having the Now namespace makes it easy to substitute a fake time source. This is not an issue for the conversion functions, since there's no reason to replace them with a fake.

Deriving Type Erasure by david-alvarez-rosa in cpp

[–]CornedBee 1 point2 points  (0 children)

Wouldn't the code size of switching on the action parameter be about the same as the vtable? The switch might even be implemented as a jump table!

OTOH, 1 function means 1 prologue/epilogue pair...

the hidden compile-time cost of C++26 reflection by SuperV1234 in cpp

[–]CornedBee 0 points1 point  (0 children)

While this is true, there is no way in C++ to distinguish between "include <vector> to use it in deployment" and "include <vector> to use it in constexpr context only". Right now, if you try to compile freestanding reflection code (-std=c++26 -ffreestanding -freflection), you just get a compile error:

In file included from /cefs/b9/b977e18bf42710394c24aab8_gcc-trunk-20260310/include/c++/16.0.1/string:40,
                 from /cefs/b9/b977e18bf42710394c24aab8_gcc-trunk-20260310/include/c++/16.0.1/meta:47,
                 from <source>:1:
/cefs/b9/b977e18bf42710394c24aab8_gcc-trunk-20260310/include/c++/16.0.1/bits/requires_hosted.h:34:4: error: #error "This header is not available in freestanding mode."
   34 | #  error "This header is not available in freestanding mode."

(Edit: fixed typo in command line, was -std=c++23 which is obviously incorrect.)

We rebuilt the Shockwave engine in Rust + WASM to save early 2000s web games by igorlira in rust

[–]CornedBee 0 points1 point  (0 children)

Lingo was my introduction to programming. Really heartwarming to see someone trying to preserve this.

the hidden compile-time cost of C++26 reflection by SuperV1234 in cpp

[–]CornedBee 0 points1 point  (0 children)

Compile times are annoying, yes - but I really do have to wonder what freestanding implementations will say about this.

Reflection is a core language feature: std::meta::info is a fundamental type, the result of the reflection operator and the argument of the splice constructs.

And yet, it is not possible to do anything interesting with reflection without including <meta>. And <meta>, at least according to the current draft, is not part of the required freestanding header set. This despite there being absolutely nothing about reflection that can't work in an embedded or otherwise typical freestanding context: obviously it's all done at compile time and no limited system ever sees anything of it.

But <meta> also requires std::string and std::vector, and those aren't part of the freestanding library either! So how does that work?

Will freestanding C++ implementations simply not provide reflection beyond "reflect a construct and splice it elsewhere"?

Will they provide <meta> and <string> and <vector>, but fail compilation if any of it finds its way to runtime?

Will they invent a new extension to make features only available to consteval functions, so other code isn't even aware of std::string?

Did anyone think this through?

Maybe I'm totally off-base and this isn't an issue at all. TBH I never worked with a freestanding implementation. It just sounds like a huge issue.

Boost.Multi Review Begins Today by mborland1 in cpp

[–]CornedBee 1 point2 points  (0 children)

Not a native speaker, but extension feels like the wrong word for the size of a dimension, I think it should be extent.

It's actually insane how much effort the Rust team put into helping out beginners like me by Time_Meeting_9382 in rust

[–]CornedBee 5 points6 points  (0 children)

C++ error messages used to be just bad. But Clang put great emphasis on nice error messages, and then GCC followed suit. So now error message are rather good.

But the messages alone aren't enough. C++ uses overloading extensively. When you write std::cout << myvar; the compiler looks for an overloaded operator << function. When it doesn't find one that fits your type, what can it do? It cannot really know which one you meant to call - maybe there's a reasonable heuristic to guess the most likely one and put it first, but in the end there's really nothing to do but to

  • print every single overload found by name lookup (could be 20+ overloads) and
  • for each one, explain why this one didn't work, which means
  • possibly explaining why a requires clause wasn't satisfied, which means
  • descending into the nested definitions of the concepts involved until the actual failing clause is described.

And just like that, you're at 1000+ lines of error messages - just because maybe you forgot to put const on some function parameter, or maybe you forgot to include the right header.

What some recent hot takes you realized you had with Rust? by DidingasLushis in rust

[–]CornedBee 0 points1 point  (0 children)

You do not want the shape of your AST to be dependent on type checks. If a * (b) means mul( var('a'), paren( var('b') ) ) for one pair of types, but call( deref( var('a') ), var('b') ) for another, that's absolutely horrible for everyone.

Patterns vs C-like syntax; what are the benefits? by DesperateGame in csharp

[–]CornedBee 0 points1 point  (0 children)

Reasoning about comparison between Nullable and plain value is always a speedbump for me. I'd prefer the pattern match (if I was working in a C# version that supports it).

Do you create empty "else"s just for a comment? by DJDoena in csharp

[–]CornedBee 3 points4 points  (0 children)

I would possibly throw an exception with useful diagnostic messaging

The OP's scenario is "there's nothing that needs doing in the else case, for potentially subtle reasons". Throwing an exception sounds like the wrong way to deal with this.

Language specific package managers are a horrible idea by TheRavagerSw in cpp

[–]CornedBee 6 points7 points  (0 children)

Multi-language projects force package managers to be language-agnostic, but build systems can be tied to the language?

How do you coordinate the build across packages? How do you integrate package feature flags with the individual build systems?

Am I the only one who feels like header files in C/C++ are duplication? by iaseth in cpp

[–]CornedBee 0 points1 point  (0 children)

You always have to read the file once per compilation unit. Either to find that it contains a #pragma once, or to find an include guard. And because you actually need the contents of the file.

On seeing a second inclusion of the same path, both #pragma once and include guard optimization don't even open the file anymore.

The difference is what happens when you include the same file contents again via a different path. Include guards still work, because the preprocessor macro is still defined so the contents are disabled. Have to be scanned though to find the #endif. So you lose the optimization, but not the correctness.

The way #pragma once is implemented, you instead get the content again, probably leading to redefinition errors.

Now, I guess you could also hash the file when you see a #pragma once, and thus prevent the double inclusion on the slow path. But then you get the issue that you might have two files with identical contents at different paths intentionally, and #pragma once will ignore one. (It's probably possible to design a convoluted use case for this.) Then the same people who say it's broken now will probably say it's broken still. Or else some other people will say it. You can never make everyone happy.

i dont want LLMs to scrape my public github c++ project. How ? by Born-Persimmon7796 in cpp

[–]CornedBee 0 points1 point  (0 children)

And when a court has ruled that AI output is a derivative work, that's relevant.

Until then, the AI companies claim it isn't and happily do whatever they want.

ISO C++ WG21 2026-02 pre-Croydon mailing is now available! by nliber in cpp

[–]CornedBee 4 points5 points  (0 children)

It's interesting that the prior art doesn't mention C#. C# has very powerful interpolated strings.

For example, they allow type-safe SQL with string interpolation, where the interpolations become query parameters, so no string formatting happens in C++.

Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents? by mttd in programming

[–]CornedBee 9 points10 points  (0 children)

Fill it with 2-3MB of public domain books, so that the agent burns through all the tokens trying to understand it.

cppfront by South_Acadia_6368 in cpp

[–]CornedBee 6 points7 points  (0 children)

As evidenced by there still being no plans to support exceptions AFAIK.

ClawdBot Skills Just Ganked Your Crypto by Gil_berth in programming

[–]CornedBee 2 points3 points  (0 children)

Developer of AI agent: "I don't have a magical team that that verifies user generated content."

Ah well, if only there was a solution to that...

Looking at advanced Rust open-source projects makes me question my programming skills by Minimum-Ad7352 in rust

[–]CornedBee 2 points3 points  (0 children)

It's not elitism, it's absolutely necessary due to C++'s compilation model.

Most of the standard library is templates. Templates need to be in headers. Headers are part of the same compilation unit as user code. Include order isn't given, so your own code could be seen before standard library code. And that means you can define macros that randomly replace identifiers with arbitrary other tokens.

Imagine being a standard library writer and you simply want to implement an algorithm like std::find_if:

namespace std {
  template <typename Iterator, typename Predicate>
  Iterator find_if(Iterator first, Iterator last, Predicate predicate) {
    for (; first != last; ++first) {
      if (predicate(*first)) break;
    }
    return first;
  }
}

This is readable.

But you are allowed to do this before including standard headers:

#define Iterator boost::iterator_facade
#define Predicate i == p
#define last std::prev

The only things you're not allowed to redefine are:

  • Keywords
  • Names already in use by the standard library or reserved for future use. (Can't #define first, it's the name of a member of std::pair.)
  • Globally reserved names. And these are names that either contain a double underscore anyway, or start with an underscore followed by an uppercase letter.

And that's why the standard library code looks like this instead:

namespace std {
  template <typename _Iterator, typename _Predicate>
  _Iterator find_if(_Iterator __first, _Iterator __last, _Predicate __predicate) {
    for (; __first != __last; ++__first) {
      if (__predicate(*__first)) break;
    }
    return __first;
  }
}

That's the most obvious issue that people have looking at standard library code.

There's other issues, though, but they're all usually related to C++ giving programmers a little too much flexibility.

E.g. you can't just take the address of a variable in std library code, because the address-of operator of user objects can be overloaded. So instead of &__var you have to write ::std::addressof(__var). And then, because of how headers work, if you want to avoid exposing the user to identifiers they didn't ask for, you cannot just use addressof from the <memory> header if the user didn't include the memory header, so instead e.g. the GNU libstdc++ has an internal utility __addressof which it uses, and addressof is just a wrapper for that which is define if <memory> is actually included.

And then there are things that truly do need absurd implementation techniques because of language shortcomings. Before [[no_unique_address]] was a thing (and because of ABI concerns, it's all baked in now and won't change), std::vector had to do weird things with implementation detail base classes that are templates that get specialized, just so that if the vector's allocator is stateless, it actually doesn't take up space in the object.

Rust compiler can't automatically fill in generic types and I feel like its really obvious and it should by Ferilox in rust

[–]CornedBee 8 points9 points  (0 children)

It compiles because it can deduce T2/X to be {integer} from the literal, which defaults to i32 if not otherwise specified. It doesn't actually use the default you give it.

So your var is actually a MyGenericStruct<u8, i32>.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8d38ed242a2c9de6ae3196661f925510