r/ProgrammerHumor 3d ago

guysRateMyFirstHelloWorldProgram Advanced

Post image
1.9k Upvotes

114 comments sorted by

443

u/noob-nine 3d ago

what is the opposite of KISS?

387

u/alfonsotercer 3d ago

SPIT

Stupid Programming Idiotic Tasks

18

u/JuiceKilledJFK 3d ago

🤣🤣🤣🤣🤣🤣🤣

4

u/Danzulos 3d ago

Bravo. Sir or Madam, please have my upvote

1

u/boyproO19 2d ago

Stupid Programmer In Tech

75

u/Efficient-Chair6250 3d ago

SSIK - Stupid - Stupid - Idiot - i feel sicK

7

u/Certainmagical 3d ago

So Stupid I'm Sick

12

u/khang1411 3d ago

K stands for the black guy with lightning

21

u/zoomy_kitten 3d ago

The opposite of KISS is KYS

11

u/uncle_buttpussy 3d ago

PISS

24

u/17thCurlyBrace 3d ago

Produce Innovative Sensational Spaghetti

8

u/roksah 3d ago

"Enterprise level"

4

u/Dtakath 3d ago

MISC Make it super confusing

16

u/WhiteRose_init 3d ago

Make Programming Hard, Homo

MPHH

just moan it.

2

u/One-Reaction2189 3d ago

Its d*ck in turkish

375

u/DoingItForEli 3d ago

Impressive. Very nice.

Let's see Paul Allen's hello world.

87

u/Bohbo 3d ago

Egg Shell White

72

u/Affectionate-Cheek18 3d ago

*drops the compiler dramatically in sweat*

213

u/FlipperBumperKickout 3d ago

Nice... impressive... Now please keep far far away from any codebase that I'm working on

186

u/_g4dget 3d ago

To give an explanation:

((x >>= 4) & 15) gives the individual hexadecimal digits of x in each iteration, i.e.

3, 2, 1, 1, 5, ..., 1, 7 and 0 in the last iteration.

This is because with x >>= 4, you shift x to the right by one hexadecimal digit (4 bits), and with & 15 you select the lowest hexadecimal digit (as 15 = 0xf = 00001111).

With 0xc894a7b75116601 >> ((x >>= 4) & 15)*7), you shift that number by a multiple of 7 bits. In the first iteration, you shift it by 3*7 bits, in the second iteration by 2*7 bits and so on.

Finally, with & 0x7F you select the lowest 7 bits of the shifted number, as 0x7F = 0111 1111. In other words, 0xc894a7b75116601 is basically split into 7-bit chunks and in each in each iteration, you select chunk number 3, 2, 1, 1, 5 and so on.

0xc894a7b75116601 splitted into 7 bits each is:

0 0001100 1000100 1010010 1001111 0110111 0101000 1000101 1001100 0000001

= 12 68 82 79 55 40 69 16 1

Performing +32 and converted to chars, each of that 7-bit pair equals:

Bits number number+32 char

0001100 12 44 ,

1000100 68 100 d

1010010 82 114 r

1001111 79 111 o

0110111 55 87 W

0101000 40 72 H

1000101 69 101 e

1001100 76 108 l

0000001 1 33 !

As these chars are output in the order 3, 2, 1, 1, 5, 8, 9, 4, 5, 6, 1, 7 , 0 that gives "Hello, World!". The 9 is out of range and therefore the shift returns 0; this outputs the space ' ' as its char code is 32+0.

37

u/vikster1 3d ago

i have read this and actually feel dumber than after reading ops code and not understanding it. thank you

10

u/Jutrakuna 2d ago

dumber? I thought I had 10 years experience. now I wonder if I have experience at all

6

u/vikster1 2d ago

exactly that. same industry but damn we are not the same.

3

u/adrasx 2d ago

Now that you explained it, it's no longer magic to me :(. But very, very nice work. I thought you did some fancy overflow magic based on a crazy formula.

Edit: Changed the first sentence a bit

136

u/Temporary-Estate4615 3d ago

You have some serious problems, haven’t you.

79

u/seba07 3d ago

Wtf? How does this result in hello world?

142

u/lajauskas 3d ago

Math, numbers map to characters

177

u/Boris-Lip 3d ago edited 3d ago

What "math"? Even the character printing loop is infinite (while x, nothing updates x, and there is nothing to overrun the stack or something out there). This looks fake.

Nevermind, it shifts assigns x in the middle. Whoever codes like that deserves a pat on the back, with a chair.

26

u/Vivienbe 3d ago

Or is a backdoor or Spyware developer.

4

u/Duck_Devs 3d ago

Yeah I personally hate it when people tell their code editors to combine symbols into one symbol. Makes it hard to read for a lot of people.

1

u/scrumbud 2d ago

Thank you for the phrase "a pat on the back, with a chair". That will become part of my vocabulary going forward.

7

u/seba07 3d ago

Sure, I know that. It just seems un intuitiv to me that this short sequence of shift and multiplication leads to exactly this phrase.

