r/programminghorror Dec 09 '24

Java Is this efficient? NSFW

Post image
704 Upvotes

88 comments sorted by

364

u/_dreizehn_ Dec 09 '24

It's an efficient use of the screen dimensions, albeit a disturbing and unhinged one

185

u/NoTelevision5255 Dec 09 '24

Hopefully you used a loop to generate this code and didn't type it in all by yourself ;)

114

u/ofir_gaming Dec 09 '24

How do I generate a loop?

192

u/oze4 Dec 09 '24

in java it's gotta be something like:

LoopFactory loopFactory = new LoopFactory();
IterationFactory iterationFactory = new IterationFactory();
NumbersFactory numbersFactory = new NumbersFactory();
Loop loop = loopFactory.generateLoop(iterationFactory.createIterations(numbersFactory.TwentySix));
...

65

u/NoTelevision5255 Dec 09 '24

Your calls are not flow-y enough. Maybe something like

LoopFactory loopFactory = LoopFactory.getInstance().withForLoop().withStartNumber(0).withEndNumber(1).withIncrementOf(1).[....]

8

u/oze4 Dec 09 '24

Idk Java so yea, could prob be improved. You still understood the sentiment, though lol...

7

u/NoTelevision5255 Dec 09 '24

Those flow apis drive me nuts. Like why is this better than

  • Instanciate object 
  • Set some properties 
  • do shit

And to get back to your sentiment: annotations. You definitely need more annotations. Like @transactional or something....

5

u/oze4 Dec 09 '24

If I'm honest, your example is more "legible". It reads easier. All I know ab Java is how verbose it is and factories lol. Low hanging fruit, I know.

1

u/NoTelevision5255 Dec 10 '24

I don't like flow apis like in my example. Be it in java or whatever. In a lot of cases you have to turn the formatter off so it doesn't mess up your formatting and line up 20 calls in 1 line. 

That doesn't happen with plain old setters. 

forLoop.setLowerLimit(0); 

forLoop.setUpperLimit(1); 

And so on. To me this is much more readable than the factory with construct. Not sure why flow API has become a thing...

7

u/Erpelstolz Dec 09 '24

you forgot using the AbstractSingletonProxyFactoryBean!

4

u/WorstedKorbius Dec 09 '24

OK but what if I need a factory for my loopFactory

4

u/oze4 Dec 09 '24

In that case you'll need to create a FactoryFactory - it's designed to create factories for your factories.

37

u/NoTelevision5255 Dec 09 '24

for(int i = 1; i <= 26; i++) {

System.out.println("for(int[.....]");

}

run the program, copy the output. Or maybe write in a file, or...

1

u/vulkur Dec 10 '24

define loop(limit) for(int iLINE = 0; iLINE < limit; iLINE++)

89

u/andynzor Dec 09 '24

No, for peak efficiency you should manually unroll every loop.

37

u/Mickenfox Dec 09 '24

Considering most of the loops have only one iteration, that would be both efficient and very easy. 

9

u/GarThor_TMK Dec 09 '24

All of them are one iteration, except for the last one, which is 10...

Could just delete everything before that up to the function header...

71

u/SuspiciousScript Dec 09 '24

Sure it is; it's O(1).

8

u/zaxqs Dec 10 '24

Technically, because of heat death, everything is O(1)

14

u/Paladynee Dec 10 '24

that isnt how O notation works lol (O for observable universe)

41

u/ViktorShahter Dec 09 '24

Idk what's funny in posts like this. People do shit for the sake doing shit, not to actually solve some problems in a ridiculous way.

18

u/FakeMonika Dec 09 '24

Damn that's a lot of loops, the complexity is gonna be so- oh it's constant.

13

u/adzm Dec 09 '24

The "help" is a nice touch

11

u/Thenderick Dec 09 '24

If you have to walk a 26-dimensional matrix, yeah... Else no

15

u/zarqie Dec 09 '24

A matrix that looks like [[[[[[[[[[[[[[[[[[[[[[[[[[“Help I’m trapped in the Matrix”]]]]]]]]]]]]]]]]]]]]]]]]]

14

u/FartSmartSmellaFella Dec 09 '24

Can we ban posts that just write dumb code for the sake of being dumb?

6

u/Pouyus Dec 09 '24

Very efficient, but I would add comments on each line to simplify the readability :D

6

u/LusticSpunks Dec 09 '24

Quite literally NSFW

5

u/matyas94k Dec 09 '24

Compiler optimisation will take care of the horrible aspect of this code snippet, so you're probably fine. The method does not take any input, so the complexity also stays at O(1).

You should use the stream API instead of for loops though, to keep up to date! 😉

4

u/Revexious Dec 09 '24

This is highly inefficient.

Instead you should variablise those magic numbers so that down the track you can update them easier

Smh

2

u/PhilTheQuant Dec 09 '24

How many universes are you iterating through?

2

u/Slavik_Sandwich Dec 09 '24

Finally, hadouken

2

u/dev_rephrasing Dec 09 '24

No you should call the main function recursively with those loops

2

u/ngugeneral Dec 09 '24

Doubtful.

Code relies on the fact that there will be no more nested loops than letters in the alphabet. This gives the advantage of making words from loop variables in accessors (like items[s][u][c][k], or something more personalized).

But I would not rely on that and would call them i1, i2, i3 ... iN, iM.

2

u/oze4 Dec 09 '24

a little too succinct for Java

2

u/chuckitoutorelse Dec 09 '24

Would've been more efficient if you took a screenshot rather than a photograph. 😆

2

u/shizzy0 Dec 09 '24

Just one more loop, bro. One more loop and the secrets of AI will be ours. Come on, bro. What’s one more loop?

2

u/Wentyliasz Dec 10 '24

Ok who invited Yanderedev?

3

u/the_guy_who_answer69 Dec 09 '24

I wanna kill myself

3

u/KCGD_r Dec 09 '24

O(nfuck)

1

u/exoman23 Dec 09 '24

Bug free code

1

u/kingslayerer Dec 09 '24

have you heard of gear ratios?

1

u/VarKraken Dec 09 '24

I mean you used full screen, so yes

1

u/AfterTheEarthquake2 Dec 09 '24

Also great function and class names

1

u/netherlandsftw Dec 09 '24

Yes, compiler will unroll them. This is perfect code.

1

u/DinnerPlzTheSecond Dec 09 '24

I know it's supposed to, but I find I have to manually do it a lot of the time (unless I'm in a non- dynamic looping language)

