February 2005 - Posts

For one of the projects I had to do, I had to create an online survey application, which would be used to gather feedback from Microsoft events. Up until then, feedback was collected by handing out a form and entering the data manually.

As I was given free choice on how to solve this problem I suggested using an existing open-source framework and extending it to meet the requirements. This suggestion was quickly approved because on one side it meant commitment from Microsoft towards open-source and on the other hand it prevented re-inventing the wheel. The project used for this solution is called NSurvey. This provides a survey framework, making it very easy to setup surveys, add questions, add users, do mailings, implement security on a survey-based level, perform statistical operations on the answers and add new functionality by extending on existing classes.



NSurvey is an ASP.NET application, written in C#, which uses a SQL Server back-end, using stored procedures, and various other layers. The installation of NSurvey went very smoothly because of an msi file, placing all files in their correct location.

I started by testing the application and learning the big structure of how it worked. During this small test round, I began thinking on how the final solution would look.
with no comments
Filed under:
One of the tools I had in my toolbox was Reflector. This tool is written by Lutz Roeder and allows you to examine a .NET assembly. Through the use of reflection it can display all namespaces, classes, methods, properties, events and fields in the dll.

It is possible to view the code in IL, C#, VB.NET and Delphi. Some of the useful features are the Call and Callee Graph.

The Call Graph shows you which items are used by a given method, while the Callee Graph displays all the methods that call a given method.







Forgot something for blog readers, the url where to get it: http://www.aisto.com/roeder/dotnet/
with 1 comment(s)
Filed under: ,

This post moved to http://blog.cumps.be/boxing-unboxing-in-net/ with some additional information about generics.

with 3 comment(s)
Filed under: ,
Important note (to not get confused):
The text below (and the future ones) is written in the past tense, because they are text that have to go into a book for school, which you have to write after your internship, giving info about what you did. But I'm writing it piece by piece, because otherwise it will be too much to remember, and a lot less detailed :)


For the second year in row, Microsoft organized the Imagine Cup. This is an international contest with various categories. As a part of my internship, I had to compete in the Visual Gaming and the Information Technology category.


The IT category was about diving into solving real life IT problems. With questions about networks, databases and various servers the content was really diversified.

You get 30 minutes to solve 30 questions, scoring 3 for each correct answer, 0 for a blank answer and -1 for a wrong answer. The first 5 people of a country advanced to the next category, which was the first goal of my internship.

After having spent half an hour taking the quiz, I had to wait a day to get the results, to prevent abuse. My score ended up being a 66/90, placing me at a shared first place in the Belgian competition. My first goal was reached.



The Visual Gaming competition was a coding challenge. In this competition you were given an SDK, which included a 2D-viewer, 3D-viewer, documentation and the required assemblies.

In the VG competition you had to write code for robots in a small game, their brains, or also called, AI. The main things I learned thanks to this competition were algorithm-knowledge, performance issues and logic thinking.

Algorithm knowledge was useful to find optimal actions for the robots, for example, the A* algorithm explained above, helped to find the shortest path. Other algorithms such as Traveling Salesman Problem also had to be solved and implemented to gain a strategic advantage in this game.

Performance was a very important aspect in the VG competition. Because your code had a limited time-window it could run in, it had to be very fast, making sure it stayed inside that window. This was the reason why I implemented a binary heap in the pathfinder, and why I made a lot of performance optimizations, such as preventing boxing and unboxing, storing certain 2-dimensional arrays in a 1-dimensional and cutting back on object initializations.

But knowing how the algorithms work and how to tweak for performance alone didn’t do the trick. The difficulty lies in making it all work together and operating as a big unit, working its way to a victory. That’s where logic thinking came in, to determine what tactics to use, and which algorithms to use.

After having played with this an afternoon I managed to get 1325 points, which was enough to get to Round 2, and to achieve another internship goal. My personal next goal was to try to score as good as possible in the second round.

(Which I will talk about when the second rounds is on its way :p)
with no comments
Filed under: ,