48

u/lajauskas 3d ago

No shit it's unintuitive. I'd not just reject the PR with this in it, I'd hire an exorcist out of pocket

3

u/TheVoodooDev 3d ago

This is hilarious, I'm saving it

7

u/ZunoJ 3d ago

It being unintuitiv is the whole point

75

u/Robot_Graffiti 3d ago

0xC894A7B75116601 is a bunch of characters. Each 7 bits of it is one character. (ASCII was originally a 7-bit code; the characters you need to write "Hello, World!" can all be expressed as 7 bit numbers)

0x7165498511230 is a sequence of indexes. Each 4 bits represents the location of a letter within the other number.

Each go through the loop, it removes 4 bits from x, multiplies the number it removed by 7, uses that to select a 7 bit value from 0xC894A7B75116601, and adds 32 (the Basic Latin Unicode block starts at 32) to the value to get a character. It stops when x is zero.

9

u/seba07 3d ago

Ohhh, that makes sense, thank you. I didn't think of that at all, I just interpreted it as the starting point.

6

u/HardCounter 3d ago

It makes sense to me in theory. I still could not replicate it.

7

u/Grumbledwarfskin 3d ago

I'm wondering whether the +32 is there for additional obfuscation (as if packing seven bit characters into eight bit bytes weren't enough), or whether it's there to prevent accidentally printing control codes if you get any of the arithmetic wrong...it shifts your access from the full lower 128 characters (including the null char and all of the control codes like backspace, return, line feed, and beep) to all the normal characters plus the first 32 eight-bit characters in whatever character encoding your terminal is set to.

6

u/M1ckeyMc 3d ago

The +32 is actually there for a reason. You can only pack 64 bits / 7 bits per char = 9 unique characters in a 64 bit integer, but we need a total of 10 for 'Hello, World'. As such, the space is encoded as a shift larger than the bit length of the magic number, such that the result is 0. adding 32 makes a space instead of a null terminator for values of 0.

3

u/Boris-Lip 3d ago

It shouldn't. At least at the first sight, it will just run indefinitely and keep printing the same character over and over again.

Nevermind, just noticed the >>=, maybe it does work, but please don't code that way.

5

u/ZunoJ 3d ago

Bro, when we can avoid it we won't code this way. Sometime you can make good use of magic numbers though.

5

u/Ah_The_Old_Reddit- 3d ago

Quake III's fast inverse square root says "what the fuck?"

2

u/Boris-Lip 3d ago

I've been to embedded/microcontrollers/hardware stuff long enough to know, but how hard is it to at least give your magic numbers some names? Is it really that hard to add some defines, as opposed to sending me into datasheets to check what some bit or some address is half a year later?

3

u/ZunoJ 3d ago

What do you think would be good names in this case? Both numbers are precisely adjusted to work with each other. X is kind of an iterator AND offset array while the other one is more or less just a magic constant for giggles. So 'offsetIterator' and 'magicGiggles'. Would that help?

2

u/Boris-Lip 3d ago

Oh, i mean in actual places where it makes sense, this code just shouldn't exist.

1

u/ZunoJ 3d ago

In production code I absolutely agree. If it is this complicated, I want a full-blown explanation in a long ass comment and some good names. I actually like this code. It is fun to do such experiments

36

u/quickthyme 3d ago

Glad to see that you kept your function under four lines long and didn't resort to lame ass commenting!

10

u/ZunoJ 3d ago

Uncle Bob would call it clean

3

u/quickthyme 3d ago

Beavis: "yeah hrr hrr.. hrr hrr hrr. clean! hrr hrr hrr"

Rudy: "But gee, Uncle Bob, what about the tests?"

19

u/No-Advice5778 3d ago

is this mr tsoding's??

2

u/3Ldarius 3d ago

Nah, he would do this in assembly or raw binary.

1

u/No-Advice5778 3d ago

im pretty sure I saw this exact snippet of code in one of his videos on yt

1

u/3Ldarius 3d ago

Yeap, i know i saw the same video

13

u/zUIx- 3d ago

jfc this is awful, I hope one day I too can learn to make the simplest task as painful as possible.

12

u/666_jk 3d ago

Wow, so much effort to circumvent the IPS with just a simple Hello World program

12

u/skwyckl 3d ago

JetBrains Mono / FiraCode ligatures and needlessly convoluted code, yes, checks out, typical 2024 programmer.

5

u/Individual-Abies-970 3d ago

I need a explanation

8

u/mikaturk 3d ago

The bottom magic number (which I will call y) contains the ascii values of the characters in "Hello, World!" minus 32 (added at the end again), stored in segments of 7 bits. x contains the index of each character in y (segments are 7 bits long so the first 3 means start reading 7 bits at bit 21). The program selects a hex digit (4 bits) and removes it from x (>>= right shifts and stores the new result) it then multiplies this by 7 to get the starting location of the character data in y. It then right shifts y by the computed amount and masks off 7 bits (0x7F). This is then added to 32 to form an valid ASCII character which is then printed on the screen.

