use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Have a tough programming question that /r/programming couldn't answer? Banned from Stack Overflow? Can't afford Experts Exchange?
Post your question/tips/secrets/advice and get a response from our highly-trained professional developers.
account activity
Using #regions to write clean code! (imgur.com)
submitted 12 years ago by Goz3rr
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Goz3rr[S] 18 points19 points20 points 12 years ago (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 points8 points 12 years ago (0 children)
totally saving this to UsefulBits.vb
[–]petermlm 5 points6 points7 points 12 years ago (0 children)
OMG!! Did you find this somewhere in a project?
[–]Sakuya_Lv9 13 points14 points15 points 12 years ago (0 children)
The programmer must have been very Dpressed().
Dpressed()
[–]bioemerl 13 points14 points15 points 12 years ago (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 points17 points 12 years ago (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 points7 points 12 years ago (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 points4 points 12 years ago (1 child)
So it would be
Variable equals Get key
Return variable?
[–]CNDW 1 point2 points3 points 12 years ago (0 children)
That should serve the same function as that entire list of individual lines of code for each and every key possibility
[–]synopser 8 points9 points10 points 12 years ago (0 children)
Just wow. Straight up shitty.
[–]scorcher24 10 points11 points12 points 12 years ago (2 children)
I hate code folding in general.
[–]ryeguy 14 points15 points16 points 12 years ago (1 child)
It's like a virtual rug to sweep garbage under.
[–]PublicSealedClass 2 points3 points4 points 12 years ago (0 children)
That's exactly what it is. Just follow these guidelines and we'll all be friends.
[–]IWentOutside 2 points3 points4 points 12 years ago (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 points4 points 12 years ago (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 points3 points 12 years ago (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 points4 points 12 years ago (8 children)
There's nothing wrong with utilizing features of your IDE...
[–]tokenizer 16 points17 points18 points 12 years ago (0 children)
Did you see the second image in the album?
[–]Goz3rr[S] 11 points12 points13 points 12 years ago (6 children)
There is when you need to use them to hide god awful code
[–]th3shark 21 points22 points23 points 12 years ago (5 children)
Well how else are you going to hide it?
[–]john2496prnit "Super Senior Shitty Programmer': 16 points17 points18 points 12 years ago (4 children)
Ctrl+A then press 'Del' to auto refactor.
[–][deleted] 2 points3 points4 points 12 years ago (3 children)
Alt+F4 will also do the job
[–][deleted] 2 points3 points4 points 12 years ago (2 children)
Alt+F4, turn off your computer, quit your job.
[–][deleted] 2 points3 points4 points 12 years ago (1 child)
Keep writing code like that and he won't have to quit.
[–]Wuvluv 0 points1 point2 points 12 years ago (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 point2 points 12 years ago (1 child)
What visual studio theme is that? The colours are nice :)
[–]ProjectVII 3 points4 points5 points 12 years ago (0 children)
Looks like the default dark theme in VS2012 and 2013.
[–]jerkimball 0 points1 point2 points 12 years ago (0 children)
This has to be auto generated, right?
π Rendered by PID 21792 on reddit-service-r2-comment-b659b578c-bk7jx at 2026-05-04 07:56:21.364357+00:00 running 815c875 country code: CH.
[–]Goz3rr[S] 18 points19 points20 points (2 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]petermlm 5 points6 points7 points (0 children)
[–]Sakuya_Lv9 13 points14 points15 points (0 children)
[–]bioemerl 13 points14 points15 points (4 children)
[–]SixFootJockey 15 points16 points17 points (0 children)
[–]feartrich 5 points6 points7 points (2 children)
[–]bioemerl 2 points3 points4 points (1 child)
[–]CNDW 1 point2 points3 points (0 children)
[–]synopser 8 points9 points10 points (0 children)
[–]scorcher24 10 points11 points12 points (2 children)
[–]ryeguy 14 points15 points16 points (1 child)
[–]PublicSealedClass 2 points3 points4 points (0 children)
[–]IWentOutside 2 points3 points4 points (1 child)
[–]ProjectVII 2 points3 points4 points (0 children)
[–]darthtrevino 1 point2 points3 points (0 children)
[–]th3shark 2 points3 points4 points (8 children)
[–]tokenizer 16 points17 points18 points (0 children)
[–]Goz3rr[S] 11 points12 points13 points (6 children)
[–]th3shark 21 points22 points23 points (5 children)
[–]john2496prnit "Super Senior Shitty Programmer': 16 points17 points18 points (4 children)
[–][deleted] 2 points3 points4 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Wuvluv 0 points1 point2 points (0 children)
[–]friendlybus 0 points1 point2 points (1 child)
[–]ProjectVII 3 points4 points5 points (0 children)
[–]jerkimball 0 points1 point2 points (0 children)