There is a fundamental problem with the way software design is taught at the university level

There is a fundamental problem with the way software design is taught at the university level.

Even self-taughts are guilty of this shit.
Why are competent programmers so hard to find?

>There is a fundamental problem with the way software design is taught at the university level

Which is?

because today every incompetent oaf is told they can be a programmer after a 1 day crash course/bootcamp

Is the poster of this actually Yandere Dev?
We may never know!

I mean, he did come to Sup Forums for the initial stuff.
Why not Sup Forums?

What is this written in, though?
I don't normally see PascalCase.

Why is it using else ifs instead of a switch? This isn't Python...
(although, desu, Python is pretty good. I use it for my DiscordBot)

What is with the direct use of class variables, though? Why are you not encapsulating it and using an accessor function??

do people not know how to write a function?

Competent programmers were shit programmers too once.

It's most likely that the competent programmers don't give a shit about you.

I only know ultra basic stuff by reading shitposts and never programmed anything but i think that he should've used switch instead of ifs and else ifs, right?

pls no bully

How would you do that in your pic better?

Not OP, but I'd:
>use a switch instead of else ifs
>NOT directly access data, but use some data hiding and stuff to force use of accessor functions, because it's safer
>use better descriptions for those, but I'm not really 100% sure why he's doing it that way... Maybe an ENUM if it actually needs to print that somewhere

probably a few other things, but rly I'd needa see more of the code to decide on further actions to take.

He's a victim of the OOP meme. He wrote the witness property as a literal string to reference instead of as enumerable states or something similar.

See above.
Or more ideally, this.Witnessed should be an event function that determines what kind of object was witnessed inside the method, and not be an attribute.
He's effectively using an adjective as a verb, which is bad.

That 1000 prints a second was haxe not cpp. mb

Switch statements are no shorter than if else statements and offer much more opportunities to fuck up idiot.

But then the hash map is uneven.

>(float)6

Yeah but switch statements are optimized together. The ifs could do a better job as a standalone decision tree but you might get lucky with a switch. maybe youll land some unions.

which fuck ups? not puttiing a break after each case?
Switch cases are much more efficient as if else blocks also more readable. Sure having more than 20 cases can become unreadable but its still better as reading all those if else boolean operations

Also why is he not using method overloading??

Switch statement ARE shorter than else-ifs...
at least in terms of what you need to read

And in this case, they ALSO would work well since several of the the GameOverCauses are the same.
4 of them are Insanity, and 2 of them are Weapon.

how would method overloading help here?

Yeah.... I'm not sure what that has to do with anything...

I mean, I'm sure there's SOME place in the code that overloading might make sense, but I don't see it in that pic

Maybe it's because im a bit of an aspie but I never did this sort of stuff even at the beginning, I am self taught and been coding since 12, it's the schools that teach this way and the teachers being incompetent morons the kids dont learn shit

by not using the second and third parameters, if he is going to use it EVERYWHERE anyways.
just make a method UpdateLabel(String) call UpdateLabel(string, 1, (float) 6).
I saw he used something other than 1 so hhe can call UpdateLabel(String, int) call UpdateLabel(String, int, float)

it increases code readability and you are also not wondering why he typed it everywhere.

>Which is?
In my experience, the problem was that software design wasn't taught.

there are also many cases that are very similar, which should be put together or at least extracted to a function that handles the minor variations.

why the fuck is this done by strings anyway? If you're not taking an action based off a string typed by the user, then you should be using an enum or something along those lines. Strings are inefficient and error prone.

use a db

This is why you are all on Sup Forums right now.

The best solution is do ditch the conditionals and use an object to pass the values. Define your data separated from your logic branches.
For instance:

consider the object (JSON),
{
thingsWitnessed: "Weapon and Blood and Insanity",
subtitleText: "Teacher Insanity Reaction",
gameOverCause: "Insanity",
}


So instead of conditionals, find the object of thingsWitnessed == this.Witnessed and pass in that object's subtitleText and gameOverCause attributes.

This is the correct answer.

>using a db in a single player game
You might as well just use a hash table, instead of loading up an entire db application to manage a few tiny tables.

