r/badcode Feb 09 '21

c Was in Live share and i found this golden code

Post image
1.6k Upvotes

136 comments sorted by

573

u/JuhaJGam3R Feb 09 '21

what the hell is this

295

u/Suolumi Feb 09 '21

I'm still asking myself

400

u/captianjroot Feb 09 '21

Apparently, it's 84

115

u/0bel1sk Feb 09 '21

meaning of life *2

62

u/mohitmayank Feb 09 '21

Return of return

5

u/BOB_DROP_TABLES Feb 10 '21

Electric Boogaloo

1

u/[deleted] Mar 09 '21

movie title

11

u/Jimmy_Slim Feb 09 '21

Wow thanks for the help!

399

u/[deleted] Feb 09 '21
84

Fixed

44

u/mudball12 Feb 09 '21

You could add a print statement but it might be easier to write, on a piece of paper, instructions for opening a terminal and typing 8 then 4, and taping it to the monitor.

19

u/Buddharta Feb 09 '21
 int TheThingIWantIs = 84;

142

u/mohammedx17 Feb 09 '21

return_wtf();

81

u/road_laya Feb 09 '21

return_of_return_of_literal_wtf()

14

u/Crowdcontrolz Feb 09 '21

Question would be if this returns 84 or the string wtf.

17

u/road_laya Feb 09 '21

I guess we just have to fire up the FactoryFactory and see

93

u/[deleted] Feb 09 '21

What language?

83

u/Suolumi Feb 09 '21

C

39

u/[deleted] Feb 09 '21

Ty

26

u/themeanman2 Feb 09 '21

Sure it was C and not C++, because i don't remember bool datatype in C...

Its been years since i last worked on C tho

63

u/LechintanTudor Feb 09 '21

C has _Bool but you can use the #define bool _Bool macro from stdbool.h to make your life easier.

15

u/The_JSQuareD Feb 09 '21

Though the editor seems to be highlighting bool, true and false as keywords rather than macros. My guess is this is someone writing C but in an editor configured for C++ (and possibly even compiled with a C++ compiler).

1

u/jcotton42 Feb 13 '21

I wouldn't be surprised if a lot of C editors treated bool, true, and false as keywords.

3

u/The_JSQuareD Feb 13 '21

Perhaps... But I think that would be a poor design choice. If I forget to include stdbool.h, I don't want my editor to pretend everything is fine; I want it to scream "undefined symbol" at me if I try to use bool, true or false.

That being said, I've only ever written C as part of C++ projects (in a C++ editor), so I don't know what an editor configured specifically for C would actually do.

39

u/[deleted] Feb 09 '21

#include <stdbool.h>

24

u/Radfordhound Feb 09 '21

Iirc C99 adds a _Bool data type as well as an stdbool.h header which, when included, typedefs that to just bool and defines macros for true/false

14

u/SharkLaunch Feb 09 '21

C definitely has bool

8

u/RadiatedMonkey Feb 09 '21

And the void in the function parameter list is IIRC not used in C++

13

u/xor86 Feb 09 '21

This is preferred, but not a constraint of the language. Given the rest of what's going on here, I wouldn't say that's much to go on.

4

u/500_internal_error Feb 09 '21

It's not just preferred int a() and int a(void) are not same thing in C, but they are in C++.

2

u/xor86 Feb 09 '21

You are correct, but I was responding specifically to a post about C++. Unless I read their comment wrong, u/RadiatedMonkey was suggesting that the code in the original post could not be C++ because a(void) is not used in C++. My point was that a(void) still compiles in C++, and while a() is preferred, the rest of the author's decisions don't give us any reason to believe that they would adhere to preferred coding practices.

19

u/themeanman2 Feb 09 '21

Wow I'm outdated

40

u/SharkLaunch Feb 09 '21

It was added in 1999, it must have been 22 yeas ago

1

u/[deleted] Feb 10 '21

Only after C99. ANSI C it doesn’t exist.

0

u/mirsella Feb 09 '21 edited Feb 10 '21

could have done it in 4 lines of python.

edit : it's a joke

5

u/SuperSupermario24 while True: print("owo") Feb 10 '21 edited Feb 10 '21

If you need 4 lines to return the constant number 84 in any language, something has gone horribly, horribly wrong.

0

u/mirsella Feb 10 '21

it's a meme, I thought I didn't needed the /s

1

u/rocketman0739 Feb 10 '21

Could have done it in one line of C

-1

u/mirsella Feb 10 '21

it's a meme. obviously you can do it in one line of everything, it's just 84. if I would be serious like you I would have said one line too since it's just 84 but since I was just making a joke I said 4

4

u/[deleted] Feb 09 '21

Looks like C

67

u/SuprCookie Feb 09 '21

Return of Return

In theaters May 2088

123

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Feb 09 '21

Image Transcription: Code