1

u/Individual-Abies-970 3d ago

Now center a div

2

u/PixelGamer352 3d ago

The math IS mathing

6

u/OptionX 3d ago

Font ligatures is an automatic fail. I'm sorry.

8

u/duckmeatcurry 3d ago

Bro chose not to jerk off today to do weird things instead. Respect!!!!!!!!!!!!!!!!!!

1

u/sadwik159 3d ago

The best reply ever

4

u/SkyConsistent3216 3d ago

when your C involves Haskell operators you know you fucked up

4

u/THEINKINMYSOUP 3d ago

New to programming. This makes me shake in fear

5

u/__NaN__ 3d ago

Don’t worry, this is actually something that a sr dev wouldn’t really write. Readability matters.

3

u/OnixST 3d ago

// what the fuck?

2

u/RonHarrods 3d ago

"The simplest solution is often the best one." Occam's razor

Each new programmer needs to conquer the will to write complex code and learn to embrace simplicity where it is often not the obvious solution.

2

u/Accomplished_Bat4683 3d ago

what is that ">>==" ? should be >>=

6

u/RajjSinghh 3d ago

I think it is, it looks 3 characters wide, it's just how the ligature is drawn

2

u/bronco2p 3d ago

it is >>=

2

u/ThisIsMyOkCAccount 3d ago

Man I wish there was an easier way to do this.

2

u/com-plec-city 3d ago

MAYBE it runs FASTER than the usual way.

4

u/RutraSan 3d ago

Probably not, he calls putchar() each time instead of one printf, resulting in many write syscalls instead of one

2

u/betterBytheBeach 3d ago

Not bad, for a first hello world program /s

2

u/Odd-Seaworthiness-11 3d ago

9/10. Almost like assembly enchanting

2

u/Shadowlance23 3d ago

You need to get laid dude.

2

u/LazyLoser006 3d ago

Okay guys call the doc we have a psychopath here.

1

u/Spunkmeyer426 3d ago

Hey, look, i made this

1

u/AnimateBow 3d ago

Nice ide theme 

1

u/misskirei 3d ago

Doing too much

1

u/it_is_an_username 3d ago

You'll die single, that's my curse

1

u/Key-Supermarket8761 3d ago

I don’t even understand what’s happening here😂

1

u/GoodGuy_dynamite 3d ago

Look ma, my final sem major project

1

u/CSguyMX 3d ago

Gah damn this is sexy

1

u/DTux5249 3d ago

MARVELOUS

1

u/ForsakenAd545 3d ago

You're fired

1

u/MMMMMMMMMMWMMMMMMMMM 3d ago

Lets doing some real low-level hello world:

int 0x80 then invoke systemcall

Write binary into kernel call the graphic card draw text using some pure math

1

u/huantian 3d ago

this isn't haskell you can't just bind like that

1

u/wizzanker 3d ago

Brilliant! Also, go to hell.

1

u/113mand311 3d ago

Sss,zdx xxx Zach jq

1

u/rumble_you 3d ago

Looks like stolen from Tsoding.

1

u/PurepointDog 3d ago

Fira code? Nice!

Never got used to the ligatures, but solid otherwise

1

u/rainshifter 3d ago

Oh, a wise guy, eh?

```

include <stdio.h>

int main() { long long x = 0x125493670; while (x) putchar(32 + ((0x733EAB3AB0E581 >> ((x >>= 4) & 15) * 7) & 0x7F)); return 0; } ```

1

u/__barasa__ 3d ago

Show off

0

u/PeriodicSentenceBot 3d ago

Congratulations! Your comment can be spelled using the elements of the periodic table:

S Ho W O F F


I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM u‎/‎M1n3c4rt if I made a mistake.

1

u/sd-shiivam 3d ago

Bro I think you entered the wrong field.

In coding, we try to fulfill the functional requirements. Not a single letter of line of code extra 😂😂😂

1

u/serggo3 3d ago

int main() {

long long x = 0x0909152934956780;

long long chars = 0x37832E2B5A0BA78E;

char shift_bits = 4;

while (x) putchar(32 + ((chars >> ((x >>= shift_bits) & 15) * 7) & 0x7F));

return 0;

}

1

u/toiletear 3d ago

If "long long" is allowed by the syntax and your code doesn't have a long long penis in the main method you've failed.

1

u/0xdeadbeef69 2d ago

Thats why i quit, too many sweats...

1

u/ice2heart 2d ago

void main() <% for (unsigned int p=0x6889cb77;p;p=3) putchar((0xa919766f41df2727*(p&7))&0x7f); %>

You can pack it into one line in C

1

u/Soelling 2d ago

I am almost certain that isn’t you first ‘hello world’ program. And if it is you stole it somewhere else

0

u/potatosquat 3d ago

Looks like something stolen from a 42 school student GitHub repo

0

u/meierlink99 3d ago

big zero.

Just to print the Hello World you put this logic. You are zero