[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Code

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 108
Thread images: 16

File: 1496386386725.png (212KB, 680x658px) Image search: [Google]
1496386386725.png
212KB, 680x658px
What is wrong with this code, besides the excessive use of if else statements?

Nothing.
>>
>>60849151
The fact that it's in a Flash game for weebs.

Senseless waste of code.
>>
>>60849151
The repetitive if statements increases the runtime complexity of the program and goes against the very principle of even having data structures and algorithms. But yes, it does output the right result, which is all that matters, right?
>>
should have more polymorphism and generality instead of seemingly trying to have an independent if statement for each possible case
>>
Simple explanation: this code could use a dictionary of similar objects instead.
>>
>GameOver(string cause)
>
>>
Need to rewrite in a functional language so you can do all the if statements in parallel.
>>
>>60849151
Brainlets don't understand that it's the most powerful code in the world.
>>
>>60849151
Should be:

if(condition A && condition B && condition C)
Switch(Bunch of shit)
>>
>>60849151 (OP)
you can apply the strategy pattern to avoid ifs
>>
>>60849151
His method of accounting for multiple thing being witness is to join strings together with " and "? That is very bug-prone. What if he joins them in the wrong order? Why doesn't he just use bitflags? It would also reduce the number of cases he has to check for.
>>
>>60849151
>excessive if/else leads = performance hit
>non-externalized strings
>not wrapping common functionality in its own method
>not using a HashMap or the like to store key/value sets, which is basically all this code does - sets values for a given key
There's a few, for starters.
>>
>>60849151
>massive if statement
>reliance on string constants for identifiers and logic switching
>fragile
>completely unmanageable
>a complete bitch to extend or change
I might murder someone who came to me with this shit code.
>>
>>60849151
Instead of keeping every possible Teacher NPC status as an array of bit flags, he's opted to concatenate them into a string, and instead of parsing this string normally, he's literally checking every possible permutation of options.
The order of the options should NOT matter.
"Insanity and Blood" should not require a separate case from "Blood and Insanity".
>>
>>60849151
Another one I forgot to mention:
> == for strings instead of .equals(...)
>>
>testing booleans against strings
>not using enums
>casting to float
its GAARBAGE
>>
There's nothing wrong with many if statements, but here are my problems with this code:

1) Separation of concerns, why are we checking for "Teacher" and "WitnessedCorpse"?

It's better to create a single function that accepts "Witnessed" as a parameter, and returns the result or updates the state.

2) Magic strings

Use enums!

3) Why not use a Switch statement?

Looks better and serves exactly the purpose of this code
>>
>>60850202
That's fine though.
>>
>>60849151
my class based approach isn't really shorter desu

witnessed = [ 'weapon', 'blood', 'insanity' ]

for thingWitnessed in witnessed {
subtitle.update(thingWitnessed)
}

subtitle.commit()
____________
class Subtitle:
init() {
weapon = blood = insanity = ... = 0
}

function update(thing) {
thing++
}

function commit() {
Gameover.cause(weapon, blood, insanity) # static class that assigns game over causes
}
>>
File: yandere simulator1.png (285KB, 1366x768px) Image search: [Google]
yandere simulator1.png
285KB, 1366x768px
I got a whole bunch of yanderedev code, let me start dumping.

1/?
>>
>>60850243
is this actual code or decompiled?
>>
>>60850226
Sometimes it is, though .equals is generally considered to be safer, especially since strings aren't a primitive type.
>>
File: yandere simulator2.png (528KB, 1294x642px) Image search: [Google]
yandere simulator2.png
528KB, 1294x642px
>>60850243
2/?
>>
File: yandere simulator3.png (265KB, 1366x768px) Image search: [Google]
yandere simulator3.png
265KB, 1366x768px
>>60850253
3/?
>>
File: 1493452802877.jpg (333KB, 720x720px) Image search: [Google]
1493452802877.jpg
333KB, 720x720px
>>60850202
Javascript doesn't use .equals faggot
>>
>>60849151
Daily reminder that this shit compares a shit ton of strings, does not have a single fuck for optimizations, have 2000+ lines of unorganized code and runs 60 times per second.

