<?xml version="1.0" encoding="UTF-8"?><feed xml:lang="en-us" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:auto-ns1="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2005/Atom"><author><name>tamberg</name></author><id>http://blogs.oberon.ch/tamberg/</id><link rel="self" href="http://blogs.oberon.ch/tamberg/atom.xml" /><link rel="alternate" type="text/html" href="http://blogs.oberon.ch/tamberg/" /><title>Mobile Software Engineering</title><updated>2009-02-23T00:00:00Z</updated><entry><id>http://blogs.oberon.ch/tamberg/2009-02-23/running-processing-code-on-the-dotnet-mf.html</id><published>2009-02-23T00:00:00Z</published><updated>2009-02-23T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2009-02-23/running-processing-code-on-the-dotnet-mf.html" /><title>Running Processing Code on the .NET Micro Framework</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>While most of our current projects focus on .NET we also love <a href="http://www.arduino.cc/">Arduino</a> - an electronics prototyping platform based on open-source hardware, an easy-to-learn programming language called <a href="http://www.processing.org/">Processing</a> and a simple software development environment. Evolved from ideas explored in the Aesthetics and Computation Group at the <a href="http://www.media.mit.edu/">MIT Media Lab</a>, 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.</p><p>Sites like <a href="http://www.instructables.com/">Instructables</a>, <a href="http://www.makezine.com/">MAKEzine</a>, <a href="http://tinker.it/">Tinker.it!</a> and <a href="http://www.liquidware.org/">Liquidware</a> 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 <a href="http://arduino.cc/en/Tutorial/Blink">Hello World</a> in Processing - or is it C#?</p><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2009-02-23/Processing.cs">Processing.cs</a>

using System.Threading;
using Microsoft.SPOT.Hardware;

partial class Processing {
  const bool HIGH = true, LOW = false;
  const int OUTPUT = 0;

  object[] pins = new object[128];

  void delay (int ms) {
    Thread.Sleep(ms);
  }

  void digitalWrite (int pin, bool value) {
    (pins[pin] as OutputPort).Write(value);
  }

  void pinMode (int pin, int mode) {
    pins[pin] = new OutputPort((Cpu.Pin) pin, false);
  }

  static void Main () {
    Processing p = new Processing();
    p.setup();
    while (true) {
      p.loop();
    }
  }
}</code></pre></blockquote><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2009-02-23/Program.cs">Program.cs</a>

partial class Processing {
  int ledPin = 13;

  void setup () {
    pinMode(ledPin, OUTPUT);
  }

  void loop () {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }
}</code></pre></blockquote></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2009-02-06/implementing-linq-on-the-dotnet-mf.html</id><published>2009-02-06T00:00:00Z</published><updated>2009-02-06T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2009-02-06/implementing-linq-on-the-dotnet-mf.html" /><title>Implementing LINQ on the .NET Micro Framework</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>The <a href="http://www.microsoft.com/netmf">.NET Micro Framework</a>, a variant of .NET radically scaled down for embedded systems, does not include the <code><a href="http://msdn.microsoft.com/en-us/library/system.linq.aspx">System.Linq</a></code> namespace and does not provide any <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx">LINQ</a> functionality. Because its implementation is based on generics, LINQ requires version 2.0 of the CLR. The Micro Framework on the other hand is restricted to the <a href="http://en.wikipedia.org/wiki/Common_Language_Infrastructure">CLI</a>, a standardized specification of Microsoft's CLR 1.0.</p><p>Fortunately, the other relevant language features such as <a href="http://www.google.com/search?q=lambda+expressions">lambda expressions</a>, <a href="http://www.google.com/search?q=extension+methods">extension methods</a> and <a href="http://en.wikipedia.org/wiki/List_comprehension">list comprehension</a> 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.</p><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2009-02-06/Linq.cs">Linq.cs</a>

using System.Collections;
using Microsoft.SPOT;