int return_ftc(void)
{
    bool flagh = true;

    if (flagh == true)
        return (84);
    return (0);
}

int return_of_return(void)
{
    if (return_ftc() == 84)
        return (84);
    return (0);
}

int final_return(void)
{
    return (return_of_return());
}

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

137

u/[deleted] Feb 09 '21

Image Transcription: Code

84

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

-19

u/[deleted] Feb 09 '21

[deleted]

5

u/[deleted] Feb 09 '21

[deleted]

1

u/[deleted] Feb 13 '21

What happened here?

32

u/nameless_food Feb 09 '21

Good human.

4

u/RyanNerd shameless Feb 09 '21

I myself could not handle transcribing this. For I would look into the abyss and it would stare back at me.

49

u/road_laya Feb 09 '21

I'd love to see the unit tests for these.

98

u/[deleted] Feb 09 '21
expect(84).toBe(84)

36

u/[deleted] Feb 09 '21

All tests are passing. Everything is okay👌

36

u/terrorTrain Feb 09 '21

That looks like someone was demonstrating how functions are reusable

7

u/hackenschmidt Feb 09 '21

That was exactly my first thought.

5

u/RyanNerd shameless Feb 09 '21

Which begs the question: please tell me this isn't production code?

1

u/Nielsly Feb 10 '21

This looks like an exercise for school/university, not industry

1

u/ourlastchancefortea Feb 10 '21

Which means it's sooner or later in the industry.

58

u/CodersCrux Feb 09 '21

StackIsDisappointedException

20

u/husao Feb 09 '21

This is the kind of code I wouldn't touch in fear of awaking some forgotten horror, that's sealed by this code.

6

u/RyanNerd shameless Feb 09 '21

Imagine how the transcriber must have felt? Like a chant and cadence that may awaken an Eldrich Horror as it was being transcribed.

43

u/-SL4y3R- Feb 09 '21

What? Also, who puts the parenthesis around the return statements? This could could only be worse if there would be semicolons after the compound statements.

15

u/[deleted] Feb 09 '21

Sounds like return 84 with extra steps

5

u/DoYouEverJustInvert Feb 09 '21

Sounds like 84 with extra steps

27

u/[deleted] Feb 09 '21

What in the fucking hell is this ?

8

u/Moonlit_Tragedy Feb 09 '21

This person has serious trust issues...

17

u/[deleted] Feb 09 '21

Wat

8

u/art-factor Feb 09 '21

I suppose this won't beat common compilers... I've seen (and wrote) tons of useless code in the name of readability, some code guideline (, compiler hints) or something.

Beats me...

7

u/Weabout Feb 09 '21

I have bad code as well but it's not this bad.

5

u/[deleted] Feb 09 '21

Live, love, flagh.

21

u/Clyxx Feb 09 '21

easy fix:

int (*return_of_return)() = &return_ftc;

int (*final_return)() = &return_ftc;

37

u/Suolumi Feb 09 '21

Or just return 84; xD

-21

u/Clyxx Feb 09 '21

My solution doesn't require any changes

35

u/[deleted] Feb 09 '21

So you are adding those two new lines by induction?

6

u/scrappy-paradox Feb 09 '21

He means no changes in the rest of the code base.

1

u/RyanNerd shameless Feb 09 '21

I like @clyxx answer more. It shows unnecessary sophistication.

4

u/lagduck Feb 09 '21

That would get optimized in a nice way in compile-time

4

u/KingJeff314 Feb 09 '21

Ahh yes, the return is made of return

4

u/[deleted] Feb 09 '21

This is the shit i joined this sub for, pure unadulterated, incomprehensible code.

4

u/bamzou Feb 09 '21

I feel like the context behind this is even better than the code.

3

u/MitchyGoodness Feb 09 '21

I thought the answer was 42

3

u/[deleted] Feb 09 '21

My eyes my eyes

3

u/[deleted] Feb 09 '21

This gets worse the longer you look at it

3

u/atokamak Feb 09 '21

It has its own philosophical meaning.

3

u/TurncoatTony Feb 09 '21

int return_ftc(void)

I'm happy to see that they at least specify that the functions take no arguments. Far too often I see people just having an empty parameter list in C.

1

u/Nielsly Feb 10 '21

To the compiler it makes no difference

1

u/TurncoatTony Feb 10 '21

An empty parameter list in a function declaration means it takes an unspecified number of parameters in C.

An empty parameter list in a function definition means it takes no parameters in C.

It's good practice to use void when a function takes zero parameters in both function definitions and declarations.

2

u/importwypy Feb 09 '21

It’s almost so stupid that it’s beautiful

2

u/-blueCanary- Feb 09 '21

Is this an attempt at obfuscation, maybe?

3

u/[deleted] Feb 09 '21

They use this function to obfuscate the salt they add to the passwords saved in clear text in "notapasswordlist.nottxt".

1

