|
Member 2053006 wrote: If I put the Reduce() method on OblongCollection then it would return another OblongCollection and still need a loop to process the code that has been snipped out.
Sure?
public void ReduceCandidates()
{
for (int index = 0; index < this.Count; ++index)
{
using (Oblong currentCandidate = this[index])
{
Oblong fittedOblong = currentCandidate.Reduce();
}
}
}
Your original never returned a new collection, so why should this?
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Ah, I think I see what you are saying there, move the entire method into OblongCollection . A good idea, but OblongCollection is in a shared library (mixed mode C++) and the snipped code is application specific, in C# and refers to some more instance members. I would rather keep application code out of the shared library unless it is generic enough to be useful in more then one application, which the snipped code is not.
|
|
|
|
|
If that is the case, I'd wrap OblongCollection within an application class. It is, generally speaking, a good idea to always wrap external API's in a class as it hides the API specifics from the developer.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Couldn't you use a delegate here? Pass a delegate for a void function taking an Oblong to ReduceCandidates(). Then you could implement the ReduceCandidates() in the library as a member of OblongCollection and the application specific code inside the delegate definition in the application.
|
|
|
|
|
It's a pretty big WTF that something can get disposed by the framework when you still have a reference to it.
|
|
|
|
|
There is no longer a reference to it when it is finalized. The indexer returns a new object which is not stored anywhere, so goes out of scope as soon as it is created. As soon as non of the instance fields of that object can not be accessed by any code the object is eligible for finalization.
I could (and should) have prevented the finalizer from running by putting a GC.KeepAlive(this) at the end of the Reduce() method, yep, finialzers are nasty. The real code horror was not disposing of disposable objects. My bad.
A good article I found on here that mentions GC.KeepAlive is Implementing IDisposable and the Dispose Pattern Properly[^]
See point 2 in this article (OK, so this is for an old version of .net)
(MSDN article) 3.9 Automatic memory management
|
|
|
|
|
There is still a reference – this within the executing Reduce method. While one could argue that you should have worked around it, the framework really shouldn't finalise something on which code is currently executing under any circumstances (well, unless you call Dispose before you try to do something else, I suppose).
|
|
|
|
|
|
Take a peek at some VB. That should at least replace the horror with one that is at least expected.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
As a VB programmer I see my share of VB... Seen many horrors as well (VB6 and even pre-VB4 practices in .NET)
I have no doubt there is legacy C# code that is as bad as legacy VB code or even worse though.
In the end code is as good as the programmer writes it, independent of the language
It's an OO world.
public class Naerling : Lazy<Person>{}
|
|
|
|
|
touche.... There is definitely some horrible C# code out there. For that matter, horrible code exists in every language.
I equate that to people of any given language who have no understanding of grammar, syntax or punctuation. I have a lot of vb and vb.net systems that I work with daily as well. I tend to find that vb lends itself to being ugly by nature which is why I prefer C# and C++ to vb.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
When programming VB just make sure to uncheck the VisualBasic Namespace reference and put Option Strict on. That's the first step in the right direction!
It's an OO world.
public class Naerling : Lazy<Person>{}
|
|
|
|
|
Some languages make it easier or harder than others to write good/bad code, though.
|
|
|
|
|
True, but neither VB nor C# prevents you from writing code as it should be
I'm a VB programmer most of the time, but you don't see me using OnErrorResumeNext or GoTo.
And an empty try catch block is just as easy to write in C# as in VB.
It's an OO world.
public class Naerling : Lazy<Person>{}
|
|
|
|
|
Naerling wrote: but you don't see me using OnErrorResumeNext or GoTo
If you did and I found out, you's get a virtual slap through the monitor from me...
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
A truly talented programmer can mess things up in any language, not only VB
|
|
|
|
|
Any chance at getting to normalize the table? If met with resistance from the customer about normalizing, sell the idea of performance benefits.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Yeah, it's going to be okay. Luckily. I found another table like that today (it's all the same schema, so we know where it's wrong).
Seriously, no table in the schema has any FK's. A few tables are like the one I described. And this is a vital part of our system!
It's an OO world.
public class Naerling : Lazy<Person>{}
|
|
|
|
|
I have once worked with a customer database that had tables with 40 columns, no FK and PK of type varchar(50). Heck the Names column was primary key, when I asked the client what'll happen if another guy joins the Org with same name as his, he was shell shocked.
|
|
|
|
|
You're right, it's not how we do things here, following procedure would require at least 10 primary key column! :P
Remember, it's more important to follow procedure than being actually productive!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I just read a function code like this :
function MightyFunction(paramA, paramB, paramC)
! Lots of code here.
! But this is the magic.
Return retA
Return retB
The code is written in Centura 1.5, and the compiler compiled it successfully.
It's easy to laugh, but, it's so hard to smile ...
|
|
|
|
|
That would compile in Visual Studio also. Just a warning about "unreachable code detected".
|
|
|
|
|
I just can't imagine, what the intention of "double return"
It's easy to laugh, but, it's so hard to smile ...
|
|
|
|
|
I sometimes use kick-out returns to temporarily 'comment out' code I suspect of breaking things. You can still do it in C# (might be an error in Java, I forget), and obviously in things like JavaScript or PHP. Leaving one in is pretty bad though.
|
|
|
|
|
Hmm, for some reason that reminds me of the custom scripting language used in the game "Space Empires V"... one of its unique quirks was that a "return" statement did not actually terminate function execution! So the function you describe would in SE5 script wind up returning retB, because it's the last return statement to execute...
|
|
|
|