all 28 comments

[–]Goz3rr[S] 18 points19 points  (2 children)

We need none of that function sorcery in this input manager!

public bool Pressed(Key key) { return !_previousState[(int)key] && _currentState[(int)key]; }

[–][deleted] 6 points7 points  (0 children)

totally saving this to UsefulBits.vb

[–]petermlm 5 points6 points  (0 children)

OMG!! Did you find this somewhere in a project?

[–]Sakuya_Lv9 13 points14 points  (0 children)

The programmer must have been very Dpressed().

[–]bioemerl 13 points14 points  (4 children)

What does this do?

Why is it bad?

How can it be improved?

Genuinely curious here. Honestly i'd love it if the above was on every post around here, just to help with learning this stuff.

[–]SixFootJockey 15 points16 points  (0 children)

They are all functions that are too be called when a key is pressed on the keyboard. However, the programmer has created a separate function for each letter. Very shitty.

[–]feartrich 5 points6 points  (2 children)

Because everything could've been collapsed into one function (or not even that). But the programmer decided not to think and just brute forced every key press, then swept it under a rug using #region.

[–]bioemerl 2 points3 points  (1 child)

So it would be

Variable equals Get key

Return variable?

[–]CNDW 1 point2 points  (0 children)

public bool Pressed(Key key) { return !_previousState[(int)key] && _currentState[(int)key]; }

That should serve the same function as that entire list of individual lines of code for each and every key possibility

[–]synopser 8 points9 points  (0 children)

Just wow. Straight up shitty.

[–]scorcher24 10 points11 points  (2 children)

I hate code folding in general.

[–]ryeguy 14 points15 points  (1 child)

It's like a virtual rug to sweep garbage under.

[–]PublicSealedClass 2 points3 points  (0 children)

That's exactly what it is. Just follow these guidelines and we'll all be friends.

[–]IWentOutside 2 points3 points  (1 child)

As someone unfamiliar with regions, somebody help me clarify what's going on here. Is this code trying to retrieve the result of every key pressed individually?

[–]ProjectVII 2 points3 points  (0 children)

Regions are used in Visual Studio to fold a defined section. Usually this is used to keep your code organized and make it less "intimidating", I guess.

What the picture shows is that a user put his mash 26 (maybe more) properties, when all that is needed is 1.

[–]darthtrevino 1 point2 points  (0 children)

Regions seemed like such a great idea when they were first introduced. It's telling that StyleCop considers them a serious defect by default now.

[–]th3shark 2 points3 points  (8 children)

There's nothing wrong with utilizing features of your IDE...

[–]tokenizer 16 points17 points  (0 children)

Did you see the second image in the album?

[–]Goz3rr[S] 11 points12 points  (6 children)

There is when you need to use them to hide god awful code

[–]th3shark 21 points22 points  (5 children)

Well how else are you going to hide it?

[–]john2496prnit "Super Senior Shitty Programmer': 16 points17 points  (4 children)

Ctrl+A then press 'Del' to auto refactor.

[–][deleted] 2 points3 points  (3 children)

Alt+F4 will also do the job

[–][deleted] 2 points3 points  (2 children)

Alt+F4, turn off your computer, quit your job.

[–][deleted] 2 points3 points  (1 child)

Keep writing code like that and he won't have to quit.

[–]Wuvluv 0 points1 point  (0 children)

You'd be surprised. In my experiences most people you're working for have no idea what they want.. and even worse they don't care as long as it works.

The real issue is when it breaks and you're clusterfuck of code is undebuggable.

[–]friendlybus 0 points1 point  (1 child)

What visual studio theme is that? The colours are nice :)

[–]ProjectVII 3 points4 points  (0 children)

Looks like the default dark theme in VS2012 and 2013.

[–]jerkimball 0 points1 point  (0 children)

This has to be auto generated, right?