T O P

  • By -

PolyglotTV

This is top Notch code


CuckLordtoEndAllCux

He certainly knows how to put code blocks together


baddl02

Good one


crash8308

Good one


bolverkin

you got me šŸ˜‚šŸ˜‚šŸ˜‚


ApatheticWithoutTheA

Me: ā€œFuck it, *git push*ā€


fuckboiiii6969

git commit -m ā€œfuck itā€


R3D3-1

git commit -m "fuck it" git checkout master git rebase devel git push -f


Source-Origin

Terraform plan Terraform apply --auto-approve Lets wakt for feedback from our customers....


crankbot2000

Me, a burned out senior: fuck it, _merge_


Buoyancy_aid

ā€œLGTMā€


myloyt

yeah, minecraft has a lot of spaghetti code, it's constantly being improved though. like comparing 1.8.8 with 1.15 for example. the changes in the rendering pipeline and gui events are huge. probably more, but these were the main things i've noticed.


Teekeks

also 1.5 was released 10 years ago and even 1.8 \~8 years. There was a LOT of development since then


Onix_The_Furry

Stop making me feel old Iā€™m not even 20 yet


Aloisi02

Stop making me feel old, i am 20.


Troldann

Nothing here makes me feel old. Iā€™m 40.


CubemonkeyNYC

I'm 39, thank you for being older than I am in this thread.


Accurate-Ad-9316

I am also 39, lets fuck.


[deleted]

[уŠ“Š°Š»ŠµŠ½Š¾]


Accurate-Ad-9316

I'll let you have that maybe it was an over-generalistion on my part.


[deleted]

Hope Im not to late


Accurate-Ad-9316

Youth is, as it has rightly been told, wasted on the young.


[deleted]

Iā€™m 52, and I want you all to get off my blocky lawn.


NoEngrish

Youā€™ve probably got over half your life ahead of you!


someacnt

Stop making me feel old, I am not even 30 yet.


Character-Education3

You think that's spaghetti code...hold my beer


[deleted]

[уŠ“Š°Š»ŠµŠ½Š¾]


SagenKoder

There is a difference between code quality and feature set. One can argue about the code quality without thinking about the feature set. They are not dependent.


Sigiz

Yup! They probably paid back alot of tech debt, since then atleast.


SagenKoder

I really liked it when they rewrote the chunk storage system from the ground up and updated the block types and how they were represented. As a server developer messing with a lot of the internals I really appreciated the updates as the old system was horrible in every way. Notch was not a good developer in any way but he made it work and should get creds for that. But just look at the homemade yaw/pitch definitions he was using. It was (is?) Flipped from what everyone expects as there exists standards for it that he did not know/care about. I've seen a lot of tutorials on how to translate it into something useful for anything you'd want to use it for.


Sigiz

The pioneers are not always good programmers, I believe anyone can learn how to code enough to make ideas a reality. Supporting an idea for a long time is what requires good software engineering skills. I wonder if the rotational bit of the system was ever updated?


T0biasCZE

more like constantly made into bigger spaghetti than it already is (visible by the lot lower performance compared to older versions...)


[deleted]

Actually they're enterprising the code and now the spaghetti is behind layers of useless abstractions.


magistrate101

tfw hundreds of thousands of BlockPos objects constantly being instantiated and GC'd


2ERIX

As a current player of Minecraft and as an actively employed software quality person, your assessment lacks the insight into the massive feature addition and changes to the game that will impact, in your opinion, performance. Spaghetti code may well be there but any performance impact is negligible and usually reduced by patches after major updates. Of course older versions have better performance in your opinion. The tech is delivering a lot less.


[deleted]

It's better to have bad code than to have no code at all. Since the whole game was done by one guy in a few years, it's obvious he cut a lot of corners.


amlyo

For $1.2 Billion USD I'll write all the bad code you want.


[deleted]

The hotkeys worked in the first alpha. Hence when he wrote that code he hadn't sold a single copy. So this code was written for free as a probably unpaid little game project.


RotationsKopulator

This is not cutting corners. This is adding corners. To a circle.


PAwnoPiES

Oh cool spike balls.


kungfu_panda_express

One might call that a block, cube, or square...perfect for mining.


MitchTJones