namespace System.Runtime.CompilerServices {
  [AttributeUsageAttribute(
    AttributeTargets.Assembly
    | AttributeTargets.Class
    | AttributeTargets.Method)]
  sealed class ExtensionAttribute: Attribute {}
}

delegate bool Predicate (object o);

sealed class Enumerator: IEnumerator {
  IEnumerator e;
  Predicate p;

  internal Enumerator (IEnumerator e, Predicate p) {
    this.e = e;
    this.p = p;
  }

  object IEnumerator.Current {
    get { return e.Current; }
  }

  void IEnumerator.Reset () {
    e.Reset();
  }

  bool IEnumerator.MoveNext () {
    var b = e.MoveNext();
    while (b &amp;&amp; !p(e.Current)) {
      b = e.MoveNext();
    }
    return b;
  }
}

sealed class Filter: IEnumerable {
  IEnumerable e;
  Predicate p;

  internal Filter (IEnumerable e, Predicate p) {
    this.e = e;
    this.p = p;
  }

  IEnumerator IEnumerable.GetEnumerator () {
    return new Enumerator(e.GetEnumerator(), p);
  }
}

static class Program {
  static int Count (this IEnumerable e) {
    var n = 0;
    foreach (var o in e) {
      n++;
    }
    return n;
  }

  static IEnumerable Where (this IEnumerable e, Predicate p) {
    return new Filter(e, p);
  }

  static void Main () {
    var a = new int[] {1, 2, 3, 4, 6, 8, 9, 9, 9};
    var n = a.Where(v =&gt; (int) v % 2 == 0).Count();
    var m = (from v in a where (int) v % 2 == 0 select v).Count();
    Debug.Print(n + " " + m);
  }
}</code></pre></blockquote></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2008-10-14/avoiding-csharp-enums.html</id><published>2008-10-14T00:00:00Z</published><updated>2008-10-14T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2008-10-14/avoiding-csharp-enums.html" /><title>Avoiding C# Enums</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>While 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 <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf">C# Specification</a> states that:</p><blockquote><p><i>An <code>enum</code> type declaration defines a type name for a related group of symbolic constants. [...] a runtime decision is made from a fixed number of choices that are known at compile-time.[...] The use of enums makes the code more readable and self-documenting.</i></p></blockquote><p>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:</p><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2008-10-14/E.cs">E.cs</a>

public enum E {A, B, C}

// <a href="http://blogs.oberon.ch/tamberg/2008-10-14/P.cs">P.cs</a>

using System;

class Program {
  static void Main () {
    Console.WriteLine(E.A);
  }
}</code></pre></blockquote><p>Running the program <code>P.exe</code> outputs the string <i>A</i>. After changing <code>E.cs</code> to <code>public enum E {B, C}</code> the output of the same program is now <i>B</i>. The error remains hidden until <code>P.cs</code> is recompiled. Hence, we use a sealed class with a private constructor and <code>static readonly</code> (not <code>const</code>) values instead:</p><blockquote><pre><code>public sealed class E {
  E () {}
  public static readonly int A = 0, B = 1, C = 2;
}</code></pre></blockquote><p>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:</p><blockquote><pre><code>public sealed class E {
  E () {}
  public static readonly E A = new E(), B = new E(), C = new E();
}</code></pre></blockquote><p>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 <a href="http://blogs.msdn.com/kcwalina/archive/2004/05/18/134208.aspx">enum design</a> at Krzysztof Cwalina's blog.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2008-10-13/changing-csharp-constants.html</id><published>2008-10-13T00:00:00Z</published><updated>2008-10-13T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2008-10-13/changing-csharp-constants.html" /><title>Changing C# Constants</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>If we expose a constant value in a public (or internal) class we use the modifiers <code>static readonly</code> instead of <code>const</code>, to be able to change the value in the future. The <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf">C# Specification</a> states that:</p><blockquote><p><i>A constant is a class member that represents a constant value: a value that can be computed at compile-time. [...] constants are considered static members</i></p></blockquote><p>Given a system with more than one assembly, this means that values are inserted in place at compile­time of the client rather than looked up at run-time. <a href="http://en.wikiquote.org/wiki/Heraclitus">Changing the constant</a> thus has no effect on client assemblies until they are recompiled. Worse, without recompilation clients will not even notice that a <code>const</code> member has been entirely removed. Consider the following example:</p><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2008-10-14/C.cs">C.cs</a>
		