Good try YandereDev, your code sucks.
>>
File: yandere simulator4.png (402KB, 1366x768px) Image search: [Google]
yandere simulator4.png
402KB, 1366x768px
>>60850265
>>
File: yandere simulator5.png (434KB, 1366x768px) Image search: [Google]
yandere simulator5.png
434KB, 1366x768px
>>60850272
>>
>>60850266
My bad, I thought OP was using a proper language there for a sec.
>>
I saw the code for some dragon VN on steam that was way worse than this
>>
File: yandere simulator6.png (337KB, 1366x768px) Image search: [Google]
yandere simulator6.png
337KB, 1366x768px
>>60850276
>>
>>60849151
this thing could easily be written in 6 lines tops.
>>
File: yandere simulator7.png (347KB, 1366x768px) Image search: [Google]
yandere simulator7.png
347KB, 1366x768px
>>60850289
>>
>>60849151
For God's Sake if you're going to ifs anyway, why the FUCK aren't you at least prioritizing singular events? if(this.Witnessed == "Insanity"){insanity stuff} as the first check covers FOUR of his lists because they're all exactly the same.
>>
File: yandere simulator8.png (298KB, 1366x768px) Image search: [Google]
yandere simulator8.png
298KB, 1366x768px
>>60850302
>>
File: yandere simulator9.png (400KB, 1366x768px) Image search: [Google]
yandere simulator9.png
400KB, 1366x768px
>>60850308
last one i think
>>
Luckily he's just the game director now and not the (read: only) lead programmer.
>>
>>60850339
Didn't he make an entire video whining about why he didn't want to hire anyone ever?
>>
File: 1489216121243.jpg (37KB, 419x424px) Image search: [Google]
1489216121243.jpg
37KB, 419x424px
>>60850281
He literally doesn't know how to code, so he just did whatever werks. That's why his code is shit. He kind of wants to hire a dev to redo it all in C# with unity 5 but I think he doesn't want to because it would take too long or something.
You can view (an old version of) the game's update event here: https://pastebin.com/cu9gDj5Z in all of it's 2.6k line clusterfuck of a mess.
>>
>>60849151
Let's see here.

String constants. Absolutely awful and painfully slow.

String constants to represent different combinations of separate concerns, instead of using a series of booleans or bitflags.

Generally the whole Witnessed system here is unmaintainable shit. Why is witnessing a corpse a whole separate thing while everything else is mashed together into that one shitty this.Witnessed value? It would be better implemented with an array of booleans, a bitflags configuration or perhaps even an event queue? An event queue seems the most flexible.

It appears everything is the same class and checks every loop whether or not it's a Teacher (or presumably various other things)

Why is he interacting with the subtitle system directly? I don't know enough about the game really but that seems like it should be abstracted away, what if there's already a subtitle on screen and you want to wait for to end?

Why is GameOverCause local to the object? That seems really odd, that should be global, what happens if two different teachers come with different values for it? You could probably make an argument that it should be a function call too.

