September 2006 - Posts

Hey,

im sitting here at the basta. its halftime.

The Basta Conference 2006 in Mainz is a german speaking 4 day event for .net and Visual studio. with pretty interessting speakers like Dino Esposito or Jason Zander.

As the keynote we heared from Jason many things about, what comes in the next time from Microsoft. so an overview of .net 3.0 and the Atlas and so on. a good overview and introducing in all the stuff and why it was done.
and... he showed us a really cool demo. as allways with the coolest features you can have currently.
it was an calcuclator, that he programmed from the IronPython console. thats something i also use for my next presentation...

The first Session was about Team System. and all about the features it has. pretty cool. will save some of my work i think. will start using it right after i come back. currently the most of them i cover with other products. but let´s give the "fully intregrated" once an try...

Then we met some really cool guys (Mark Miller and Oliver Sturm) from DevExpress and talked about some nice additions to their Refactor! it and dxCore product. and they are really smart, because they dont put them on their wish list, they even IMPLEMENTED this directly while we stand next to them in a simple version into their Visual studio AddIn. isn't that a cool feature. now i not only have my additions, i also know how to add one of them, if i want one. thank you.

Next, i got some introducing about MDA, a Model Driven Architecture. cool idea and stuff here. good to know that stuff. I'll implement that in one of my later projects.

After the Lunch, we talked with some guys about testing. specially speed tests. there are some guys of "Speed Test Pro". that looks really cool. nice featureset, really easy implementation, good reports. they bring a new version the next weeks. looking foreward for that. (with the new version, the trace file is written directly to disk. not to the memory...)

After a little bit sitting in the sun, we looked foreward for dino's session. That was really cool. He really give us the feeling, how it is to program with Ajax. a great Speaker. and was very interresting.
The coolest feature i see in Atlas?
That you have clientside also an DataSource (like the DataSet) and the Visualization can have Filters like the Dataview and is automatically updated, when you add, remove, change something in the source. isn't that a cool feature?
i just start programming now...

So, a short wrapup?
Nothing of "Cool new stuff, that you comes in a year"
All Sessions are to start programming now. (.net 3.0, team system, Atlas, Ajax, SOA)
nearly no Vista (just jason has it on his machine and it had an black screen once^^)
Many SOA solutions
Much stuff for managing your live nebst programming. but no standard there.
Really nice people to talk with.
Great food.
The Wlan connection is not the best here (seems they run out of ip adresses in their pool)
Bad, i missed the session about .net on the xBox

 So, thats all for now. i write the second part on thursday, after the conference.
If you have questions, want more infos an a specific part or session just ask me.

Brenton House posted about an Interesting Interview Question.

its  pretty easy.

selected = selected++;

what comes out?

 

on the first view, you would say something+1. but that's not right.

The most people use this with some while stuff.