public class C {
  public const int c = 7;
}

// <a href="http://blogs.oberon.ch/tamberg/2008-10-13/P.cs">P.cs</a>

using System;

class Program {
  static void Main () {
    Console.WriteLine(C.c);
  }
}</code></pre></blockquote><p>Running the program <code>P.exe</code> outputs the string <i>7</i>. After deleting <code>public const int c = 7;</code> from <code>C.cs</code> the output is still <i>7</i>. Replacing <code>const</code> with <code>static readonly</code> in the above example leads to a <code>System.MissingFieldException</code> as soon as the client tries to access the deleted variable. Note, that such an exception is a good thing because the client code is already broken anyway.</p><p>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 <a href="http://blogs.msdn.com/bclteam/archive/2006/05/08/592547.aspx">breaking changes in .NET</a> can be found at the .NET BCL Team Blog.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2008-09-05/innovating-cave-exploration.html</id><published>2008-09-05T00:00:00Z</published><updated>2008-09-05T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2008-09-05/innovating-cave-exploration.html" /><title>Innovating Cave Exploration</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Exploring 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 <a href="http://hidden-earth.org.uk/rules.creg.html">cave radio</a> 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.</p><p>His current project is a <a href="http://paperless.bheeb.ch/">paperless cave surveying</a> 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 <a href="http://www.leica-geosystems.com/corporate/en/ndef/lgs_67942.htm">Leica Disto A3</a>. 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.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2008-01-31/inventing-the-future.html</id><published>2008-01-31T00:00:00Z</published><updated>2008-01-31T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2008-01-31/inventing-the-future.html" /><title>Inventing the Future</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Alan Kay on <a href="http://www.ecotopia.com/webpress/futures.htm">predicting the future</a>:</p><blockquote><p><i>[...] the best way to predict the future is to invent it.</i></p></blockquote><p><img src="http://blogs.oberon.ch/tamberg/2008-01-31/dynabookindle.jpg" border="none" /><br clear="all" />Dynabook (1968), Kindle (2007)</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-11-26/implementing-oberon-modules-in-csharp.html</id><published>2007-11-26T00:00:00Z</published><updated>2007-11-26T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-11-26/implementing-oberon-modules-in-csharp.html" /><title>Implementing Oberon Modules in C#</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>The C# language unfortunately does not provide a module feature. Nevertheless, the access modifier <code>internal</code> makes implementing <a href="http://blogs.oberon.ch/tamberg/2007-11-21/knowing-oberon-modules.html">Oberon-style module semantics</a> quite straightforward. On the binary level an Oberon module comes very close to a .NET assembly. In code, the C# modifier <code>internal</code> limits member accessibility to a single assembly, so we can use it to designate module wide visibility.</p><p>Module members that are marked as exported in Oberon become <code>public</code> in C#. Further, for better readability the <code>MODULE</code> keyword can be emulated with a C# <code>namespace</code> keyword - as long as every assembly is assigned one unique namespace. To import another module, <a href="http://blogs.oberon.ch/tamberg/2007-10-17/compiling-csharp-without-visual-studio.html">reference its assembly</a> and insert a <code>using</code> statement for the corresponding namespace.</p><p>Here's an example of a module <code>M</code> in Component Pascal. Note that comments are also in Component Pascal syntax. All procedure and method bodies are empty for the sake of brevity.</p><blockquote><pre><code><i>(* <a href="http://blogs.oberon.ch/tamberg/2007-11-26/M.odc.txt">M.odc</a> *)</i>

