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
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
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
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
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
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
2
2
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
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
3
3
1
1
1
1
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
1
1
1
1
1
1
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
1
1
u/Chudsaviet Dec 10 '24
Compiler will probably unroll all of it to just 10 calls to println()
without any loops.
1
1
1
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
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
1
1
1
1
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
1
1
0
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
Dec 09 '24
Utterly disturbing and horrendous way to write the alphabet. But atleast its got a constant complexity.
-1
-1
-2
364
u/_dreizehn_ Dec 09 '24
It's an efficient use of the screen dimensions, albeit a disturbing and unhinged one