int something = 0; while(something < 10) { //do something something++; }

here it is easy. it'll do the while 10 times.

But the base idea is a little bit different. this is done that you don't need to write an extra line for the counter.

int something = 0; while(something++ <= 10) { //do something }

so. the something is automatically incremented with the ++. no need for an extra line....
but, does this now 10 iterations or 11? what is returned in the 10th iteration?

The answer is, there are 2 of this ++ features you can use.

// returns something and increment something afterwards something++; // increment something bevore, and the returns the result ++something;

so. now it is clear. there would be 11 iterations, because at the 10th, 10 is returned, and 11 is stored afterwards.

and that's exactly what happens in the question.

selected = selected++;

here, at the right side, selected is returned, and then incremented. and after that, selected is stored on the left side. so the answer is, the original value is stored. not the incremented.

selected = ++selected;

Here, it would happen what you normally expect. the incremented value would be stored.

little tricky, hah?

with 1 comment(s)
Filed under:

eh, oh. someone who uses anonymous methods? aren't they so bad? why should someone use them?

here, I cry it out. I LOVE them. they are great.

first, what are these Anonymous Methods?
Anonymous Method is a new feature of the .net 2.0. with them, you can create an inline method, without having to name them. here's an short example:

 

// Create a handler for a click event
button1.Click += delegate(System.Object o, System.EventArgs e)
{ System.Windows.Forms.MessageBox.Show(
"Click!"); };

So, seems to be easy. but why most people say, they are bad is, because the usability of code drops. these Methods are not listed anywhere nor can be reused. so it seems they are just for the guys, that program "quick and dirty"

BUT, they have one feature, that makes them really cool and useful in some conditions. and this feature is also one of the things, you really should be aware of, if you using them.
These methods are sharing the context of the Hosting Method. yes. you can access any of the private variables of the method where you created it.

Hmm.. sounds a little crappy.
Where to benefit from it?
Let me show you an example of the most common once.
We want to use any feature and improvement of .net 2.0. so we use a generic Collection for our items.

 

public class MyListSearcher {
private List<string> myList = new List<string>();

public MyListSearcher() {
myList.Add(
"foo");
myList.Add(
"bar");
}

}

Now, we want to make a public function, that has an char as Parameter and returns the first entry, where the char is contained. if none, it returns string.Empty. oh, yea. this is easy. lets make an foreach...
NO. the List have some pretty cool functions, that are much faster than an foreach. like the List.Find method.

 

public string GetStringContainingChar(char c)
{
return myList.Find(new Predicate<string>(???));
}

This method accepts an Delegate, that is called for every item in the List, until it returns true, then this Item is returned.  beside of making the process faster, its also much cleaner to read the code.

The easiest would be, making a new Method and store the character in the current class, so the Method can access it, and use it.

 

private char savedChar;

public string GetStringContainingChar(char c) {
savedChar
= c;
return myList.Find(new Predicate<string>(stringContainsChar));
}

private bool stringContainsChar(string s) {
return (s.IndexOf(savedChar) != -1);
}

That's working. and enough for a single thread. but what, if there can be multiple calls at the same time? then this solution does not fit anymore. the easiest workaround is, create a short class, that holds you your value.

 

public string GetStringContainingChar(char c) {
SearchHelper helper
= new SearchHelper(c);
return myList.Find(new Predicate<string>(helper.StringContainsChar));
}

private class SearchHelper
{
private char c;

public SearchHelper(char c)
{
this.c = c;
}

public bool StringContainsChar(string s)
{
return (s.IndexOf(c) != -1);
}
}

Now, this is also Multithreading save. the implementing Method is pretty short. but we have such damn Helpers, that noone likes. let's see, how we can get rid of this all with an Anonymous Method.

 

public string GetStringContainingChar(char c) {
// using Anonymous Method
return myList.Find(delegate(string s) {
return (s.IndexOf(c) != -1);
});
}

Is that short. The delegate can use all private variables of the hosting Method. so also its Parameters (but no out or ref parameters). I prefer always to make a comment before, so when someone comes thru it, he knows, what is used here (there are not much people outside using this). there is no faster and shorter solution than this.

What to think of:
These Anonymous Methods share the context. so the context has to be alive as long as the Method is referenced. so if you add an Method for example to an Event of classB, then your Method and class is in memory until classB drops out. could be a possible memory problem

You have to think of as if the Method itself is the hosting class for the Delegate. and if you are modifying variables of the Method, you can run into an Multithreading problem again, if the delegate is called parallel. here's a demo:

internal static class staticTest {
public delegate void TestDelegate(string text);

public static TestDelegate Tester;

public static void InitTest() {
int count = 0;
string myString = "init";

Tester
= delegate(string text) {
Write(
string.Format("Bevore: int {0}: string {1}", count, myString));
count
++;
myString
= text;
Write(
string.Format("After: int {0}: string {1}", count, myString));
};

}

public static void RunTest() {

InitTest();
Write(
"Test Initiated");
Tester(
"test one");
Tester(
"test two");
}

}

so, on every call of the Tester delegate, the count is risen and the text is changed. the output is like

Test Initiated

Bevore: int 0: string init
After: int 1: string test one

Bevore: int 1: string test one
After: int 2: string test two

 

So, we see, there are really some useful stuff, what you can do with these. if you have some other ideas, where they would be great, let me know, and i post them here.

 

Some Q&A

Why is this working in Multithreading, when i reuse the class instance? isn't that then the same context?
No, the context of the Method itself is different on every call. just the context of the class is the same. so the Parameter c is not shared.

 

Update: added my demo project