MODULE M;

  IMPORT Q; <i>(* imported module *)</i>

  TYPE
    <b>T</b>* = POINTER TO RECORD END; <i>(* exported class *)</i>
    U = POINTER TO RECORD END;

  VAR
    <b>i</b>*: INTEGER; <i>(* exported module variable *)</i>
    j: INTEGER;

  PROCEDURE (t: T) <b>A</b>*, NEW; BEGIN END A; <i>(* exported method *)</i>
  PROCEDURE (t: T) B, NEW; BEGIN END B;

  PROCEDURE <b>F</b>* BEGIN END F; <i>(* exported procedure *)</i>
  PROCEDURE G BEGIN END G;

BEGIN
  <i>(* module initialization ... *)</i>
END M.</code></pre></blockquote><p>The same module could be implemented in C# as follows</p><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2007-11-26/M.cs">M.cs</a>

namespace M {

  using Q; // imported module

  public sealed class T { // exported class
    public void A () {} // exported method
    internal void B () {}
  }
  
  sealed class U {} // internal <a href="http://blogs.oberon.ch/tamberg/2007-10-30/understanding-csharp-access-modifiers.html">by default</a>

  public sealed class M {
    M () {} // private by default
    public static int i; // exported module variable
    internal static int j;
    public static void F () {} // exported procedure
    internal static void G () {}
    static M () {
      // module initialization ...
    }
  }

}</code></pre></blockquote><p>Now look at the interface definition generated out of the compiled Component Pascal module</p><blockquote><pre><code>DEFINITION M;

  TYPE
    T = POINTER TO RECORD 
      (t: T) A, NEW
    END;

  VAR
    i: INTEGER;

  PROCEDURE F;