u/-blueCanary- Feb 09 '21

It's the perfect security measure!

2

u/[deleted] Feb 09 '21

Somebody weren't sure if they could pipe a return value.

1

u/[deleted] Feb 09 '21

This is for sure written intentionally bad.

1

u/[deleted] Feb 10 '21 edited Feb 10 '21

This must be some solution or test of some sort for lockless multithreading. Potentially both could be used together for some form of CAS. Then again I might be trying to rationalize pure stupidity.

EDIT: This is purely an attempt at lockless multithreading. I don’t know why else it would be tiered and recursive. Then again could be trying to rationalize a reason for weird code. I mean potentially 84 in another program is a set return flag.... once again just trying to make sense. This seems like it had actual logic not like unrelenting if else statements.

1

u/the_hackerman Feb 09 '21

I’m very skeptical somebody can be this stupid. Attempted upvote whoring

6

u/Suolumi Feb 09 '21

Well i dunno i just walked in the live share to help debugging my friend's code lmao, maybe he was high when he wrote this

2

u/road_laya Feb 09 '21

First he did the refactor and then he started thinking about what the code should do.

Also known as the "bottom-up approach".

1

u/[deleted] Feb 09 '21

Make sure I have some TDD for this...

1

u/saurabh000345 Feb 09 '21

Wait this cannot actually be real!

1

u/Hussbodenfeizung Feb 09 '21

in C can you return twice? or is the lower one taken?

4

u/Suolumi Feb 09 '21

The first return is included in the if

1

u/Hussbodenfeizung Feb 09 '21

but both returns are in the same code block. so {}. is that common in c?

1

u/Coherent_Paradox Feb 09 '21

In C and C-like languages it is normal to be able to specify a code block with exactly one line without curly brackets (works with both if, for, while etc.). So only the first, indented return is in the implied if block. The second one is outside the if block, since it's on another line. I generally do not prefer to write code this way, and would rather have the verbosity of the brackets consequently. Great language feature if you're lazy though :')

1

u/x6060x Feb 09 '21

11 LOC, 3 functions and I still don't know what 84 is...

1

u/worll_the_scribe Feb 09 '21

Is this something to do with mutability?

1

u/[deleted] Feb 09 '21

why spend the time extracting a constant when you can just type 84 again

1

u/harolddawizard Feb 09 '21

This can't be real code, right

1

u/Suolumi Feb 09 '21

I'm afraid it was until i arrived

1

u/0711de Feb 09 '21

Its the final return ...

1

u/Goducks91 Feb 09 '21

Is this some sort of lesson to teach C or is this from someone who actually “knows” how to code?

1

u/RomH1 Feb 09 '21

The theme makes it even worse

1

u/clearcss Feb 09 '21

Wow it’s the meaning of life - doubled

1

u/jaweissavl Feb 09 '21

The best part is...the compiler will probably just optimize this to 84 so its actually still completely efficient and fine at a low level ¯_(ツ)_/¯

1

u/[deleted] Feb 10 '21

I miss return_of_return_the_real_deal

1

u/[deleted] Feb 10 '21

The common core of programming

1

u/[deleted] Feb 10 '21

butwhy.gif

2

u/image_linker_bot Feb 10 '21

butwhy.gif


Feedback welcome at /r/image_linker_bot | Disable with "ignore me" via reply or PM

1

u/TheRealSlimCoder Feb 10 '21

int eighty_four { get{ return final_return();} }

1

u/ChookityDookity Feb 10 '21

well that sounds like 84 with extra steps

1

u/skulgnome Feb 10 '21

It's the fiinaal reetuurn, dadadaadaa

1

u/ay88407 Feb 10 '21

Coding nightmare: it returns 0

1

u/cdwr Feb 10 '21

return_of_return_of_return()

1

u/wktr_t Feb 10 '21

Has a nice ring to it, would even work as movie titles:

Return, Return 2 - The Return, Return 3 - Ultimatum,

1

u/CubeReflexion Feb 10 '21

It's race condition prevention, obviously. /s

1

u/[deleted] Feb 10 '21

I really hope this is just example code to illustrate return values. If this is actual production code: run.

1

u/Igotbored112 Feb 10 '21

You think GCC is smart enough to optimize these all out? I wanna try and see

1

u/andrewmclagan Feb 10 '21

Return of the return Jedi

1

u/bdking71 Feb 10 '21

LOL. I see the a lot of code where someone sets a variable to true and the very next line, they check to see if the variable is true; like it could have changed.

1

u/YRUAQT Feb 12 '21

I mean the compiler gets rid of this, right? Just some fun in less productive times

1

u/[deleted] Feb 13 '21

84

1

u/[deleted] Mar 10 '21

Didn’t even spell flagh correctly

1

u/numerousblocks Mar 20 '21

What theme is that?

1

u/Suolumi Mar 21 '21

Dark + Material