|
another version may come up with something like
for ( int i = 0; i < data.Count; container.Add(data[i].Items,i++ )
|
|
|
|
|
improved version of above can be like:
for ( int i = 0; i < data.Count; container.Add(data[i++].Items)
|
|
|
|
|
I can improve even that code
for ( int i = 0; i < data.Count; container.Add(data[++i].Items)
|
|
|
|
|
Adrian0, unfortunately, your solution was invalid.
As ++i will be calculated(increased) before accessing the element of data collection.
container will never have data[0], plus you will receive an out of index exception at the final loop
of this for expression. Say data collection has 4 elements.
Each iteration looks like:
Loop 1, i initialised = 0:
container.Add(data[1]).Items
Loop 2, i initialised = 1:
container.Add(data[2]).Items
Loop 3, i initialised = 2:
container.Add(data[3]).Items
Loop 3, i initialised = 3:
container.Add(data[4]).Items <<< Exception here
When i++ or ++i is within an expression, ++i has the highest priority to get executed bofere the reset of
the expression. In contrast, i++ is get executed after the whole expression has been executed.
container.Add(data[i++].Items) //Get the ith element of data collection, append to container and then increase i by 1
container.Add(data[++i].Items) //Increase i by 1, then get the 1th element of data collection to append to the container.
|
|
|
|
|
Good work yxhu. Didn't recognize that.
But if you are that fussy watch your parenthesis
Loop 3, i initialised = 3:
container.Add(data[4]).Items <<< Exception here
Your code wouldn't compile because .Add() is usually of type void.
greets
Adrian
|
|
|
|
|
Lol... that was a typo. Thanks Adrian0.
|
|
|
|
|
A common one in this forum is functions used that don't actually do anything. Well here is one I have just found too...
public static bool ToBoolean(bool value);
...forget where I seen this now (no wonder it is seen so often, people obviously read too much documentation lol)
PS. I am assuming most no exactly where I found this Convertion function
return 5;
|
|
|
|
|
It not really a horror, is it? It does say it does no conversion in MSDN[^]
I would say it is just there to complete the set: Convert.ToInt32 and so forth are there too.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
As I said. People post these 'Do Nothing' functions all the time. I was simple pointing this one out as these are obviously OK if MS says so
return 5;
|
|
|
|
|
Actually very handy if you are passing a object type which has an underlying value of type bool. Good code should always be strongly typed but maybe when dealing with COM objects, this overloaded method could be handy.
|
|
|
|
|
Robert Croll wrote: Actually very handy if you are passing a object type which has an underlying value of type bool
But this specific function does not take an object. It takes a bool and returns a bool. Just wasted code in any usage
return 5;
|
|
|
|
|
For those who desperately need self-validation.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
|
The horror here is not only that these methods do not do what they are supposed to do. The fact is that the implementation itself is really poor. Seems that the programmer got paid according to the number of lines of code he wrote.
|
|
|
|
|
Well... Actually I (the new developer) has to pay :P
|
|
|
|
|
Hopefully the programmer was so called "Senior". That's a tough call for a junior programmer.
|
|
|
|
|
The root of the problem is that it's done in VB...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Found this in the daily WTF.
private IAlertDocument CompareObjectAsIAlertDocumentOrNullIfNotCastable(object compareObject) {
return compareObject as IAlertDocument;
}
What do you think? I can follow this pattern:
string GetAStringThatRepresentsTheObjectPassedAsAnObjectParameterSoItWorksForAnyObject(object obj)
{
return obj.ToString();
}
|
|
|
|
|
_Erik_ wrote: string GetAStringThatRepresentsTheObjectPassedAsAnObjectParameterSoItWorksForAnyObject(object obj)
{
return obj.ToString();
}
You forgot part of the method name...
It should be... GetAStringThatRepresentsTheObjectPassedAsAnObjectParameterSoItWorksForAnyObjectAsLongAsTheObjectIsNotNull
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Damn it!! I thought I could follow the pattern!!
|
|
|
|
|
Throw new UserFellAsleepAtTheKeyboardException(me)
Dwayne J. Baldwin
|
|
|
|
|
Before I get started, some background:
gr1d[^] is a (very new) persistent multiplayer programming AI game: the idea is you code your agents and upload them, and let them do their thing. (Check it out, if you haven't!)
Now, with these agents, they have to inherit an interface. For brevity, I'll reduce it to the relevant details:
Public Class πRateSapient
Implements gr1d.API.Agent.IPirate1
...
Public Sub Tick(ByVal agentUpdate As Gr1d.Api.Agent.IAgentUpdateInfo) Implements ...
' Logic here
End Sub
(VB is NOT the code horror, thank you very much! :P )
Now, in my infinite wisdom, I started some abstractions. This included building it so all AIs under that schema (my search/claim/don't go picking fights) operated under the same logic.
How'd I do this? Well:
Public Module Logic
<Extension()>
Public Sub Tick(ByVal agent As πRateSapient, ByVal update As Agent.IAgentUpdateInfo)
' Logic here
End Sub
...
Can you see where this is going? I didn't.
Public Class πRateSapient
Implements gr1d.API.Agent.IPirate1
...
Public Sub Tick(ByVal agentUpdate As Gr1d.Api.Agent.IAgentUpdateInfo) Implements ...
Me.Tick(agentUpdate)
End Sub
...
No debugging, no thought put into it, I just thought it'd call the extension method.
Whoops. And yeah, it was sloooow.
Moral of the story folks: think about your damn naming conventions, especially if you're using extension methods!!!
(And I was wondering why my agents did nothing!)
(Also, may I mention that running the game logic, and the site, on the same instance is also a bit of a horror?)
Hope you laughed.
[edit]
To be fair, I wasn't the only one with a recursive loop. But I sure as hell didn't help. xD
[/edit]
Don't forget to rate my post if it helped!
"He has no enemies, but is intensely disliked by his friends."
"His mother should have thrown him away, and kept the stork."
"There's nothing wrong with you that reincarnation won't cure."
"He loves nature, in spite of what it did to him."
modified on Wednesday, December 22, 2010 6:05 AM
|
|
|
|
|
|
Kinda learned that one, didn't I? :P
Don't forget to rate my post if it helped!
"He has no enemies, but is intensely disliked by his friends."
"His mother should have thrown him away, and kept the stork."
"There's nothing wrong with you that reincarnation won't cure."
"He loves nature, in spite of what it did to him."
|
|
|
|
|
Last time I tried to even check the site out, it was at a crawl.
|
|
|
|