A pathfinder has to be very fast, but when we take a look at the performance we notice that working with the open-list is the bottleneck.

There are several possible data structures to store the open-list. We could use an ArrayList to store the values and keep it sorted using an IComparable interface. With this solution we end up with too much overhead keeping the entire list sorted. After all, the only thing our pathfinder is interested in, is the node with the lowest F-score, it doesn’t care about the other nodes.

A better solution is using a binary heap. In a binary heap, each item has two children with a value higher or equal to itself. Which means in the end the lowest item is at the top of the heap, easily accessible.



One of the nice things of a binary heap is the fact that it can be stored in a 1-dimensional array, making sorting of the heap a very quick operation.

The top of the heap is always stored at index 1. We don’t use the 0-index when working with zero-based arrays.



The children of any given item are always stored at the item’s location * 2 and the item’s location * 2 + 1. For example, in the image given above, the item with value 20 is stored at index 3 and its two children can be found at index 6 (3 * 2) and index 7 (3 * 2 + 1).

Adding an item to a binary heap can be achieved by adding the new item at the end of the array and then letting the new item bubble its way up.

This is achieved by comparing the item with its parent, swapping them when the item is smaller then its parent and repeating this until the parent is smaller.

 

public void Add(Int32 fCost) {

  this.binaryHeap[this.numberOfItems] = fCost;

  

  Int32 bubbleIndex = this.numberOfItems;

  while (bubbleIndex != 1) {

    Int32 parentIndex = bubbleIndex / 2;

    if (this.binaryHeap[bubbleIndex] <= this.binaryHeap[parentIndex]) {

      Int32 tmpValue = this.binaryHeap[parentIndex];

      this.binaryHeap[parentIndex] = this.binaryHeap[bubbleIndex];

      this.binaryHeap[bubbleIndex] = tmpValue;

      bubbleIndex = parentIndex;

    } else {

      break;

    }

  }             

  this.numberOfItems++;

} /* Add */


To remove an item from a binary heap, we simply take the item at index 1. But now we have to repair our heap, because there is a gap at the top. To fix this we take the last item and place it at the top, after which we let it sink downwards. This is done by comparing the value with its two children, replacing it with the smallest child and repeating this until the parent is smaller than both children.

 

public BinaryHeapItem Remove() {

  this.numberOfItems--;

  Int32 returnItem = this.binaryHeap[1];

 

  this.binaryHeap[1] = this.binaryHeap[this.numberOfItems];

 

  Int32 swapItem = 1, parent = 1;

  do {

    parent = swapItem;

    if ((2 * parent + 1) <= this.numberOfItems) {

      // Both children exist

      if (this.binaryHeap[parent] >= this.binaryHeap[2 * parent]) {

        swapItem = 2 * parent;

      }

      if (this.binaryHeap[swapItem] >= this.binaryHeap[2 * parent + 1]) {

        swapItem = 2 * parent + 1;

      }

    } else if ((2 * parent) <= this.numberOfItems) {

      // Only one child exists

      if (this.binaryHeap[parent] >= this.binaryHeap[2 * parent]) {

        swapItem = 2 * parent;

      }

    }

    // One if the parent's children are smaller or equal, swap them

    if (parent != swapItem) {

      Int32 tmpIndex = this.binaryHeap[parent];

      this.binaryHeap[parent] = this.binaryHeap[swapItem];

      this.binaryHeap[swapItem] = tmpIndex;

    }

  } while (parent != swapItem);

  return returnItem;

} /* Remove */


A small comparison between an ArrayList and this binary heap implementation gives the following results:

Binary Heap: added 4000 items.

Time needed: 00:00:00

Lowest F-score: 1

Sorted ArrayList: added 4000 items.

Time needed: 00:00:07.2968750

Lowest F-score: 1

 

Binary Heap: added 10000 items.

Time needed: 00:00:00.0156250

Lowest F-score: 1

Sorted ArrayList: added 10000 items.

Time needed: 00:00:56.1250000

Lowest F-score: 1


