r/shittyprogramming • • Jul 23 '21

#define yeet throw

134 Upvotes

25 comments sorted by

109

u/Yoghurt42 Jul 23 '21

Fun fact: Rust currently uses yeet as a placeholder for throw/raise to avoid bikeshedding while the feature is being finalized

98

u/myusernameisokay Jul 23 '21

yeet is a bikeshed-avoidance name for throw/fail/raise/etc, used because it definitely won't be the final keyword.

That’s a shame because that’s fucking hilarious

21

u/[deleted] Jul 23 '21

How does rust handle errors then? Just uses the Result type? I figured they wouldn’t implement a try/catch since the Result kinda handles it, but I am a noob so I’m not sure

26

u/toastedstapler Jul 23 '21

Yep, errors are data just like happy path code in rust

8

u/MichiRecRoom Jul 24 '21

As far as I'm aware, Rust has two main ways to deal with errors. Result<T, E> for recoverable errors (which can be handled by the developer, allowing them to determine whether to continue the program or force an exit), and panicking for non-recoverable errors (which always result in the program exiting immediately).

For more info, I'll point you to the Rust Book's section on error handling.

→ More replies (3)

30

u/Totally_Generic_Name Jul 23 '21

Temporary solutions tend to be the most permanent kind of solution…

1

u/Lucretiel Aug 13 '24

This is just for the keyword, while the semantics are being defined. 

9

u/AegisCZ Jul 23 '21

not a toy language at all

10

u/ShitTalkingAssWipe Jul 23 '21

thank you, adding this to my templates

8

u/LePootPootJames Jul 24 '21

The busiest airport in the U.K.

5

u/SaltyWolf444 Jul 23 '21

I don't know too many programming languages, could you tell me which language is it in?

29

u/Spocino Jul 23 '21

C++, the only popular language with #define and a throw keyword.

13

u/gayscout Jul 23 '21

C# also has #defines and throw, but I don't think they are macros, so this wouldn't work as expected.

5

u/doublestop Jul 24 '21 edited Jul 24 '21
[DebuggerNonUserCode]
static void Yeet(this Exception ex) => throw ex;

new ArgumentException().Yeet();

Too bad there's no way to extend a rethrow without resetting the stack trace.

3

u/Spocino Jul 25 '21

yeah, it looks like the only use of the #define is conditional compilation, a la #ifndef NDEBUG et cetera.

1

u/SaltyWolf444 Jul 23 '21

Thanks for the answer! I do not much C++ experience, other than arduino programming, but I'll definenietly look into it sometimes.

0

u/SaltyWolf444 Jul 23 '21

After a bit of reading I'm guessing that it is C.

15

u/[deleted] Jul 23 '21 edited Jul 24 '21

C doesn’t support exceptions and the whole try catch thing which in general is not very memory safe. It’s likely C++

3

u/[deleted] Jul 23 '21

Put that shit on a t-shirt!

1

u/UrAccountGotHacked Aug 06 '21

Hey man i would like to talk to you in DMs. How can I?

0

u/[deleted] Jul 23 '21

[deleted] — view deleted comment

37

u/jarfil Jul 23 '21 edited Oct 29 '23

CENSORED

9

u/kobbled Jul 24 '21

The opposite of yeet is yoink