This is like loading up chromium to check for updates. It's a bit easier, but it adds a ton of bloat.

if you used an enum for things witnessed, you could just pull it and its attributes out of an an array.

>comparing strings
>iterating over useless JSON objects
t. javascript artisan

public string GetSubtitleText(WitnessState state)
{
const string reaction = "Teacher {0} Reaction";
const int maxWitnessStates = 6; // Can be retrieved dynamically, done here as const for convenience

for (int i = 0; i < maxWitnessStates; i++)
{
WitnessState check = (WitnessState) (1

you don't fucking put the data in the code what the fuck is this bullshit again

there is a fundamental problem when you canĀ“t even put in english what the fuck are you talking about.

I wasn't suggesting an implementation, only a higher level design idea.

What language is that?

C#, same language as in OP

>don't put the data in the code
what part of this is data? things witnessed?

Why wouldn't you put that in the code? If turing complete behavior is determined by the thing witnessed, then there's no point moving it outside of the code.

If it needs to do anything more complex than just output the title, like start a specific AI routine, you're going to need an enum or polymorphic object somewhere to deal with it.

It's got to be Java, as C++ defines "this" as a pointer, not a reference (meaning its members are accused with the arrow instead of the dot operator). I'm pretty sure you can't do testing against strings in a switch, though that could be avoided if they used enums instead of strings (which they should be doing anyway, since it would save a lot of space; only advantage to using strings as enums is that they're printable).

And PascalCase in this instance is unusual, in any modern language it's usually reserved for class types (String, BitInteger, etc) with camelCase or snake_case used for everything else.

Yandere Simulator is written in C#

It's C# so yes "MS Java"

apparently it's C#. You weren't far off though.

>PascalCase in this instance is unusual
not in C#. C# is a special snowflake so it uses pascale case.

Python. The sjw special snowflake of languages.

why is that?

He's a faggot talking shit.
Forget about it.

In my defense, I was approaching the question of which is more optimized to serve his interests.

>eva rused Sup Forums into fixing his code
haha, suckers

It makes things a bit more easily extendable but also harder to read, since the information you need to make sense out of what's written is now spread over multiple files, as opposed to all of it fitting on one screen previously.

It's always a tradeoff between simplicity and extendability, and the choice should not always be in favor of extendability as you're preaching.

I have a small question. Why are you using shift operators when you can do it 'normal' way? Like just putting 1,2,3,4... in that enum.
Is it some kind of preference?

...

Someone already did a long time ago but apparently he is adamant on sticking with his terrible code and complaining that adding stuff and progressing would take too much work

if statements are faster than switch
fuck your coding standard

barring maybe doing it for prototyping reasons, the compilation for that block will involve calls.

Not him, btw.

Fewer calls*


>tfw furor calls

Because you can combine the enums that way, because each value is on its own bit. So you could say the witness state is eg. Insanity & Weapon.

> computed jmp statement is faster than if/elses.

How do you say "your argument is not necessarily true because switches can be optimized in ways if/elses cannot"? in English?

In Java it would be
> this.witnessed.equals("some string")

But yeah, you weren't far off.

Wait.

Are you saying that enums aren't proper types in C#, but just a fucking integer value?

I feel bamboozled. How come nobody is picking on C# programmers for this?

people that endlessly labor over making their code more "efficient" end up increasing execution speed by 5% and decreasing readability by 50%

Really, the worst part about this code is that it isn't properly documented/commented...

> How do you say "your argument is not necessarily true because switches can be optimized in ways if/elses cannot"? in English?

How do you say "jump to variable address instruction used in switch implementation eliminates CPU cache while a bunch of jumps to known addresses produced by if/else keep the cache"? in English?

It's written in a way that you don't need comments to understand it.

Spotted the web dev! jk

Isnt that when you bust out function pointers over regular calls to instated functions or lambdas instead?

Really the best solution here is manual memory allocation.

>accessor functions
t. java fag

...

...

I don't know about C#, I just said that because it's a pretty common thing in C/C++.

But yeah, it's probably just a integer underneath.

Because so I can combine it with OR operators like
WitnessState myState = WitnessState.Insanity | WitnessState.Lewd;


You can see I declared the enum so it inherits byte type, so it's basically a byte underneath.

>Why are competent programmers so hard to find?
Because their classes give them languages that are too easy to use and therefore don't serve as filters. Talentless subhumans breeze through university classes with their training wheels on, and when they get to the real world they pollute the job market with their inferior abilities, instead of failing out at the 101 level and flipping burgers for the rest of their lives.

I think he's talking about code blocks being identified by indentation

>calling strcmp 5000 times instead of comparing ints

Why does this always happen in C# games?
Terraria does the same shit. Is there some code generator tool that does this?

I'm in 101 and we're using c++ how do I do

Is the yoshi supposed to look like a condom on a penis?

What is wrong with this?

It's some decompiled code. It's bound to look shitty.

It's a 2.5k line function that runs every frame

I don't see anything necessarily wrong with these.

T. Novice programmer here. Why does readability have such a premium placed on it? Why not just have good notes/documentation while having the best code you can write? I understand dealing with legacy code, but at the same time "readable code" without documentation is shit to deal with.

it's c#. The "this" is from reflection

>ctrl+f
>prime numbers
>Phrase not found

Holy shit does noone here know anything about efficiency?

Explain.

Then you're part of the problem.

this.Witnessed is an integer that gets multiplied with a prime number every time something is witnessed. To check what is witnessed you use integer division with consecutive primes and order the prime to event map such that important events get checked first.

That's retarded.

>There is a fundamental problem with the way software design is taught at the university level.
NO
> Why are competent programmers so hard to find?
because programming is just a tool. you need to seek people with the ability to efficiently solve problems. this is the problem. also university programming degrees are just meme

not a programmer but even i can understand the genius behind this.

You're welcome to try to come up with a method that'd execute faster and still contain all witnessed events.

Why would you declare it as a byte? You typically don't gain any performance or reduce your memory footprint by using a type size smaller than word size (64 bit on AMD64), if you're not storing an array of the type.

In the case he wants to store it in an array/on disk/send it over network?

Just use powers of 2 instead of primes. Integer divisions are expensive. bitwise and is almost the cheapest instruction that exists.

A bitmask.

Is saving 7 bytes on a network operation with a 64 byte header (assuming TCP) important?

Typically games use UDP so I guess every byte counts.

>How come nobody is picking on C# programmers for this?
The fact that you think that this is some sort of vector for ridicule shows clearly your ignorance on the subject.

could be

If there was nothing to lose from doing it, well, yeah I'd do it. There's nothing wrong with greater efficiency that comes without a cost.

An array...
of...
...
booleans.

UDP is only about 12 bytes shorter than TCP though.

>There's nothing wrong with greater efficiency that comes without a cost
There's a potential maintenance cost of using a type that limits you to 8 values for the enum instead of 32 or 64. Having to go back and switch type sizes often causes problems.

bytes are also slower to compute to some degree. On x86 or AMD64, The compiler typically has to XOR the register before loading a single byte to avoid a dependency chain on the upper bits of the register, while it doesn't need to do this for a 32 or 64 bit value.

When sending an array of those, the size will grow much faster.
I guess it depends on what OP wants to do with it. If he wont use more than 8 he can always cast it to byte to store/send.

A switch may have looked neater, but the point is that there are several redundancies that could have easily been consolidated into fewer lines.

Third year Computer Science student from the UK here

Personally, I think this is down to the fact that it's so easy to get into a Computer Science course, and even easier to stay once you're already in. They have to teach at the lowest level in the class which is usually someone who can barely grasp the object orientation, let alone programming languages themselves.

The way they have to teach is basically "let's get everyone to actually complete this task" which is usually, as in the picture, code that 'works' but is inefficient and crap

If you think those if statements are bad, you'd hate to see how some people work with data structures

I don't mean to sound horrible here but that is honestly the reason teaching isn't very advance and Masters concentrate on good code, which in my opinion should be a major part of the degree. It should be far harder and if you write crap code you shouldn't be able to get anything more than a pass.

rant over

the idea of object orientation**

I need more coffee

masking and bitwise and-ing

you don't need anything more than a pass; companies don't care much, if at all, about your gpa.

CompSci != Software Engineering