156
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 09 '21
Image Transcription: Code
if (this.ParseDataDontCutLastChar("JAN", j))
{
copyProtectScript.date_month = 1;
}
if (this.ParseDataDontCutLastChar("FEB", j))
{
copyProtectScript.date_month = 2;
}
if (this.ParseDataDontCutLastChar("MAR", j))
{
copyProtectScript.date_month = 3;
}
if (this.ParseDataDontCutLastChar("APR", j))
{
copyProtectScript.date_month = 4;
}
if (this.ParseDataDontCutLastChar("MAY", j))
{
copyProtectScript.date_month = 5;
}
if (this.ParseDataDontCutLastChar("JUN", j))
{
copyProtectScript.date_month = 6;
}
if (this.ParseDataDontCutLastChar("JUL", j))
{
copyProtectScript.date_month = 7;
}
if (this.ParseDataDontCutLastChar("AUG", j))
{
copyProtectScript.date_month = 8;
}
if (this.ParseDataDontCutLastChar("SEP", j))
{
copyProtectScript.date_month = 9;
}
if (this.ParseDataDontCutLastChar("OCT", j))
{
copyProtectScript.date_month = 10;
}
if (this.ParseDataDontCutLastChar("NOV", j))
{
copyProtectScript.date_month = 11;
}
if (this.ParseDataDontCutLastChar("DEC", j))
{
copyProtectScript.date_month = 12;
}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!
86
27
5
144
u/Lost4468 Apr 09 '21 edited Apr 10 '21
How do we know this isn't compiler optimisation? Or does this come from actual source code?
Also Yanderedev's problem isn't really the bad code. It's his attitude. Dude refuses/refused to take any criticism and admit he didn't know what he was doing. Had he just admitted he was out of his depth he could have easily fixed it before going too far with the crappy code base. Not to mention he seemingly has done nothing for multiple years.
Terraria was programmed terribly as well. In fact I would say it was significantly worse than Yanderedev's code. Thankfully the dev was never hit too hard by performance issues due to it being in 2D (and also spaghetti code can be fast sometimes) and not requiring a ton of computing power. That dev admitted the fault though and went back and fixed it I believe, not to mention all the other things he added. He didn't just sit there saying what an amazing dev he was.
I have interviewed people like that. I give them a problem and they're obviously stuck, but they would rather sit there for 20 minutes. And then when I finally interrupt them they always blame it on anything but themselves. If you seriously don't get it and know you've gone way past the allotted time, ask for help, of course employers would rather employ the person who can solve it, but they certainly wouldn't hire the person who just sat there refusing help, over someone who got stuck and asked.
Edit: I think OP is right actually, I think the way Yanderedev wrote it prevented it being optimised out into anything else.
If we look it still checks every single month even after it finds a month... There's no else if branching, there's no break/continue/etc, there's no return. What I'm saying is I don't think it could have reasonably came from a switch statement, or an array or anything else.
Essentially by not returning or using else etc, the compiler is stuck, it thinks it has to do each one anyway, so I think this must be almost exactly how it was originally written?
This doesn't mean the method is justified though, C# decompilation is still flawed for actual method bodies. But above the method body it actually should be very accurate, because the compiler has to preserve all of that. I believe it has to even preserve all private method/field/property names as well for reflection and similar purposes?
94
u/Shadow_Being Apr 09 '21
gonna give you a secret. all code is bad code. it's all shitpiles on top of shitpiles taped together with duct tape.
It's not a matter of if your code is bad. it's a matter of how bad is your code.
26
u/Lost4468 Apr 09 '21
Well I would say that means we still have good and bad code, it's just there's a lot of room to improve. Or maybe there isn't, maybe this is it, we've already reached peak code quality. But I would say that good code is 99% art and 1% engineering.
It's one of the criticisms I've seen of software engineering in general, and why some people argue it's not engineering. I don't agree with them at all on it not being engineering, but I can certainly see why they say parts are a mess.
Civil engineering has figured out objective ways to measure things, and has developed methods and stuck with them for a long time. We know a bridge won't (shouldn't) fall down because we know enough about the physics, we have objective ways to design it and test it and make sure it will not fall down, before we build it. These are generally all agreed upon and rarely change. And the best methods work amazingly well and have so few issues.
But in software engineering there's really nothing like that. There's very few objective measures of code, it's nearly all subjective. And there's very little widespread agreement, and the trends seem to change every few years. And there's really no method that works well outside of both very specific circumstances and in a vacuum. We have no methods which can guarantee anything will work and act like we want it to, it always inevitably ends up interacting in some really complex way we couldn't predict beforehand.
There are some obvious exceptions, like validate your fucking input so we don't have another Therac-25. But as far as the large scale design and behaviour of code, it's much more of an art than engineering. And it will be for the foreseeable future, because there are just way too many degrees of freedom. When engineering a bridge you're designing it to withstand forces which always behave in the same way, materials which always behave and interact in similar ways, etc. Whereas when developing software you literally create all of those rules yourself, and you can't even properly sort it out for your own code, nevermind when you start interacting with other peoples code.
6
u/TigreDeLosLlanos Apr 10 '21
It even runs in a much deeper level. When you want to use some system call or even a wrapper you are found with the "the standard doesn't specify what this thing should return or how it should do it" so you are left with non portable and potentially unpredictable code. The cause is often that the code came before than the standarization so they don't want to crap on some edge cases and forcing some people to redo their code because they used some things in a non-common sense way to save 0.1 ms execution time and 14kB of memory.
0
u/MrHelloBye Apr 10 '21
Therac-25?
4
u/Lost4468 Apr 10 '21
The Therac-25 was a medical machine used for X-ray based radiation therapy.
Looks like I have had it mixed up in my mind for a while though. The issue I was thinking of was a similar machine, and there were machines in both the France and the UK. France uses a , in the place of a . and a . in the place of a , e.g. so 1,000,000.5005 in the UK but 1.000.000,5005 in France. Some patients were moving back and forth between France and the UK, so this would cause them to frequently have doctors from both countries communicate in what doses etc they have given the patient.
So the problem was the doctors were sending each other numbers with , and . in them back and forth, e.g. a UK doctor might prescribe a dose of 1.115, but then in France this would look like 1,115 to someone there. These doses were obviously lethal/very dangerous, but the machine did no input validation at all. So someone in France would get the number, just quickly type in the number without thinking and deliver a dose 1,000 times as large to the patient.
Now it looks like the Therac-25 issue was different though, and more complicated. It essentially boiled down to a ton of mistakes, there's a good video here. It's rather complicated, but it essentially boiled down to hardware cut offs replaced with software cut offs which would sometimes not work, and even when they did could be easily overridden by the user with no explanation.
I can't find anything on the one I heard about. It was introduced to me in my software engineering class, and I'm beginning to wonder if it was one of those stories that had been passed around that mutated from the original, and this was actually the Therac-25 story, just incorrect?
2
Apr 10 '21
there was a picture of yandere's code quite like this. It had "this." at the start of stuff
it wasn't decompiled, there was a comment in there
6
u/SandeonMNG Apr 09 '21
Has yanderedev never heard of a switch
3
u/Nilstrieb Apr 10 '21
this can actually not be a switch like this.
also in C# string switches don't exist behind the scenes, so it gets converted to else if chains.
also a switch would only make this code slightly less terrible1
u/Antihihi Apr 10 '21
Actually it's kinda my fault for this but this is not Yandere Simulator, this is a different game made in Unity, I don't want to tell the games name as i actually enjoy it.
1
u/digitbh Apr 24 '21
I love how every reply to yanderedev is "hurr durr, try switch!!" As if that's gonna solve any of the gaping problems
0
23
u/NetherFX Apr 09 '21
I'm curious, let's say there's no way to use Date, what'd be a better way than using a Dictionary, or HashMap?
38
u/PolishedCheese Apr 09 '21
Definitely dictionary or hashmap comprehension. Return mapDict[a]
5
-3
u/Shadow_Being Apr 09 '21
based on this code alone. that is literally no different in approach.
Somewhere you have to type out the month string and the numbers in a long list of code.
24
u/dpelego Apr 09 '21
Big difference in readability between 12 if statements and initializing a hashmap with 12 values.
If you really want, you could have an array with all of the values and then a for loop to populate the hashmap where each key is the array element and the value is the array index + 1.
Still 3 lines, better than the code in the image.
-10
u/Shadow_Being Apr 09 '21
yeah sure i mean i guess so you are right.
If I was to give the original code a readability score I'd say it's a 6/10
If I was to give your code a readability score I'd say its a 6.5/10
not exactly worth even spending the time to do it just for that.
6
u/dpelego Apr 10 '21
How would you do it then?
-2
u/Shadow_Being Apr 10 '21
i would leave it as is because its not worth spending time on it.
Ideally woudn't have architected it such that manually searching a string for certain substrings and converting it to integers by doing all these checks.
E.g. saving data in a json format would probably have been way smarter.
copyProtectScript = JsonSerializer.Deserialize(j);
4
u/TinyBreadBigMouth Apr 10 '21
Dictionary is shorter.
Dictionary is easier to read and check for typos.
Doing a single dictionary lookup is more efficient than doing 12 string comparisons, without even using
elseto stop comparing when you find a match.-1
u/Shadow_Being Apr 10 '21
It would definitely also not be shorter. likely the same length
Being easier to read, it is possible that is would be very slightly easier to read which i coverered in another response.
no its not, you still have to do 12 string comparisons because you would have to loop over the dictionary and run ParseDataDontCutLastChar on each item in the dictionary. The performance would actually be very slightly worse because you have the overhead of setting up the dictionary.
2
u/TinyBreadBigMouth Apr 10 '21
Presumably, whatever is in
ParseDataDontCutLastCharcould be reworked to return the parsed value instead of doing the comparison internally.Dictionary<string, int> dateNameTable = new Dictionary<string, int>() { { "JAN", 1 }, { "FEB", 2 }, { "MAR", 3 }, { "APR", 4 }, { "MAY", 5 }, { "JUN", 6 }, { "JUL", 7 }, { "AUG", 8 }, { "SEP", 9 }, { "OCT", 10 }, { "NOV", 11 }, { "DEC", 12 }, }; ... string monthName = this.ParseDataDontCutLastChar(j); if (this.dateNameTable.TryGetValue(monthName, out int monthIndex)) { copyProtectScript.date_month = monthIndex; }1
u/Shadow_Being Apr 10 '21
> Presumably, whatever is in ParseDataDontCutLastChar could be reworked to return the parsed value instead of doing the comparison internally.
Yes that is precisely what the code in OP is doing....
the only correct thing to do here is to ditch trying to create your own serialization system and just use a well established one like JSON.
2
u/TinyBreadBigMouth Apr 10 '21
Yes that is precisely what the code in OP is doing
...How do you figure? It doesn't returns a parsed value, it takes a string and returns the result of comparing that string with the parsed value.
6
u/mplaczek99 Apr 10 '21
Always remember folks, you want to keep your code efficient and tidy. You don't want to be another Yanderedev.
4
3
2
1
u/c3534l Apr 09 '21
I'm not sure what it says about me that I used to defend Yandere Simulator despite it not being my bag up until I started to see the kind of code the dev was writing.
1
1
1
u/Spynder shameless stealing content to r/YandereTechnique Apr 10 '21
r/YandereTechnique in its glory
1
1
1
1
1
1
1
1
0
u/ResTamReditDeDeus Apr 09 '21
An enum could work here too. Also, why do you call him/her Yanderedev?
5
Apr 10 '21
This is code from the game Yandere simulator. A game about a girl who kills other girls who are dating her senpai or whatever. Games pretty pervy and the dev used patreon funds for a couple grand sex doll.
1
u/Antihihi Apr 10 '21
Actually it's kinda my fault for this but this is not Yandere Simulator, this is a different game made in Unity, I don't want to tell the games name as i actually enjoy it.
-3
u/_-Phage-_ Apr 09 '21
I mean It's better if you use switch in terms of readibility.
If It's performance though It depends on how many time this is called, switch Isn't incredibly faster than if-else(except sometimes.)
29
Apr 09 '21
um how about an array
7
u/_-Phage-_ Apr 09 '21
yeah
I'm still learning, I'm more familiar with unity so I'd thought it could be something similar.
6
14
Apr 09 '21
The Switch statement is always faster than if-else, except in most cases, the performance gain is insignificant.
3
Apr 09 '21
Is it on strings though? I don't know if strings are hashed for the switch (so a hash + go-to) or if it's just a chain of strcmp.
4
Apr 09 '21
As far as I know, C# strings are checked with hashes in the switch statement. I might be wrong, I should check the documentation.
0
u/_-Phage-_ Apr 10 '21
That's what i said..
2
Apr 10 '21
You said " except sometimes ". There's always a performance gain, but it won't matter unless you write performance-critical code probably.
-1
u/BananyaDev Apr 10 '21
It's depressing how many programmers who probably don't have the slightest idea about or have ever worked on performance critical code decide to make a meme out of the decompiled gameplay code of a random indie dev.
0
0
Apr 09 '21
[deleted]
2
u/Antihihi Apr 09 '21
No, this is ugly takes up a lot of lines and could easily be done through an array for example
150
u/[deleted] Apr 09 '21
We found it boys and girls and non binary pals. Yandare Devs' brain