Daniel Hoelbling-Inzko talks about programming

Computer Programming Quotes

Oh god, I am still laughing after having read this brilliant list of 101 Great Computer Programming Quotes I found on DotNetKicks.

Here are some of my favorites, although I would recommend the whole list to anyone with some spare time!

  1. “Saying that Java is nice because it works on all OSes is like saying that anal sex is nice because it works on all genders.”
  2. “Computers are like bikinis. They save people a lot of guesswork.”
    (Sam Ewing)
  3. “Programming is like sex: one mistake and you’re providing support for a lifetime.”
    (Michael Sinz)
  4. “Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots.  So far the Universe is winning.”
    (Rich Cook)
  5. “It’s ridiculous to live 100 years and only be able to remember 30 million bytes.  You know, less than a compact disc.  The human condition is really becoming more obsolete every minute.”
    (Marvin Minsky)
  6. “Hardware: The parts of a computer system that can be kicked.”
    (Jeff Pesis)
  7. “I’ve finally learned what ‘upward compatible’ means.  It means we get to keep all our old mistakes.”
    (Dennie van Tassel)
  8. “There are two major products that come out of Berkeley: LSD and UNIX.  We don’t believe this to be a coincidence.”
    (Jeremy S. Anderson)
  9. “There are two ways of constructing a software design.  One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”
    (C.A.R. Hoare)
  10. “Software suppliers are trying to make their software packages more ‘user-friendly’…  Their best approach so far has been to take all the old brochures and stamp the words ‘user-friendly’ on the cover.”
    (Bill Gates)
  11. “There’s an old story about the person who wished his computer were as easy to use as his telephone.  That wish has come true, since I no longer know how to use my telephone.”
    (Bjarne Stroustrup)
  12. “The use of COBOL cripples the mind; its teaching should therefore be regarded as a criminal offense.”
    (E.W. Dijkstra)
  13. “There is no programming language–no matter how structured–that will prevent programmers from making bad programs.”
    (Larry Flon)

Enumerators in C#

I am still trying to figure out if what I did was useful or not.

Based on the assumption that sometimes you may need a variable typed IEnumerable<T> to hold a value that only implements IEnumerable I wrote this adapter class (you find it after the jump).

What's IEnumerator?
IEnumerator it the old non-generic implementation of the Iterator pattern, while IEnumerator<T> is the strongly-typed generic version introduced in .NET 2.0.

IEnumerable<T> implements IEnumerable, but there is no way to cast IEnumerable to IEnumerable<T>. So I wondered how you could comply to the Iterator pattern.

My first suspicion came when I tried foreach on both IEnumerables. Foreach has no problem with both of them, so I dug out my C# language spec and discovered that foreach has to use two different methods for either IEnumerable or IEnumerable<T> (That's not really clear there, anyone to falsify my assumption?).
They could have gone the other way and use the non-generic IEnumerable for the iteration, but that would need an implicit typecast on every iteration (and that would slow things down I guess).

In a scenario like the following one you can't pass the Enumerator created by an Array.GetEnumerator() because it uses IEnumerator instead of the generic version IEnumerator<T>.

public void PrintList(IEnumerable<String> MyList)
foreach (String Entryin MyList)
Console.WriteLine("{0}", Entry);

Because IEnumerable<T> implements IEnumerable you could just switch back to the non-generic version, but that's something I don't really like (although it may be more practical).

So here are 2 (very simple) adapter classes that will provide upward-compatibility to your IEnumerable and IEnumerator needs:

public class GenericEnumerableAdapter<T> : IEnumerable<T>
    private IEnumerable _Old;
    public GenericEnumerableAdapter(IEnumerable OldEnumerable)
        this._Old = OldEnumerable;

#region IEnumerable<T> Members

public IEnumerator<T> GetEnumerator() { return new GenericEnumeratorAdapter<T>(_Old.GetEnumerator()); }


#region IEnumerable Members

IEnumerator IEnumerable.GetEnumerator() { return _Old.GetEnumerator(); }

#endregion }

public class GenericEnumeratorAdapter<T> : IEnumerator<T> { private IEnumerator _OldEnum; public GenericEnumeratorAdapter(IEnumerator OldEnumerator) { _OldEnum = OldEnumerator; }

#region IDisposable Members

public void Dispose() { this._OldEnum = null; }


#region IEnumerator<T> Members

public T Current { get { return (T)_OldEnum.Current; } }

object IEnumerator.Current { get { return _OldEnum.Current; } }

public bool MoveNext() { return _OldEnum.MoveNext(); }

public void Reset() { _OldEnum.Reset(); }

#endregion }

My Photography business


dynamic css for .NET