Jan 21
Ok, what does this expression do or mean? First of all: never write something like this in your code. Nobody understands the meaning with a single look and that will lead to confusion and maybe to a bug in your software someday.
Now let’s take a deeper look. First you may think about the difference between x++
and ++x
. If you write it as a single statement both expressions are equal, but if you use it as a part of a complex expression the first will evaluated to the value of x
before increasing it; the second one will evaluate to the new value of x
. So y = x++;
leads to a different result for y
as y = ++x;
.
x+=a
simply is a ‘shortcut’ for x=x+a
.
Now let’s do it step by step. For example x
is 5
. Then first x
will be increased by one to 6
but the old value will go into the formula that remains as x=x+5
. Since x
was increased before the result will be 11
.
If you think that is all right, than please take a break and test it with your favorite compiler. If you are a C or C++ guy you will in fact receive 11 as an answer and everything is fine. But if you are a C# or java guy x
will be 10
. Why?
.Net as well as the Java Runtime are stack machines. The expression will be put on the stack step by step before evaluating the whole thing. At that time x
is 5. x
will be changed to 6
by the x++
part, but that only happens in the main memory. The old value (5
) is still on the stack. After executing the whole expression the changed x
will be overwritten by 10
(5+5
).
And once again: NEVER write code like this!
Jan 13
I found this somewhere and I think it’s worth to write a short (only a very short) entry.
throw null;
If you use this expression in your C# code it will throw a NullReferenceException
. That is because the throw
-statement needs an object of type Exception
as its single parameter. But this very object is null
in my example.
I like this way to produce some exception while testing code.
Jan 05
It was very silent here in the past month. That was mainly because I was working on my diploma thesis until the end of September. After that I did my final exam and started working in Bonn. Now it is December and almost 2009. I’m sitting in a plane to Australia for holiday and have much time to write articles. I will try to keep this blog alive and will write articles more frequently.
Today I will introduce Flow. With Flow you can model the behavior of nodes in a wireless sensor network (WSN) in a data driven and event driven manor. I developed Flow as part of my diploma thesis.
Flow is build as a Visual Studio Addon (a VS Package) on top of the DSL-Tools containing three different domain specific languages to describe different parts of the software running on a sensor node. These different DSLs are working together and using most of the techniques I described earlier in this blog. E.g. my library JaDAL was initially build to support this diploma thesis.
You will find screenshots, more explanations and Flow itself on http://flow.irgendwie.net. While the webpage and the software are available in English the thesis itself is a pdf-document and can only be downloaded in a German version.
The software is fully working and if no wireless sensor network is available you can use a node simulator to evaluate Flow. The code is released under the new BSD license and also available for download.
Screenshots:
Dataflows modeled with Flow looks like that:
The simulated sensor nodes are represented as Windows forms programmed by such dataflows:
For more information just visit http://flow.irgendwie.net.
Recent Comments