Why has he needlessly duplicated the handling code and why isn't it in a method somewhere? If he wants to add more complex behavior he's going to have to change it in like ten different places for no good reason.
>>
>>60849836
Is there a functional different between switches if else chains?
>>
>>60850349
>this.audio.volume = this.audio.volume - 0.333333343f;
nice
>>
File: 1474653031540.jpg (34KB, 400x340px) Image search: [Google]
1474653031540.jpg
34KB, 400x340px
>>60850369
An if else chain has to evaluate every if statement until it reaches one that succeeds. With a switch it is usually possible to calculate the address that you need to jump to from what you pass into the switch statement.
>>
>>60850369
In theory, the if/else will be compiled into a series of comparisons and jumps (check if it's zero... No? check if it's one... No? etc.) and the switch case statement will be compiled into a jump table where the number fed in is just used as an index to get an address from the table, instead of doing one comparison for each possible value, you load a single memory address and do a single jump to it. (More or less, there's another couple commands necessary to handle out of range values but you get the idea).

In practice the compiler may detect your if/else statement can be converted to a jump table and do it for you. That's not going to happen if you use string constants though as it has to handle any argument of any length (I suspect a very clever compiler might be able to manage it, but I would be surprised if any actually do).
>>
>>60849151
Generally, you shouldn't use strings and numbers in your code like that.
If the text is stored in an array somewhere, you could easily translate the text, edit spelling errors etc without breaking the game.
Another benefit is you can store the index and use simple comparisons to check for multiple cases at once.
>>
>>60849151
I remember writing code like that.

When I was 10.
>>
>>60850414
>(I suspect a very clever compiler might be able to manage it, but I would be surprised if any actually do).
FYI I know at least in Java's implementation of switch on strings it actually uses the strings hashcode (unique hash of the string as an integer)
I tested out a quick example in C (with gcc -O3) and it didn't do anything fancy.
>>
At around 3 levels of if statements things start getting trickier to read. It's usually a good idea to refactor some of those blocks into functions.
>>
It's very flaky. Why is a string of English representing a set of conditions?

>>60850243
That's fine.

>>60850289
This is all fine, what are you trying to ridicule?
>>
>>60850272
>>60850276
>>60850289
>>60850302
umm is this all javascript?
And this is all running on every frame draw?
>>
>>60850348
it was directed to youtube subscribers who were spamming him with "suggestions" that weren't useful or needed.
>>
>>60850727
Yes, https://pastebin.com/cu9gDj5Z is running every frame.
>>
>>60850771
And you are surprised? Ever read Quake 3?
>>
From this small section of code. Witnessed could be a bitmap and remove all of the if statements.
In C++

std::string *possibleWitnessed = {"Insanity", "Weapon", "Blood"};
unsigned int x=0;
while( Witnessed>>x )
{
if(Witnessed & (1 << x))
return possibleWitnessed [x];
}

And just adding it to the string is EZ
>>
So this is why he had trouble developing because he has fuckton of bugprone shit and recompiles long time between every change.

No sympathy for his spagetti desu.
>>
Complain about his code all you want his game strangely runs better and is somehow less buggy than 95% of Kickstarter/Early Access/Patreon games anyhow
>>
>>60851106

Yeah but it doesn't really do much. He's got the start of a lot of ideas but nothing that's at all complicated.

Not only that, but he jumped to a large scale without finishing any of the core features. He'll take forever to do any updating when he wants to finish a feature and he may have to rewrite nearly everything in the end.
>>
>>60851106
>Complain about his code all you want his game strangely runs better and is somehow less buggy than 95% of Kickstarter/Early Access/Patreon games anyhow
Comparing one pile of shit to another pile of shit?
>>
Holy shit that's some pretty shit code. "weapon and blood and insanity", he couldn't have thought of a better way to do this other than a string separated by ands?
>>
>>60849151
it's redundant and shitty to maintain. this is why arrays exist.
>>
>>60850403
>>60850369
That's only true depending on optimization levels and complexity of the switch statement, and at higher optimization it'll be pretty much the same.

The if/else chain is hard to understand and redundant, while a switch statement would be more appropriate.
>>
>>60849151
yansim went opensource?
it honestly should, one man is not enough to complete this project
>>
>>60850771
Does the dev not know what a helper function is? This looks like an absolute mess to maintain
>>
>>60851693
his a prototype dev that tries to ship a finished producy all by himself, what do you think his code would look like?
>>
>>60851715
>dude I'm doing it by myself that's why I shouldn't use any functions and just throw every single fucking thing in one update method.

No, that's not how it works you literal fucking pajeet.
>>
>>60851729
>implying
i don't say he should, i say he literally doesn't posess the skills to do it the right way, he's a prototype dev end, suprise, his code looks like a bunch of prototypes shoestringed together
>>
>>60850359
>String constants. Absolutely awful and painfully slow.

I mean it's terrible, but why would you just go and fucking lie about something you're clueless about? C# automatically interns magic strings.
>>
>>60849151
>I'm YandereDev! I worked at a video game company for 3 years, then left to become a freelance programmer and pursue my dream of becoming an independent game developer. In the past, I've worked on 5 console games (for Wii, 360, and PS3) and 5 mobile games (for Vita and iPhone).
>can't program shit
Jesus just look at the FAQ and the way this idiot is full of himself. Also the way he tiptoes around all the questions writing whole paragraphs only to say that he doesn't know the answer yet. This piece of shit is gonna be the next Numale Sky isn't it?
>>
Should probably be a separate function to be fair.
if (this.Teacher && this.WitnessedCorpse )
{
this.Subtitle.UpdateLabel(this.Witnessed.Subtitle, 1, (float) 6)
this.GameOverCause = this.Witnessed.Cause;
}


mmmuh object orients poogramming
>>
>>60851838
wait, is he flat out lying now?
i remember when he first started yandere dev on /v/ he said he had like 0 programming experience
>>
>>60849151
Using excessive string manipulation instead of just using boolean variables.
>>
>>60851890

He probably worked at a game company but as a programmer.
>>
makes no use of conditional operator/&&
>>
>>60849151
>add one more witnessed status
>have to add 12 more else if statements
>>
>>60850011
>hey look here's some fundamentally flawed code, let's fix it by transmuting it into a design pattern instead of fixing it
t. pudoo padeep
>>
>>60849151
>shitty variable name: "this"
>using strings to list conditions
>using "and" as if you were talking to a person
>not using nested if statements to eliminate a shit ton of checks
if ( weapon){
if (weapon + blood + insanity);
if (weapon + blood);
if ( weapon + insanity);
}
if (blood){
if (blood + insanity);
...
}
>>
>>60850910
Can you give the simplest explanation of the >> and << operator?
>>
File: 1493044522494.jpg (82KB, 960x720px) Image search: [Google]
1493044522494.jpg
82KB, 960x720px
>>60849151
If statements and switches compile down to the same assembly so it's just as fast.

It's up to you whether this is bait or not.
>>
>>60854190
The voices of the 2d girls you obsess over are all 3d women
>>
>>60850369
No. They compile to the same thing.

It is literally meme tier live in basement install gentoo faggots that argue about this shit.

Code in OP is fine. Could potentially be better but there is nothing strictly wrong with it. Anyone who has difficulty following that logic shouldn't be working with software.
>>
>>60854223
>t. pajeet or numale that somehow got a job he didn't deserve
>>
>>60854095

You need to read up on bitmaps in general. That's a basic operator for bitmaps, and you really shouldn't jump into them without understanding what you're doing.
>>
>>60854190

This goes beyond the fact that he used if statements.
>>
File: 1494911274745.jpg (506KB, 1428x781px) Image search: [Google]
1494911274745.jpg
506KB, 1428x781px
>>60854216
>The voices of the 2d girls you obsess over are all 3d women
Once we have compelling software voice generation we will truly leave the 3D world forever.
>>
>>60854475
yea I know, thats why I dont konw it yet.
I stick to C, but some of the stuff Im working with is C++ and it uses this magic.

The shit Ive read is talking about shifting bits, but I dont see how this has anything to do with functions.

Honestly dude, Ive got too much going on in life to spend any more time on hobbies and I really just need a tldr on this
>>
>>60854544

Then don't worry about bitmask operators at all. Avoid bitmasks. You'd be working with binary and if you're not ready for that then you shouldn't do it.
>>
>>60854095
It's a bitwise operation. Think of witnessed in it's bit representation. >> and << shift the bits left and right. Read up on bitwise operations and try to dissect this simple example. Also, note the use of a single & as oppose to &&. Don't forget to read up on & and | as well.
>>
>>60854609
I agree.
But this doesnt help me get my nigger rigged laptop lojack up and running any faster.
>>
>>60854643
Will do.
>>
its writen in jewnity and its written by a autistic niglet
>>
>>60854068
>shitty variable name: this
>I have never heard of object-oriented programming before
>>
>>60855311
shitty object name, you feel better snowflake?
>>
>>60855467
you still don't get it do you
>>
>>60855467
You can't be serious
>>
>string comparisons in the main game loop
>redundant statements

No wonder his "game" runs like shit.

Yeah, it's not even a game, it's just a vaporware that will never ever be released because the guy can't make games. He spent most of his time implementing shitty easter eggs to cater to his autistic millenial weeaboos fanbase so that they would give him patreon money and making videos to try to stay relevant. Why would he ever make a fully functional game when he made more money during development than he could ever dream of post-release?
His thing is full of technical issues, it's been three years and despite using easy-mode-generic-games-factory Unity, he still uses generic assets (the whole game depends on them), bland backgrounds, bad writing and shallow characters, shitty voice actors and art direction and awkward animations. He's been struggling for half a year to implement a damn "major" character, and looking at the flowchart even my 12 years old cousin could have drawn that he puts in each of his video, it's hardly even a week worth of work.

But no, he needs to constantly make videos or else people will stop giving a fuck and won't donate.
>>
>>60850721
>t. retard
>>
>>60849151
he stores game state in a fucking string, concatenated with and

makes me rage desu
>>
>>60855514
What is it
>>
>>60849151
Use of strings instead of enums.
>>
is yanderedev still interested in getting people to rewrite his code in c#?
>>
>>60854544
Bitmaps exist in C a fair bit more than C++??????

I think you got memed on. Don't use C if you don't even know basic concepts. Otherwise even Python would be faster
>>
>>60849186
The compiler will optimize this more sleekly than human-readable datastructures would
>>
>>60851759
String interning isn't going to help if he's building anything stored in this.Witnessed dynamically, which seems likely with all the "X and Y and Z" values he has in it.
>>
>>60856885
I would cut my dick live on stream if any compiler was able to optimize this exact code.
>>
>>60856885
lol, no it won't. The compiler can't do shit
>>
>>60856885
Prove it. Source or demonstration. Alternatively fuck off with your kike lies.
>>
>>60856071
>Using the this Keyword
>Within an instance method or a constructor,thisis a reference to thecurrent object— the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by usingthis.

From some Java tutorial docs, but the idea is the same in other OOP languages.
>>
Don't know which is funnier his code or typical /g/ failing at basic shit, being retarded and writing buggy broken 'improvements'.
Thread posts: 108
Thread images: 16


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.