this post was submitted on 14 Mar 2024
1283 points (98.5% liked)

Programmer Humor

19606 readers
654 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] sonymegadrive@feddit.uk 16 points 8 months ago (1 children)

C++: Nuh, uh ...

template <typename T>
concept Crackable = requires(T obj) {
    { obj.crack() };
};

auto crack(Crackable auto& nut) {
    nut.crack();
}
[–] Aatube@kbin.melroy.org 2 points 8 months ago* (last edited 8 months ago) (1 children)

This is dangerous. The object might not have the crack() method, and this bloats the compiled size by a lot if you use it with different types. There's also no reason I can see to use concepts here. The saner way would probably be to use inheritance and objects to mimic Java interfaces.

[–] sonymegadrive@feddit.uk 5 points 8 months ago

This is dangerous

Well, they say you do have to be over 18 to use Concepts