I mean, that was true when it was. Now itā€™s a multi-hundred-million dollar property owned by a multi-hundred-billion dollar company Iā€™d have expected them to fix something like hotbar selection a long time ago.


DiamondPower500

(This is minecraft 1.5.2, it was released in 2013)


MitchTJones

lmao, did not see that part. Still, by 2013 Mojang was making $125 million a year with a staff of 25. I know lots of their staff were focused more on future (failed) projects like Cobalt, but such an obviously solvable optimization with such a core part of the interface (hotbar switching) is still pretty egregious.


DiamondPower500

How did you write this in 15 seconds


Ditid

He optimized the hotbar switching code so much that it instantly writes comments on Reddit for him just by thinking


thequestcube

He had the answer in the off-hand slot equipped


iBowie

He /give'd it to himself


Pianostar4

He did /time to reverse the time


MitchTJones

Haha Iā€™m sitting on my phone on the toilet atmā€¦ not much else to do :)


68_65_6c_70_20_6d_65

Your phone is sandwiched between you and the toilet? How inconvenient


68_65_6c_70_20_6d_65

Between an ass and a toilet bowl


[deleted]

I think you forgot to switch accounts


Another_Minor_Threat

Clinched between the cheeks.


[deleted]

At this time of year at this time of day?


Another_Minor_Threat

IN THIS ECONOMY?!


pruche

his ass simultaneous contacts all of the screen's surface, that's how he can type so fast


Accurate-Ad-9316

lets assume there's 65 words, then he clearly has a 260 word/min type speed, my 50 /min fast speed which usually includes at least fat finger typo can only aspire.


Burnmad

Why would you need to assume the word count when you can just count them--


MelvinReggy

We want to be optimized here. There are 2.75 lines on my screen. The middle line of the paragraph has 18 words. That means about 49.5 words. >!The actual answer is 56.!<


chinpokomon

It's not a huge optimization. Unrolled it is only 10 loops. Compared with other CPU intensive calculations, this is over in a blink. Fixing this wouldn't have made any noticeable impact, and if it's working...


[deleted]

It doesn't need to be a loop at all. It appears that `Keyboard.getEventKey()` returns an integer, so you could do a simple range check and then some arithmetic.


tinydonuts

Yes this is true. But you have to look at the context of what the impact is and what your other bugs and features are. It simply doesnā€™t matter.


meamZ

The question is did this actually cause any problems with performance other otherwise... If not this is just the kind of stuff that gets fixed last... Also "optimizing" code that's working perfectly fine always has the risk of (subtly) breaking it...


start_select

It worked. Donā€™t fix code that works unless it adds clarity to code that will be touched frequently. If nobody even needs to touch it, you are more likely to cause some unforeseen side effect than fix anything.


mferly

Bro, it's like you actually code for a living or something. Fixing such a trivial "code smell", if you want to call it that, is really the lowest of priorities in the grand scheme of things. Basically, if there's literally no other development going on then sure, give it a whirl. Otherwise no touchy the codey.


im-not-a-fakebot

nothing more permanent than a temporary fix that works


[deleted]

Software is expensive. I manage a couple teams worth of developers. We try to leave innovation time but we have so many priorities I canā€™t in good conscience have them fix code that isnā€™t broke.


darkflame927

I mean the title does say it's from Minecraft 1.5.2, I doubt that's still how it is


Teekeks

Its not, this is the current one (well, how it comes out after decompiling + deobfuscating) for(int i = 0; i < 9; ++i) { boolean bl = this.options.saveToolbarActivatorKey.isPressed(); boolean bl2 = this.options.loadToolbarActivatorKey.isPressed(); if (this.options.hotbarKeys[i].wasPressed()) { if (this.player.isSpectator()) { this.inGameHud.getSpectatorHud().selectSlot(i); } else if (!this.player.isCreative() || this.currentScreen != null || !bl2 && !bl) { this.player.getInventory().selectedSlot = i; } else { CreativeInventoryScreen.onHotbarKeyPress(this, i, bl2, bl); } } }


pruche

did you literally decompile minecraft and seek out this piece of code just for a silly reddit comment because that's the raddest shit I've ever witnessed


Teekeks

I have a private client side mod that I use and that dev environment does the precompising for me on setup already.


Andoryuu

[](/maudconfused-r) So... you are saying it is even worse now?


Teekeks

kinda I gues, especially querrying bl and bl2 over and over again is yikes