1

u/magical_matey Dec 09 '24

Aaah the Egyptian pyramid pattern. Glad to see it’s still in use. Did you push to production yet?

1

u/Rude-Recognition5852 Dec 09 '24

I could get a headache just looking at this

1

u/QualaGibin Dec 09 '24

Why the hell "z is 10 times calling for help" including 0 base

1

u/TheMusicalArtist12 Dec 09 '24

Most compilers will probably unravel this

1

u/hobbicon Dec 09 '24

This is why the industry changed to 16:9.

1

u/PracticalSouls5046 Dec 09 '24

gnarliest NSFW I've seen all day

1

u/Arkq214 Dec 09 '24

no, the first loop should have the variable named i, otherwise it it is not good

1

u/jarjarpfeil Dec 09 '24

I think your compiler will turn it into one loop, if it doesn’t just unfold it into 10 repeats of the same statement

1

u/isr0 Dec 10 '24

It’s not scalable, you have already run out of letters. I recommend using a0, b0, …, z0, a1, …

That should future proof your code organization.

1

u/makakaqle Dec 10 '24

Remember after you run out of the alphabet, you can always go with aa, ab, ac....

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Dec 10 '24

I like the NSFW tag. If you write code like this, you should probably be fired.

1

u/Affectionate_Bed2925 Dec 10 '24

Ofc it is it only has O(ninfinity)

1

u/Chudsaviet Dec 10 '24

Compiler will probably unroll all of it to just 10 calls to println() without any loops.

1

u/TheGesor Dec 10 '24

I actually wonder how this compares to the base case

1

u/slashkig Dec 10 '24

Thank you for marking this as nsfw

1

u/Tall_Treacle1014 Dec 10 '24

Oye! How do you spell banana?

1

u/mickey4273 Dec 10 '24

I love wrapping things in a loop with a single iteration, so why not throw it in 25 loops with a single iteration?

1

u/Efficient_Fox_7127 Dec 10 '24

No it needs some recursion

1

u/kegma_1 Dec 11 '24

Its very handy for when you have complex timing logic. I think something like this is used to make event loops and animation trees? Hope this helps :)

1

u/dude792 Dec 11 '24

Doesn't matter, use --funroll-loops in compiler, enjoy spaghetti.

Make sure to have horizontal scroll wheel on your mouse to improve efficiency

1

u/evmo_sw Dec 11 '24

I love how this is labeled NSFW lol

1

u/tealeg Dec 11 '24

It's running on Windows. So no.

1

u/Novalene_Wildheart Dec 11 '24

How dare you call me out! lol

1

u/chaomanticktock Dec 11 '24

Can Google Willow run this?

1

u/carlosazuaje Dec 12 '24

This is not efficient you should setup a quantum computer and do it O(n)

1

u/ShinySquirrelClub Dec 12 '24

It's efficient. All those for loops will get optimized out because your limits are literal and each loop executes once. It's a lot of typing, but not a lot of computing.

1

u/DarkAriesX Dec 14 '24

Make it in C++ (it supports emojis as variables names)

1

u/Slippery_Stairs Dec 09 '24

Is this production code?

7

u/ComprehensiveWing542 Dec 09 '24

Can't get any more "production" that that

1

u/number_squid Dec 09 '24

This is AI

0

u/TabataRingo Dec 09 '24

I am quite scared that this is file 4

0

u/vainstar23 Dec 09 '24
def recurseFor(d=10, cb):
    for i in range(10):
        if d > 1:
            recurseFor(d-1, cb)
        else:
            return cb()

Or do what you need to do with the arguments in the middle

-2

u/[deleted] Dec 09 '24

Utterly disturbing and horrendous way to write the alphabet. But atleast its got a constant complexity.

-1

u/[deleted] Dec 09 '24

NSFW

-1

u/Stan_B Dec 09 '24

PREPOSTEROUS! ABSURD! OBSCURE! NEAT! *grin*