April 10, 2004
spout
I’m Loving the .NET Fx ARM
Saturday, April 10, 2004
I enjoyed the annotations in
The .NET Framework Standard Library Annotated Reference so much that I read
them all in one sitting (in the bathtub, if you must know…). The annotations
are where the authors put in their 2 cents about a particular class, method or
property and it was very interesting. Here’s what I learned just from that part
of the book:
- You shouldn’t use ApplicationException for custom
exceptions. Derive from Exception instead.
- Because
ICloneable.Clone doesn’t define whether it returns a deep or a shallow copy,
it’s practically worthless.
- Prefer UTF-8 because it takes
up the same amount of space to represent ASCII characters as ASCII, but can
also represent all Unicode characters (I knew that UTF-8 took up the same
amount of space but hadn’t yet jumped to “prefer”).
- I was
reminded of the System.Convert class, which does all of the same conversions
that the various type-specific ToXxx and Parse methods do, but puts them all
in one place.
- There’s another use for the private
interface method implementation syntax in C#:
class Enum : IEnumerator {
object IEnumerator.Current { get { return this.foo; } }
...
}
This syntax hides an interface method from general use unless you
cast to the interface base class:
Enum enum = new Enum();
object obj1 = enum.Current(); // compile-time error
object obj2 = (IEnumerator)enum.Current(); // this works
The thing I never thought of that this enables is that it lets you override
based on return type, which isn’t normally allowed in C#:class Enum : IEnumerator {
object IEnumerator.Current { get { return this.foo; }
Foo Current { get { return this.foo; } }
...
}
This private method implementation syntax lets you return the
generic type as part of the interface implementation so that you can plug
into standard idioms, e.g. foreach, but a more specific type for users of
the type directly, saving the cast:
Enum enum2 = new Enum();
Foo foo1 = (Foo)((IEnumerator)enum.Current());
Foo foo2 = enum.Current(); // no cast required
This will be less interesting as generics take over, but still, it’s a
useful trick.
- DateTime is always assumed to represent
local time, so if you convert to Universal time twice, you’ll change the
value each time.
- Since it’s possible to cast any number to
an enum value, e.g. TrueFalseEnum tfe = (TrueFalseEnum)42, make sure to
always check that an enum is a legal value. Theoretically this is a pain,
but in practice, I tend to check enum values with switch statements, making
the default case the error case, so it’s good to know that my code does the
right thing.
- The Threading.Interlocked class.
-
Jim Miller has way more birthdays than we do. : )
-
Jeff Richter agrees with me that the ThreadStart delegate needs an object
parameter.
- I should be using CompareInfo instead of
ToLower for case-insensitive comparisons (although they don’t show how):
using System.Globalization;
using System.Threading;
...
CompareInfo compare = Thread.CurrentThread.CurrentCulture.CompareInfo;
if( compare.Compare("foo", "FOO", CompareOptions.IgnoreCase) == 0 ) {
Console.WriteLine("the same");
}
If I can get that much out of just the annotations, imagine
what I could learn if I
read the whole thing. : )
Discuss
April 6, 2004
spout
Filling In Missing Computer Science Knowledge
Tuesday, April 6, 2004
Sometimes I get emails from folks
that don’t have a formal computer science knowledge and want the benefits of one
w/o actually going back to college. Since I was disappointed in my own formal
education (despite going on to “better” my BS in Computer Science with an MS), I
can understand this desire.
My first thought was
the MIT Open Courseware, which has a full course of computer science
curriculum. However, while the course material is all there, unless there are
officially sanctioned forums for each course, there’s really no place to ask
questions even of fellow students.
After thinking on it for a
while, I thought I’d go right to my favorite source.
Prof. Joe Hummel is a professor of computer science at Lake Forest College
in Illinois and has spent a lot of time thinking about how to fill in missing CS
knowledge in professional programmers (VB programmers, mostly) at DevelopMentor.
Here’s what he said:
For starters, I’d recommend a book by
Brookshear called
“Computer Science: an overview” (8th edition). It’s written for those
new to CS, but introduces lots of nice CS concepts like algorithm analysis,
theory of computation (e.g. that some problems cannot be solved!), and other
things like OS, networks, DBs, etc. It’s a great starter book. After that,
I’d recommend books on data structures and algorithms. After that, it really
depends on what his interests are: Programming Languages? Theory? Operating
Systems? Distributed Systems? Software Eng? AI?
Discuss
April 3, 2004
spout
The Future Is eBay for Services
Here.
With the bottom line more and more important, the era of “company loyalty” and “guaranteed employment” is long over. RentACoder.com takes this to it’s logical conclusion, matching vendors with jobs and money with qualified folks with the time and willingness to do the job at the asking price. As connectedness improves, the importance of being on site declines, the perfect market for services will develop, giving us eBay for employment.
April 1, 2004
spout
Let There By Light In The Darkness
Here. The one where it's late, I'm on my 3rd Diet Coke (I never use caffine), I stumble onto a piece of writing I like but have never published and decide
what the hell...