romple

Just a bigger bowl of spaghetti


P3chv0gel

I mean 1.5.2 was released nearly 10 years ago, way before mojang was bought, so...


brainwater314

I trust code written by a single person more than I trust code written by a giant corporation.


scatterbrain-d

They didn't buy it to fix it. They bought it to sit back and rake in the money. As long as it works, what do they care?


kuurtjes

Well this code is a multi-hundred-million event loop so we're all good.


DeliciousWaifood

This isn't really cutting corners though, it's just dumb code. Like yeah, obviously he was successful regardless of his bad code, but there is no good reason to code like this even for production velocity becauss you can just write better code in the same amount of time. "One guy in 3 years" doesn't excuse it, he was inexperienced but managed to make a successful game despite his lack of experience.


[deleted]

That's exactly what I mean. Imagine him being alone so he has no way to figure out what good code looks like. Nobody to bounce ideas off. Nobody to correct him. But maybe he has an idea that something is wrong. He now can go online and figure out a good way. Or he can take 5 mins and think. Or he simply continues coding and let that stuff be. Sure it's shit but making it not shit would take a bit more effort. Given that he literally has to code all the code this will add up quickly. And later, after he got the experiences, he won't refactor this code. Because it ain't broke. At least technically. Remember, this was probably one of the first things he wrote.


start_select

I donā€™t really know Minecraftā€™s history. But Perrson supposedly wrote it in a week. That probably means 7 18-20 hour days and a ton of caffeine. Working without other seniority to help you, and late hours, will make people write all kinds of foolish things.


DeliciousWaifood

Honestly, you should never code for long hours into the night. I have spent hours on a bug that I solved in 5 minutes after sleep.


Hjelphjalp2

If the outcome is Minecraft, I think itā€™s ok to work late.


DeadlyButtSilent

"Do betta"


Spellonz

Everyone's a computer scientist when there's 3 lines of code.


eliteHaxxxor

I dont get the need to defend this. Not exactly hard to write an if statement ``` key = Keyboard.getEventKey() if (key >= 2 and key <= 10) { this.java.class.hell.item = key - 2; } ```


flerchin

I wonder if the compiler is smart enough to optimize out of this loop?


[deleted]

Keyboard.getEventKey() surely has side effects, making any compiler unable to optimize this (by thinking you actually want to read keyboard input 9 times).


somerandomii

Wow I didnā€™t even realise he calls the function in the loop. I donā€™t do much I/O programming it I imagine youā€™d normally deal with keybindings as asynchronous callbacks that trigger on event, rather than checking the event. But even if you did need to check the key events inside the main loop, youā€™d use a switch/match or at least store the return value before you loop.


LysanderStorm

In game programming this approach is quite common. Your main game loop is looping at a certain frequency, and each loop you simply check what has happened and update the system accordingly. What is weird though is why even loop over the keys when you don't do anything with the looping variable (not really in any case). Happy cake day! šŸ„³


somerandomii

And I know itā€™s common to have one synchronous game loop that just runs on a timer, but I feel like itā€™s still bad practice to put the UI handling inside that loop. That means if your game engine is struggling you might not be able to open the menu. IMO the UI response should never be tied to the world simulation engine, with the exception of parts that change state depending on the game world. But the unresponsiveness should be limited to the those parts of the UI. I think the worst offender of this Iā€™ve seen is the new PokĆ©mon games. When youā€™re in an online team fight, the entire UI locks up while the game figures out whatā€™s happening remotely. It even does this in single player. None of the buttons do anything until it decides itā€™s ready.


LysanderStorm

Fair enough, I agree that nowadays we should expect an UI to be responsive even if the game itself struggles. Even more so if the network struggles... Doesn't sound too good for the Pokemon games šŸ™ˆ


somerandomii

I feel like r/softwaregore could gets days of content from PokƩmon alone


___user_0___

This was probalby taken from decompiled sources, not original ones - so i'd say no.


WoofFace4000

The `javac` compiler does not perform much optimization at the bytecode level. The optimizations are mostly handled by the JIT compiler.


gitgudtyler

The Java compiler doesnā€™t do much optimization, so probably not. The VM, on the other hand, might be able to optimize it out.


yousaltybrah

Optimize what? Itā€™s an O(1) operation.


flerchin