Inspiration and some images used from Patrick Lester.
with 2 comment(s)
Filed under:
The A* algorithm works with two lists, an open-list and a closed-list. The open-list is the list of nodes to be checked, while the closed-list already has been checked. Each node also gets scored with F, G and H-scores.

 

·         F-score:   Total cost for a node (G-score + H-score).

·         G-score:   Movement cost.

·         H-score:   Estimated movement cost.

In my demonstration program I used pixels as nodes in a grid-based map. A rule the pathfinder had to obey was it could only move horizontally and vertically.

We start with a begin point and an endpoint, a map and we know which nodes are not passable.



The first step in A* is to add the start point to the closed list, and examine its neighbors.

We ignore it if it’s an obstacle or already on the closed list. When it’s not yet on the open-list, we add it to the open-list, and when it’s already on the list, we check of the G-score isn’t lower than the current G-score. If the score is lower, we change the parent of the node.



These steps are repeated until the goal-node is added to the open-list.

Thanks to the parent information of each node it is possible to reconstruct the shortest path from end to start.



The most important information for the algorithm is that it has to know the node with the lowest F-score, because this is most likely the one leading to the shortest path, and the one which will be added to the closed-list during the next iteration.

Because the pathfinder has to be fast, the data structure used to store these values has to be very fast as well. That’s why a binary heap is used in combination with A*.

(Other data structures can be used, but this solution proved to be the fastest on a 200 * 200 map)

with 4 comment(s)
Filed under:

The first task I got during my internship was to manage a meeting of the Microsoft Student Council. This was also the start of my internship, the real thing from the beginning.

The Microsoft Student Council is a Microsoft program focused towards students. Its goals are to support dedicated students who are willing to work with new technologies and are passionate about learning new things. Every student is able to join the council, without any costs. The only requirement consists out of the students coming to Microsoft, instead of Microsoft asking students to join. In other words, if you are motivated, you can be part of it.

The council organizes four meetings a year, each with a different theme. These students also get the opportunity to attend Microsoft seminars and to get involved in discussions with Microsoft developers. Nowadays there are about 100 students who are part of this council.

Besides organizing training and meetings, the Microsoft Student Council also tries to get students involved in various competitions and challenges, trying to spark the students’ interest for new things. This results in a good community-feeling among the involved students, learning each other new things.

On the 11th of February 2005 the second meeting took place, having Digital Entertainment as its theme. Due to an unexpected absence of the person organising it, I was assigned to manage this meeting during the day.

Practically this meant I had to provide the required information for everyone on the SharePoint site used by the council, provide a route description, act as a contact person for the speakers, welcome everyone on the meeting, close the meeting at the end and make sure all speakers follow their assigned speaking times.

I also was a speaker myself during this event. My talk was about Game Programming - AI in Games, in particular about the A* pathfinding algorithm and using a binary heap as data structure.

Pathfinding is very important in gaming, because it is used a lot it has to be as fast and efficient as possible. A good pathfinder can be used to calculate distances as well.

For navigation, the A* algorithm is used to find the shortest path.



Note to blog readers: Because I'm writing all of this in Word, I can't paste it into .Text without the layout getting screwed up, so I removed some table formatting and images. I do try to make readable though ;)
with 1 comment(s)
Filed under:
As some of you might now, I'll be doing my internship at Microsoft.

One of the things I'm supposed to do, is blog about my time there.

So, because of this, there is now an MS Internship category on my blog.

Ofcourse not everything I do will be posted, but I'm sure there will be enough :)

I'm really looking forward working there!
with 5 comment(s)
Filed under: ,
Allright, currently it's a very busy time, but some people asked for more info about the previous DevDays 2005, so here is my attempt :)

First of all, I haven't taken any pictures this time, because I had to give my bag away at the start, and the camera was in there.

The first presentation after Bill Gates' keynote was by Philippe Destoop about Closing The Gap Between Development And Operations: A Developer's Perspective.