END M.</code></pre></blockquote><p>And the public interface of the compiled C# code as generated by Lutz Röder's <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a></p><blockquote><pre><code>namespace M {

  public sealed class T {
    public T ();
    public void A ();
  }

  public sealed class M {
    public static int i;
    public static void F ();
  }

}</code></pre></blockquote><p>To sum things up: Implementing modules is possible and quite easy thanks to <a href="http://www.google.com/search?q=anders+hejlsberg">Anders Hejlsberg</a> who - familiar with <i>units</i>, Delphi's module feature - presumably sneaked the <code>internal</code> modifier into C#.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-11-21/knowing-oberon-modules.html</id><published>2007-11-21T00:00:00Z</published><updated>2007-11-21T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-11-21/knowing-oberon-modules.html" /><title>Knowing Oberon Modules</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Before we switched to C#, we used our own programming language <a href="http://en.wikipedia.org/wiki/Component_Pascal">Component Pascal</a>, a dialect of Niklaus Wirth’s <a href="http://en.wikipedia.org/wiki/Oberon-1">Oberon</a>. 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 <a href="http://en.wikipedia.org/wiki/Modula-2">Modula-2</a> and later refined in Oberon to provide language support for <a href="http://blogs.oberon.ch/tamberg/2007-11-15/decomposing-systems-into-modules.html">modularization</a>.</p><p>The Component Pascal <a href="http://www.oberon.ch/pdf/CP-Lang.pdf">language report</a> states that</p><blockquote><p><i>A module is a collection of declarations of constants, types, variables, and procedures, together with a sequence of statements for the purpose of assigning initial values to the variables. A module constitutes a text that is compilable as a unit.[…]</i></p></blockquote><p>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 <i>exported</i>. To access the exported members of another module, a client module must refer to the other module as <i>imported</i>. 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.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-11-15/decomposing-systems-into-modules.html</id><published>2007-11-15T00:00:00Z</published><updated>2007-11-15T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-11-15/decomposing-systems-into-modules.html" /><title>Decomposing Systems Into Modules</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>In his classic paper <a href="http://www.google.com/search?q=parnas+decomposing+systems+into+modules+pdf">On the Criteria To Be Used in Decomposing Systems into Modules</a> the software engineering pioneer David Parnas introduces modularization as</p><blockquote><p><i>a mechanism for improving the flexibility and comprehensibility of a system while allowing the shortening of its development time.</i></p></blockquote><p>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.</p><p>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.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-10-30/understanding-csharp-access-modifiers.html</id><published>2007-10-30T00:00:00Z</published><updated>2007-10-30T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-10-30/understanding-csharp-access-modifiers.html" /><title>Understanding C# Access Modifiers</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Information hiding is essential in object oriented as well as in modular programming. C# provides the access modifiers <code>private</code>, <code>internal</code>, <code>public</code>, <code>protected</code> and <code>protected internal</code> to give a programmer fine grained control over the visibility of a member in a specific context. Those contexts are <code>namespace</code>, <code>class</code>, <code>struct</code>, <code>interface</code> and <code>enum</code>. A member would be e.g. a field, an event, a delegate, property or method. But, as Marc's table shows, this does not really matter. A member's context alone determines if a modifier can be applied at all (□), and which modifier is the default (■).</p><blockquote><p><table border="" width=""><tr><td width="16%"></td><td width="16%"><code>namespace</code></td><td width="16%"><code>class</code></td><td width="16%"><code>struct</code></td><td width="16%"><code>interface</code></td><td width="16%"><code>enum</code></td></tr><tr><td width="16%"><code>private</code></td><td width="16%"></td><td width="16%">■</td><td width="16%">■</td><td width="16%"></td><td width="16%"></td></tr><tr><td width="16%"><code>internal</code></td><td width="16%">■</td><td width="16%">□</td><td width="16%">□</td><td width="16%"></td><td width="16%"></td></tr><tr><td width="16%"><code>public</code></td><td width="16%">□</td><td width="16%">□</td><td width="16%">□</td><td width="16%">■*</td><td width="16%">■*</td></tr><tr><td width="16%"><code>protected</code></td><td width="16%"></td><td width="16%">□</td><td width="16%"></td><td width="16%"></td><td width="16%"></td></tr><tr><td width="16%"><code>protected internal</code></td><td width="16%"></td><td width="16%">□</td><td width="16%"></td><td width="16%"></td><td width="16%"></td></tr></table></p></blockquote><p>*) Because members of <code>interface</code> and <code>enum</code> are always <code>public</code> by default, the modifier must not be applied in those contexts.</p><p>The individual access modifiers are defined in the <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf">C# Language Specification</a> as</p><blockquote><p><table border="" width="60%"><tr><td width="25%"><code>private</code></td><td width="">Access limited to the containing type</td></tr><tr><td width="25%"><code>internal</code></td><td width="">Access limited to this program</td></tr><tr><td width="25%"><code>public</code></td><td width="">Access not limited</td></tr><tr><td width="25%"><code>protected</code></td><td width="">Access limited to the containing class or types derived from the containing class</td></tr><tr><td width="25%"><code>protected internal</code></td><td width="">Access limited to this program or types derived from the containing class</td></tr></table></p></blockquote><p>Note: the term <i>this program</i> can be replaced by <i>the containing assembly</i>.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-10-17/compiling-csharp-without-visual-studio.html</id><published>2007-10-17T00:00:00Z</published><updated>2007-10-17T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-10-17/compiling-csharp-without-visual-studio.html" /><title>Compiling C# Without Visual Studio</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Using 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 <i>csc</i> may be the better choice. Consider this example resulting in a library <i>A.dll</i> and a client program <i>B.exe</i> that references it.</p><blockquote><pre><code>// <a href="http://blogs.oberon.ch/tamberg/2007-10-17/A.cs">A.cs</a>

using System;

public sealed class A {
    
  A () {}

  public static void P () {
    Console.WriteLine("A.P");
  }

}

// <a href="http://blogs.oberon.ch/tamberg/2007-10-17/B.cs">B.cs</a>

using System;

sealed class B {

  B () {}