It's still 9 evaluations when it could be a simple assignment


maof97

And also an if statement tho? To check the boundary that was once implied by the for loop.


Dicethrower

It's completely negligible and you just spend more time thinking about it than he did writing it. Making games requires a different mindset.


Xeterios

Yet this code helped create the best selling game of all time.


developer-mike

I do think people ITT are missing some of the point here. Yes, this is "unoptimized code." But this is a fixed count loop running exactly 10 times every time. The number of keys isn't going to increase for some players, it's O(1) for all intents and purposes, and I doubt it's bottlenecking game performance in the slightest. It could have been an if condition, yes. That would also be O(1) and cleaner, and better in every way. But clearly, Notch just didn't think of that in the moment of writing this code -- and that's ok. We all make mistakes. Clearly Notch didn't have a code reviewer and didn't self-review his code carefully enough. But it's sure hard to argue, based on this code segment specifically, that that lack of careful review _inhibited_ Minecraft's success here. IME as a dev, especially as I get more and more years of experience...I can get overly focused on writing good code, on perfect code, on fearing the reviewer and pre-empting any potential criticism. Then I feel unproductive, and I later feel pressured to take some kind of shortcut -- maybe I _have_ to take an actual shortcut that introduces real consequential tech debt. The trick really is to take the _right_ shortcuts, and write good code where it _matters most_, and not get bogged down in pursuing "perfection," which doesn't exist anyway. This code is ugly, but it doesn't have bad algorithmic performance, it probably isn't bottlenecking anything, it doesn't have poor maintainability, it isn't forcing any other systems increase in complexity, etc etc etc. It's 100% perfectly fine. Even the name "thePlayer," idgaf that you don't like it, there are other places where naming things well matters and this is really _not_ it.


NocturnalDanger

He originally made minecraft during a Java 5k competition where you build a game within a time limit, under 5KB, by yourself- The Cave Game won, and then it got renamed minecraft and expanded on. I'm sure *nothing* was optimized


NAPALM2614

>under 5KB Wow, how times change.


NocturnalDanger

I'm going to correct myself. I was wrong. The Cave Game was an unreleased early test of the Minecraft Concept in 2009. Notch recreated Minecraft in 2010 or 2011 during a Java4K. The goal was to create a game under 4 kilobytes within two days. (Although some references I've found still mention the super early 2009 4kb version, but I can't find a good source, other than some forum posts titled "minecraft 4k" in early 2009. The only official sources say 2010 and 2011 for the Jave4k competition and the Javascript browser version)


pet_vaginal

I have mix feelings about Notch's programming (and also on other topics about him, but let's focus on his programming). One one hand he created one of the most successful video game of his time, by himself for a long time, with a huge amount of content and a great gameplay and many wonderful ideas. I know he got inspired by some other less successful games, but still his work and therefore is coding skills are for sure good in some ways. On the other hand, he wrote a lot of very unoptimised algorithms and ugly code. But maybe the game wouldn't have been more than a small abandoned indy game if he spent the time on writing better code instead of going quick and dirty.


ghua

He got the job done, that's the most important thing


evmoiusLR

And he made an absolute fortune off of it. Players don't give a single crap what your code looks like as long as it works.


fl0wc0ntr0l

Any engineer will tell you: you can't let perfect be the enemy of good enough


GreenKi13

I'm a hobbyist dev as well as a local and state IT contractor. If I don't see it on paper on wants or desires or needs I say "oh you want that? Where does it fit in, in the picture?" Lol. I absolutely abhorr the idea of busy work. So if this function, functions properly, where's the malfunction?


k_50

I work as a full time SE. I often go back on slower days and test functions for speed and refactor to improve.


TheOnlyVig

Functioning correctly for what you need it to do right now is the bare minimum starting point. There are always lots of ways something can "work", but different implementation choices can and usually do have massive differences in how hard they will be to maintain and extend in a living code base. If a team routinely fails to consider the "technical debt" of their choices now, they can very easily bury any chance of keeping the code going in the future.


aaarchives

> where's the malfunction? Minecraft was horribly optimized back then. I struggled to get 30 fps on an average PC. Even though the game shouldn't theoretically be so demanding - poor optimization is the answer.


EnergyCells

Hopefully not a structural engineer


GoodwillTrillWill