The main problem lies withing a lack of communication between developers and operations. Depending on the size of a company Operations has either little power or unlimited power. In either case, not talking to Operations can lead to your company suffering loss when your application crashes, or when Ops have a lot of power, prevent your app from being deployed.

The solution to this is to work together with Ops during development and to make them like your app ;)

You do this by communication a lot and by implementing monitoring and control functionality into your app, to be used by Ops later on.

The good thing is, a lot of the code needed to do this already exists, in the form of the Enterprise Library. More particulary, the Logging and Instrumentation Application Block.

Using this block you can raise events and timed events to about anything you want. Making it possible for Ops to receive these events in their monitoring programs and do something with it.

You can view some examples of code in the presentation.

Next presentation was IT Fortress: Developing On A Secured Infrastructure by Raf Cox.

He talked about security, first examine what you want to protect and why, then choose a technology to protect it with, and don't be shy of using built-in technology of the OS, it's better then re-inventing it.

In a secure environment you have to be aware as a developer that your application isn't as "free" as it might be in your development environment. It can be run as a normal user, not fully trusted, with limited network access.

You always have to think about possible security bugs, if you don't, they will be there and hackers will know them.

After this he explained the possible authentication choices in Windows, how Basic Authentication, SSL and Kerberos works.

You can use Windows for authorization as well. By using the Authorization Manager it is possible to define common roles in your organisation with common used operations and define their permissions in the manager in a central place. After this applications all can use this information.

Last part of the presentation was about using least privilege. You can read all about it in the presentation.

Third presentation of the day was by Clemens Vasters about Interop & Integration: Best Practices For SOA With Today's Technologies.

During this presentation everything that has been shown is readily available, no future products were used, which is a nice thing for a presentation! :)

The presentation was based on a demonstration example to explain how service-oriented architecture works.

Basicly every functionality in the example is a service, when you take a look at the big overview it looks like a very modular system where each service has one well-defined task and works together with other services.

Some properties of these services are autonomy, where each service control and hide their state, services also are never hard linked to each other and are platform independant, so no returning DataSets.

Services also contain "edge code", which is code specifically written for the borders, and do nothing but forward to the real code that handles the logic, which are basic classes.

This was a very energy-rich session, with a lot of new information, which is still being processed by my brain :)

You can view all the diagrams in the presentation.

Next presentation was Best Practices For Windows Forms Development by Marc Ghys and Bart Debeuckelaere.

The first issue was to improve performance for Smart Clients. This can be done by using a lot of caching, compress the SOAP messages, and possibly use ngen.exe to precompile your assemblies. Also when you have to do something intensive, do it when the user expects it, for example, make a web-service call when a user clicks a submit button while showing a loading msg, and not when he leaves a textbox for example.

Next was how to secure webservices, by using the integrated authentication mechanisms in Windows and by using WSE.

Other things during this presentation were creating your own controls to provide a consistent look and feel in your application, using code generation to save time and to have consistent code. Then some info was given about ClickOnce, but the demo failed and then the time was up. But you can view the presentation for more info.

At the end of the day there was a community block left. These were the Lightning Talks where I talked about Alternate Data Streams. And these are the only photos I have of the day, taken by Tom Mertens, tnx!



This concludes day 1, tommorow I'll try to do the same for day 2, I also ran out of time now ;)
with 2 comment(s)
Filed under: ,
The Developer & IT Pro Days 2005 are over, as well are my exams.

During day 2 we saw what is going to come with the next .NET version (partial files, generics, ClickOnce, ...) and what mistakes an admin can make in his IT setup and how to fix them.

The last one was really funny, but sadly enough those mistakes are often made, running SQL Server as SYSTEM, SQL Injection, simple passwords, no defense in depth, logging on as domain admin, ...

My exams are also over now, the last one of my current education, coming up next is a 3-month internship at Microsoft.

And just like Tom's doing, here is a picture of the Channel 9 guy, sitting together with the Azlan mascotte on the tower of stuff I had to learn these last 3 weeks for my exams :)

More Posts « Previous page - Next page »