  static void Main () {
    Console.WriteLine("B.Main");
    A.P();
    Console.ReadLine();
  }

}
</code></pre></blockquote><p>To compile, save the above <i>.cs</i> files and run the following batch file.</p><blockquote><pre><code>REM <a href="http://blogs.oberon.ch/tamberg/2007-10-17/make.bat">make.bat</a>

PATH C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\
csc /checked /t:library A.cs
csc /checked /t:exe B.cs /r:A.dll
PAUSE
</code></pre></blockquote><p>Note the <i>/checked</i> compiler option, which should be the default but unfortunately is not.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-10-16/learning-dotnet.html</id><published>2007-10-16T00:00:00Z</published><updated>2007-10-16T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-10-16/learning-dotnet.html" /><title>Learning .NET</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>To get a good overview over the .NET library, download Lutz Röder’s <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a>. We use it daily to browse assemblies (e.g. <i>mscorlib.dll</i> in <i>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\</i>) with the visibility setting <i>View &gt; Options &gt; Browser &gt; Visibility</i> set to <i>Public Items only</i>. The few namespaces worth becoming familiar with at first are <code>System</code>, <code>System.Collections</code>, <code>System.IO</code>, <code>System.Drawing</code> and the <code>System.Windows.Forms</code> namespace. <a href="http://www.amazon.com/exec/obidos/ASIN/0321246756/">Framework Design Guidelines</a>, a book by Krzysztof Cwalina and Brad Abrams from Microsoft, provides further insight into the main design decisions behind the .NET library. And finally there is the very Google friendly MSDN online documentation. Just enter a particular type or method name and feel lucky (e.g. <a href="http://www.google.com/search?q=IEnumerable">IEnumerable</a>).</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-10-15/learning-csharp.html</id><published>2007-10-15T00:00:00Z</published><updated>2007-10-15T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-10-15/learning-csharp.html" /><title>Learning C#</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Recently <a href="http://en.wikipedia.org/wiki/MilkShape_3D">Mete</a>, 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 <a href="http://dotnet.jku.at/csbook">C# to the Point</a> 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 <a href="http://www.ecma-international.org/publications/standards/Ecma-334.htm">ECMA-334</a>.</p></div></content></entry><entry><id>http://blogs.oberon.ch/tamberg/2007-10-10/iterating-array-elements-backwards.html</id><published>2007-10-10T00:00:00Z</published><updated>2007-10-10T00:00:00Z</updated><link href="http://blogs.oberon.ch/tamberg/2007-10-10/iterating-array-elements-backwards.html" /><title>Iterating Array Elements Backwards</title><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>To illustrate the sort of nit-picking we spend our energy on, consider this example from back in the days when we programmed in <a href="http://en.wikipedia.org/wiki/Component_Pascal">Component Pascal</a> and <code>foreach</code> was not an option (example in C#).</p><p>Given an array</p><blockquote><pre><code>object[] a;</code></pre></blockquote><p>A straight forward approach to iterate through it would be</p><blockquote><pre><code>int i = 0;
while (i &lt; a.Length) {
  Process(a[i]);
  i++;
}
</code></pre></blockquote><p>Preventing multiple calls to the property method <code>a.Length</code> leads to</p><blockquote><pre><code>int i = 0;
int n = a.Length;
while (i &lt; n) {
  Process(a[i]);
  i++;
}
</code></pre></blockquote><p>If there's no fixed processing order we can further eliminate a variable</p><blockquote><pre><code>int n = a.Length - 1;
while (n &gt;= 0) {
  Process(a[n]);
  n--;
}
</code></pre></blockquote><p>And finally, reordering the decrement we can get rid of the ugly <code>-1</code> and <code>&gt;=</code></p><blockquote><pre><code>int n = a.Length;
while (n &gt; 0) {
  n--;
  Process(a[n]);
}
</code></pre></blockquote><p>The latter two examples use the variable name <code>n</code> rather than <code>i</code> to emphasize the iteration direction.</p></div></content></entry></feed>