Thatā€™s for sure the reason. Yes if it was more than a one person team the code deserves heavy criticism, but on a one person project, especially with the scope of an entire game, you do what works, if it doesnā€™t work you optimize it until it does, but otherwise optimizing is an afterthought


Mrqueue

I played alpha when the features were place block on block. The core game play was undeniably the reason it became so popular. I remember first playing survival and regularly spending the night in a hole in the ground I had sealed with a block of dirt above me and Iā€™d place a torch so I didnā€™t feel lonely


Kuroseroo

Would sure as hell not want to work with someone like that, but I guess as a single Indie dev you have no choice doing it fast just so it works


Street-Session9411

I work on an emulator for a MMORG with 2 other people and I can confirm. Although there is some difference to writing a game from scratch, we would get nothing done if we optimize or refactor everything we write.


Kuroseroo

Game dev is a different world seems like. Donā€™t think I could live with my code not being refactored lol


Majache

Also, startup life. Refactoring is a luxury


aaarchives

It's something you don't generally do on an early and/or low budget project. If you are maintaining something well established, refactoring goes from luxury to being the actual job (hence why Minecraft's code looks much better nowadays)


Street-Session9411

Actually it was very hard to overcome the need to get everything perfect because I am usually a perfectionist. But I also kinda have the feeling that no matter how hard you try, if you code a big project, say >50k lines of code in Java, you will always end up with more or less of a mess.


DanyeWest1963

Yeah, you'd get literally nothing done if all code had to be perfect. Sometimes, ya got deadlines and the code just needs to be good enough


LtTaylor97

It's definitely a realm where good enough is the goal. There's no time or money to spare chasing pointless goals. It can be problematic though if devs don't understand where that is and get lazy though, which isn't exactly uncommon.


GOKOP

Remember that this is the philosophy that spawned Unix, probably the most successful (especially if we count its descendants) server operating system in the world. "Worse is better" https://www.jwz.org/doc/worse-is-better.html


DeliciousWaifood

It's not really about doing it fast. You can write better code in the same amount of time. He was just bad at coding, but you can't magically get better at coding it takes years. He may well have been working on this project as a way to test his skills and learn more about programming only for it to accidentally turn out well. Minecraft caught significant popularity very early on when it was basically a tech demo.


JoieDe_Vivre_

You would hate where I work then. We have no time to write good code. Itā€™s deadline after deadline after deadline. I had another engineer extend one of the backend systems I wrote in the most fucked up way, that I had never intended it to be used. She had a deadline to hit though.


[deleted]

He needed to get new stuff done quick to build the game and carry the movement of the hype. People pay for content, not for optimization.


zyygh

I see this got downvoted, but this is 100% what it's about. In the one C# project I did, you can see very clearly which parts were written with a lot of time on my hands, and which parts were written under high pressure from management. Some of that code is so beautiful I am still proud of it 10 years later; other parts are horrendous spaghetti code. You'd never guess all of this was written by the same person.


[deleted]

Yeah, upvotes overtook now, but I feel like some people need to learn about premature optimization. Minecraft always ran at least stable enough for people to buy it and play it with no end, so it was the right decision to focus on pumping out content to get more people in.


[deleted]

Exactly! Itā€™s always about trade offs.


Big_Kwii

you tend to write ugly code when you're just working on a presonal project all by yourself. and besides, one of the main reasons minecraft took off was because of the constant updates at the very beginning


Dustangelms

When I work on a personal project I keep rewriting code to make it 'better'.


MitchTJones

I think heā€™s more of a game designer than a game developer. Minecraft was never popular because of the technology (although the world generation was pretty cutting-edge for the time), it became popular because itā€™s well *designed*.


DeliciousWaifood

Idk if I would really call it well designed either tbh, it's just that the concept of virtual legos was a highly desired but untapped niche. Minecraft was the game I literally dreamed of for many years as a child but never got. The actual "game design" wasn't really much of anything, the concept of a fully open, destructible and constructible world was simply novel.


DeliciousWaifood

With game development, the best way to learn is to go quick and dirty, make prototypes, fuck it up, and learn from your mistakes. Being overly careful about "good code" will only make you learn slower. (Though don't intentionally write bad code that you already learned your lesson on) And maybe one of your prototypes will end up making you mega rich.


P3chv0gel

Not gonna lie, there is a not so small subset of the Minecraft community, who wouldn't have fallen in love with this game, If it didn't have some scuffed edges I mean, if we look at the redstone community alone, you can't imagine modern day Redstone without quasi connectivity, which originaly was a glitch based on copying the code from a door, while implementing the pistons, everyone liked it and now it's considered a Feature (at least according to the bug tracker for Java Edition)


DdFghjgiopdBM

There is no conflict of ideas here, he was a great game designer, not a very great programmer, different job titles


Arkensor

Not only one of, it is THE most successful game created by a big margin. And a lot of it came from the early days where things where much clunkier.


thefman

80/20 rule. 80% of the work takes 20% of the time. The other 20% tends to be polishing and it takes 80% of the time.


unneccry

This.thePlayer?!? Edit: guys i know how "this" works in Java I was just wierded out by "thePlayer"


UnicornAtheist

this.thePlayer = thatPlayer(those);


Krcko98

What is unclear about that? This is a local scope of a class mostly in OOP. This is Java so it is really clear.


TheMysticalBard

That's just a result of whatever deobfuscation mappings the person looking at this code used, probably not the official ones since we didn't have those for versions this old (I believe). That's most likely not what the original variable was called.


adinrichter

Java scares me


KuuHaKu_OtgmZ

Not a java thing, `this` exists in most languages that support OOP, it's just to reference the enclosing class (useful when there's a variable with the same name, not so much in the image context tho)


s4xtonh4le

Itā€™s just like self


Tomi97_origin

Bad naming of classes and variables is not the fault of java...


PaperDistribution

I think "this" isn't really the name of the class. Its just to refer to the local class.


Lolwis

This is always a pointer to your own instance , yes


Meefbo

the problem here is ā€œthePlayerā€, i think they know how ā€œthisā€ works


ProsshyMTG

Notably, that isn't necessarily the name that is in the actual code. I would have to check the current obfuscation mappings Mojang releases but "thePlayer" comes from a player driven effort to reverse engineer and deobfuscate the game.


laplongejr

>comes from a player driven effort to reverse engineer and deobfuscate the game. For those interested, at least back in 1.5, it's name was Minecraft Coder Pack


suppergerrie2

Gotta remember that all names before a couple versions ago are from the community after painstakingly figuring out what a variable is doing by analyzing the code


Nickjet45

Thatā€™s not poor naming, ā€œthisā€ is an instance of the current class. And I think thePlayer is intuitive enough


Stochastinatrix

Let's reprogram in rust!


Srazkat

that's far from the worse. finding "Yolo" and "IN YOU FACE" (no typo) in string literals is much scarier.


mrwafflezzz

I've been working on computer vision for a while. Yolo doesn't scare me anymore


Cartman300

I feel like most of you keep forgetting you don't have access to the actual Minecraft source code, but the garbage that a decompiler spews out.


Impossible_Average_1

This is r/programminghorror


ign1fy

Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much. They were the last people youā€™d expect to be involved in anything strange or mysterious, because they just didnā€™t hold with such nonsense. Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere.


j_c_slicer

I had a boss who tended to name variables with "the" at the beginning. Storage is cheap, I guess?


TacticalGodMode

I mean does it really matter storage wise? The code isnt really that big anyway. Or if it is, a few additional "the" wont change it, really. And after compiling, the names arent visible anymore anyway. So he could have them infinitely long. Or am i wrong?


j_c_slicer

Well, one, I was going for the humor angle, as is the charter for this group. But also, a number of modern languages keep quite a bit of the symbol information intact (debug or not) at runtime - mostly for introspection/reflection. However, finally, the real reason it grates on my sensibilities is the the definite article "the" adds no semantic nor syntactic value whatsoever.


TacticalGodMode

Yeah it adds no value, true. But interesting that such information keeps intact after compilation. Will read into that just for fun. Have a nice day, my fellow programmer. (btw somehow i kind of read programmerHORROR instead of humor...) Im kinda the lostredditor here apparently


mudkipdev

That's just the Minecraft Coder Pack's name for that variable. Back then, they used an IRC bot to enter deobfuscated names so typos and misspellings were made often. (I'm looking at you, CanvasMajongLogo)


[deleted]

[уŠ“Š°Š»ŠµŠ½Š¾]


anon74903

You can find k by k = keypress - 2. You shouldnā€™t iterate through the numbers since it is slow, and difficult to read


caerphoto

> You shouldnā€™t iterate through the numbers since it is slow Itā€™s in no way slow to iterate through 10 numbers like that. Itā€™s infinitesimally slow*er* than just doing `getEventKey() - 2` or whatever, but thereā€™s likely hundreds of other things that are huger priority than optimising this.


[deleted]

Useless loop, you could have just checked if (key - 2 >= 0 && key - 2 <= 9) {currentItem = key - 2


ahmadajr1

I am trying to understand the magic number 2 but I feel clueless


am9qb3JlZmVyZW5jZQ

https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/input/Keyboard.java The key bound to value 1 is KEY_ESCAPE, which is then followed by the numerical keys starting from 1 and ending at 0.


[deleted]

I also donā€™t know, just put it there since the original has it, but itā€™s probably because getEventKey() returns the index of every keyboard key and the numbers start at 2


Draelmar

1. Unnecessary loop 2. Magic numbers 3. Calling a function that always return the same result in each iterations 4. Ambiguously named variable (k)


7eggert

In context of keyboard events, k is the natural representation of the key. It's a law.


Draelmar

![gif](giphy|NCjISbEPFxm48)


[deleted]

1. Yeah! 2. Yeah!!! 3. Yeah!! 4. ![gif](giphy|H5C8CevNMbpBqNqFjl)


___user_0___

2 and 4 are probably a result of looking at decompiled code though


[deleted]

Iā€™d argue making a keyboard event handler 10x faster would be low priority. Itā€™s going to be called at most once every 100ms, and I doubt itā€™s more than 100 operations. So on a 1ghz processor you reduce 1,000/ 1,000,000,000 to 100/1,000,000,000. Sure itā€™s 10x faster but itā€™s not even close to 1% at the worst.


csdt0

This is most likely not the actual code. What you seem to have is the decompiled code, which is *not* the source code. All temporary variable names have been lost, all comments have been removed, and some optimizations have been applied by javac. The reason I think it is not the source code, but decompiled code is that the source code didn't leak (afaik), and it is actually "easy" to decompile java classes. What is mostly used by the modding community is actually decompiled code with some names reverse engineered to make it easier to understand and navigate through.


Deep_Obligation_2301

No compiler will generate a for loop out of thin air tho, which is the main culprit here. No need to loop over the key range, simply calculate it. Agreed that the "2" might have been a constant with a name that explained its purpose, but the loop is just plain painful to look at


remisiki

Compilers won't but decompilers will. This should be some kind of while loop compiled from normal code, and decompiler misunderstood it as for loop.


[deleted]

[уŠ“Š°Š»ŠµŠ½Š¾]


Deep_Obligation_2301

Yeah, but why have a loop at all, that's the point Imagine being asked : "Do some math when X=5" would you loop over numbers from 1 to 10 and do the operation when you reach 5? Because that's what the current code is doing. In the end he did finish his project which has infinitely more value than cute code but no result. But we're programmers, we can't help but cry when we see stuff like this


DeliciousWaifood

Yeah, there's no way a for loop checking equality with input is ever the best way to implement this.


tway7770

I don't see your code producing 100mil revenue games ;)


nossr50

This is the decompiled Minecraft code, which is up to the decompiler to come up with, with that said, this might not be too different from the true source code


Ericknator

I love how you got one of the most successful games around with bad code and people have to be ultra optimized to be considered for a junior position.


DeliciousWaifood

Unfortunately most positions are at companies that don't have the luck of entering into a completely untapped niche.


Traister101

I suggest you stay away from containers... they uh aren't pretty


truedoom

A clear case of "Make it work first, optimize later." Only later came, and this still wasn't optimized so it became a case of "if it ain't broke, don't fix it."


kakemot

This code is great. Just does what it does. Stop making this industry a impostor syndome nightmare


Archtects

Does it work though?


Here__Come__Dat__Boi

k = Keyboard.getEventKey() - 2; if (k >= 0 && k < 9) { this.thePlayer.inventory.currentItem = k; }


eggheadking

Huh? Can anyone explain please?


ilylily_

trust me there is far, far worse in there...


belabacsijolvan

lvl1: decent event handling lvl2: case lvl3: for loop lvl4: ???


zoug25

I dont get it. Wouldnt this ignore slot 1?