Visual Studio autogenerated code
-
If the first
if
is true, for example, why bother testing all the others which follow? It's dopey code.Steve
some else if would be much better indeed, and the switch/case would be even more appropriate for this stuff, but still it doesn't real shock me.
-
This is the base code vs generates to check for special keys, on a Smart Device project:
private void Form1\_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == System.Windows.Forms.Keys.Up)) { // Subir oscilador // Subir } if ((e.KeyCode == System.Windows.Forms.Keys.Down)) { // Bajar oscilador // Bajar } if ((e.KeyCode == System.Windows.Forms.Keys.Left)) { // Izquierda } if ((e.KeyCode == System.Windows.Forms.Keys.Right)) { // Derecha } if ((e.KeyCode == System.Windows.Forms.Keys.Enter)) { // Entrar } }
A Pocket PC is full of power, so let's check for every possible key.
Ah, but this way there's a nice little hack brewing. Modify the parameters in some ASM code mid-execution, and you can invoke multiple segments of code. That way, there's two operating modes built in - cracker and normal user. Crackers can have super-special zero-bug privileges, while normal users can get walloped with the bug-hammer Of course, a nice little service running in the background on the target machines can do this automatically. Maybe a clause can be put in which stops modifying the code if certain packets are received. Grumpy, abusive user gets bugs, rich user with lots of contacts gets fewer
-
This is the base code vs generates to check for special keys, on a Smart Device project:
private void Form1\_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == System.Windows.Forms.Keys.Up)) { // Subir oscilador // Subir } if ((e.KeyCode == System.Windows.Forms.Keys.Down)) { // Bajar oscilador // Bajar } if ((e.KeyCode == System.Windows.Forms.Keys.Left)) { // Izquierda } if ((e.KeyCode == System.Windows.Forms.Keys.Right)) { // Derecha } if ((e.KeyCode == System.Windows.Forms.Keys.Enter)) { // Entrar } }
A Pocket PC is full of power, so let's check for every possible key.
You would delete the auto-generated code anyway wouldn't you? Actually isn't there a file (or files) that contain such things and you can change them there?
-
This is the base code vs generates to check for special keys, on a Smart Device project:
private void Form1\_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == System.Windows.Forms.Keys.Up)) { // Subir oscilador // Subir } if ((e.KeyCode == System.Windows.Forms.Keys.Down)) { // Bajar oscilador // Bajar } if ((e.KeyCode == System.Windows.Forms.Keys.Left)) { // Izquierda } if ((e.KeyCode == System.Windows.Forms.Keys.Right)) { // Derecha } if ((e.KeyCode == System.Windows.Forms.Keys.Enter)) { // Entrar } }
A Pocket PC is full of power, so let's check for every possible key.
This might not be a horror at all. Maybe it's intended this way (I don't know as I never used a Pocket PC). If the user presses multiple directions, several
if
s are true and the code for each of them should be executed. Otherwise diagonal directions would be impossible because it would accept only a single directional key at once. -
This might not be a horror at all. Maybe it's intended this way (I don't know as I never used a Pocket PC). If the user presses multiple directions, several
if
s are true and the code for each of them should be executed. Otherwise diagonal directions would be impossible because it would accept only a single directional key at once. -
You would delete the auto-generated code anyway wouldn't you? Actually isn't there a file (or files) that contain such things and you can change them there?
PIEBALDconsult wrote:
You would delete the auto-generated code anyway wouldn't you? Actually isn't there a file (or files) that contain such things and you can change them there?
Of course, I can change the code, the same way you would change the code on all the horrors published here. Isn't this forum to publish horrors you find over there? I think this is a reply horror. :laugh:
-
...yes, thatwould be true
-
It's not a big horror, its just funny to see it on Visual Studio. The correct implementation would be:
private void Form1\_KeyDown(object sender, KeyEventArgs e) { switch(e.KeyCode) { case System.Windows.Forms.Keys.Up: // Subir oscilador // Subir break; case System.Windows.Forms.Keys.Down: // Bajar oscilador // Bajar break; case System.Windows.Forms.Keys.Left: // Izquierda break; case System.Windows.Forms.Keys.Right: // Derecha break; case System.Windows.Forms.Keys.Enter: // Entrar break; } }
-
...yes, thatwould be true
Even if multiple keys where able to be captured at the same time, using many == will not be a solution. After all, if the keys where combined using the | operator, as happens with flags, the right way to check the values will be using: if ((parameter & condition) == condition) or if ((parameter & condition) != 0) But that's not the case with keys. So, this is an ugly code (but not an horror in my opinion).
-
it is a horror that this visible code is so poor. :mad: What about the non-visible code. Shame on Microsoft!!! X|
Press F1 for help or google it. Greetings from Germany
-
If the first
if
is true, for example, why bother testing all the others which follow? It's dopey code.Steve
That many bunch of
if
s could have been elegantly presented with a decentswitch
block.Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
I mean the code we cant look at, like the soruce code of windwos or Office. :-\
Press F1 for help or google it. Greetings from Germany
KarstenK wrote:
we cant look at, like the soruce code of windwos or Office
But we can feel it and enjoy it with timely patches and service packs.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
adgonz wrote:
multiple events are fired.
The application goes haywire and user runs amuck helter-skelter.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
KarstenK wrote:
we cant look at, like the soruce code of windwos or Office
But we can feel it and enjoy it with timely patches and service packs.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
I don't see any horror here. What do you want to do if you need to check for those keys?