2009-02-23 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Running Processing Code on the .NET Micro FrameworkWhile most of our current projects focus on .NET we also love Arduino - an electronics prototyping platform based on open-source hardware, an easy-to-learn programming language called Processing and a simple software development environment. Evolved from ideas explored in the Aesthetics and Computation Group at the MIT Media Lab, Processing defines a procedural subset of Java together with a lean but effective high-level library. Primarily designed to simplify visual computing on desktop machines, Processing and its philosophy could be successfully ported to the embedded world. Sites like Instructables, MAKEzine, Tinker.it! and Liquidware show the enormous momentum of the rapidly growing Arduino community. The technical reason that Processing is quite easy to support by hardware vendors like Arduino is the fact that it can be translated to C almost one-to-one. So, after thinking about this whole story, Marc came up today with an elegant way to run Processing on even more devices, namely all those supporting the .NET Micro Framework. As a proof of concept, here is a (partial) port of the Processing library and the original Hello World in Processing - or is it C#?
|
||||||||||||||||||||||||||||||||||||||||||||||
2009-02-06 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Implementing LINQ on the .NET Micro FrameworkThe .NET Micro Framework, a variant of .NET radically scaled down for embedded systems, does not include the Fortunately, the other relevant language features such as lambda expressions, extension methods and list comprehension can all be seen as syntactic sugar. Introduced with C# 3.0 - and due to the genius of Anders Hejlsberg - those features can be compiled to IL instructions already implemented by any CLI-compliant virtual machine. And, as Marc Frei and Cuno Pfister prove with the following code, the lack of generics barely affects the undeniable elegance of LINQ.
|
||||||||||||||||||||||||||||||||||||||||||||||
2008-10-14 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Avoiding C# EnumsWhile the designers of C# introduced them with good intentions, enums also add a surprising amount of complexity to the language. And some serious sources of errors. The C# Specification states that:
But in a system with more than one assembly, there is not necessarily a single time of compilation. As a result, modifying a public enum can break client assemblies. Consider the following example:
Running the program
Note that this approach is no less type-safe than an enum would be, as it is always possible to assign arbitrary values to an enum variable using a typecast. Even the self-documenting nature of enums can be preserved, with the following pattern:
Such an approach is slightly less concise than an enum, but it eliminates the class of errors described above. Those still unconvinced might want to read the plethora of caveats, dos and don'ts regarding enum design at Krzysztof Cwalina's blog. |
||||||||||||||||||||||||||||||||||||||||||||||
2008-10-13 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Changing C# ConstantsIf we expose a constant value in a public (or internal) class we use the modifiers
Given a system with more than one assembly, this means that values are inserted in place at compiletime of the client rather than looked up at run-time. Changing the constant thus has no effect on client assemblies until they are recompiled. Worse, without recompilation clients will not even notice that a
Running the program Besides deleting constants there are many other types of breaking changes in .NET, but there seems to be no specification as to what exactly is considered breaking and what is not. The closest thing to a complete list of breaking changes in .NET can be found at the .NET BCL Team Blog. |
||||||||||||||||||||||||||||||||||||||||||||||
2008-09-05 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Innovating Cave ExplorationExploring caves does not come to mind as the most high tech of activities. But Beat Heeb, our CTO and a passionate caver, is about to change this. On his mission to revolutionize the field of caving, he already engineered a software-based cave radio capable of transmitting short text messages out of a cave (!) as well as a sensor based on a PIC controller to count people squeezing through a tunnel. His current project is a paperless cave surveying system. A laser distance meter communicates over Bluetooth with a mobile device. There, the measured distances are rendered into a 3D model of the cave. Besides the cave surveying software written in C# on the .NET Compact Framework the main engineering task consisted of adding a 3D compass and Bluetooth to the distance meter, a relatively cheap, off-the-shelf Leica Disto A3. Striving for simplicity, Beat managed to create an add-on board that fits into the original housing and can be attached by soldering a mere four wires to the Disto. |
||||||||||||||||||||||||||||||||||||||||||||||
2008-01-31 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Inventing the FutureAlan Kay on predicting the future:
|
||||||||||||||||||||||||||||||||||||||||||||||
2007-11-26 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Implementing Oberon Modules in C#The C# language unfortunately does not provide a module feature. Nevertheless, the access modifier Module members that are marked as exported in Oberon become Here's an example of a module
The same module could be implemented in C# as follows
Now look at the interface definition generated out of the compiled Component Pascal module
And the public interface of the compiled C# code as generated by Lutz Röder's Reflector
To sum things up: Implementing modules is possible and quite easy thanks to Anders Hejlsberg who - familiar with units, Delphi's module feature - presumably sneaked the |
||||||||||||||||||||||||||||||||||||||||||||||
2007-11-21 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Knowing Oberon ModulesBefore we switched to C#, we used our own programming language Component Pascal, a dialect of Niklaus Wirth’s Oberon. Published in 1988, Oberon’s feature set is similar to those of the early Java and C# versions, with an important exception. The module concept which Wirth officially introduced with Modula-2 and later refined in Oberon to provide language support for modularization. The Component Pascal language report states that
A module also defines a scope of visibility for it's members. To be accessible outside of a module, a member must be marked as exported. To access the exported members of another module, a client module must refer to the other module as imported. Mutual imports of modules are not allowed. As modules are the only unit of compilation, every valid program is structured into one or more modules with clearly stated dependencies. |
||||||||||||||||||||||||||||||||||||||||||||||
2007-11-15 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Decomposing Systems Into ModulesIn his classic paper On the Criteria To Be Used in Decomposing Systems into Modules the software engineering pioneer David Parnas introduces modularization as
He identifies information hiding as the key criterion for a successful decomposition. Individual design desicions are confined to a single module each. The interface or definition of a module should reveal as little as possible about its inner workings, thereby minimizing dependencies and facilitating change. Since 1972 when the paper was published, a lot of fancy software development methodologies have been coming and going. Nevertheless, we are convinced that modularization as described by Parnas is still the most important engineering skill to learn and master in order to develop good software. |
||||||||||||||||||||||||||||||||||||||||||||||
2007-10-30 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Understanding C# Access ModifiersInformation hiding is essential in object oriented as well as in modular programming. C# provides the access modifiers
*) Because members of The individual access modifiers are defined in the C# Language Specification as
Note: the term this program can be replaced by the containing assembly. |
||||||||||||||||||||||||||||||||||||||||||||||
2007-10-17 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Compiling C# Without Visual StudioUsing a state of the art software development environment might boost your productivity - at least if it’s measured in lines of code. However, to understand what is going on behind the scenes using the command line C# compiler csc may be the better choice. Consider this example resulting in a library A.dll and a client program B.exe that references it.
To compile, save the above .cs files and run the following batch file.
Note the /checked compiler option, which should be the default but unfortunately is not. |
||||||||||||||||||||||||||||||||||||||||||||||
2007-10-16 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Learning .NETTo get a good overview over the .NET library, download Lutz Röder’s Reflector. We use it daily to browse assemblies (e.g. mscorlib.dll in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\) with the visibility setting View > Options > Browser > Visibility set to Public Items only. The few namespaces worth becoming familiar with at first are |
||||||||||||||||||||||||||||||||||||||||||||||
2007-10-15 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Learning C#Recently Mete, a longtime friend and hardcore C++ coder, asked which book he should consider to learn the C# programming language. Having piles of C# related books on my shelf the only one I use regularly is the excellent book C# to the Point by Hanspeter Mössenböck. On a mere 200 pages he explains C# in astonishing depth, focusing on underlying concepts and concise examples rather than hand waving and Visual Studio screenshots. For additional information on specific language features, check the C# language specification ECMA-334. |
||||||||||||||||||||||||||||||||||||||||||||||
2007-10-10 by tamberg
|
||||||||||||||||||||||||||||||||||||||||||||||
Iterating Array Elements BackwardsTo illustrate the sort of nit-picking we spend our energy on, consider this example from back in the days when we programmed in Component Pascal and Given an array
A straight forward approach to iterate through it would be
Preventing multiple calls to the property method
If there's no fixed processing order we can further eliminate a variable
And finally, reordering the decrement we can get rid of the ugly
The latter two examples use the variable name |
||||||||||||||||||||||||||||||||||||||||||||||
About | Contact | RSS |