Saturday, January 15, 2005

delegates in java

so, this c# project that i have to convert to java uses delegates. i hadn't worked with delegates in c# before, so studying the delegates usage in the project was quite interesting. after some research i decide not to use reflection or anything else as a means to implement delegates in java. instead i take a to rewrite the code that uses delegates to simple function calls constructs. delegates here are used to make a templates approach to some tasks - for example visit a hierarchy of objects each of which may have subhierarchy and so on. with delegates used it makes it easy to go down the tree of objects and apply some operation on each of them AND - what is important -the operation would be a delegate so many operations can be executed by calling a single method that traverses the tree. or sort of :)
so my decision - as i cant use template code - is to generally make a tree traversal in a distinct method for each operation.
so instead of

internal override void visitHierarchy(CollectionVisitor visitor)
{
base.visitHierarchy(visitor);

foreach (SomeObject Obj in collection1)
Obj.visitHierarchy(visitor);
foreach (SomeObject Obj in collection2)
Obj.visitHierarchy(visitor);
}

there will be a similar block of code, but implemented for the different operations that need to be executed:

public void visitWithOperation1()
{
super.visitWithOperation1();

foreach (SomeObject Obj in collection1)
Obj.visitWithOperation1();
foreach (SomeObject Obj in collection2)
Obj.visitWithOperation1();
}

and

public void visitWithOperation2()
{
super.visitWithOperation2();

foreach (SomeObject Obj in collection1)
Obj.visitWithOperation2();
foreach (SomeObject Obj in collection2)
Obj.visitWithOperation2();
}


of course there isn't foreach in java... but hope you get the idea....
so this is a little bit tedious approach to rewriting delegates in java, but i hope it works for now

Wednesday, December 22, 2004

vs.net 2003: Could not copy temporary files to the output directory.

ok, after fighting this problem for weeks, i gave up trying to have all my project output to the same folder. wrote a copy file post build event and calmed down. the strange thing is this (single output folder for all projects) setup worked very well for months and "suddenly" it started failing - first once at a time, then to an extent where i could not normally work... i read and read posts, blogs, newsgroups, articles, tips and shits with no productive result.
oh, well - after all it is a do-once operation; hope i wont have to fix it again.

mscorwks.dll could not be loaded

i have sent a new application to one of my customers. suddenly they complain that they recieve a strange message that i have never encountered:
"mscorwks.dll could not be loaded". what the hell ? they have followed my instructions and have installed .Net Framework 1.1 and some additional libraries, so what might be the problem ?? good thing there's google and the .Net 247 community; and this article - http://www.dotnet247.com/247reference/msgs/41/207197.aspx.
so i have mixed a debug and release version ? hmm but why didnt i get that message locally then ? the Mystery of the Sith.....

Edit: so, after i read this thread i began to get suspicious and checked with my clients exactly what version of the .Net Framework they had and.... voila! they had 1.0.xxxx when 1.1 was needed! man, this remote work is getting so confusing sometimes....