Why Doesn’t C# Implement "Top Level" Methods?

C# requires that every method be in some class, even if it is a static method in a static class in the global namespace. Other languages allow “top level” functions. A recent stackoverflow post asks why that is. I am asked “why doesn’t C# implement feature X?” all the time. The answer is always the…

58

C# 3.0 is still statically typed, honest!

Since LINQ was announced I’ve seen a lot of really positive feedback and a lot of questions and concerns. Keep ’em coming! We need this feedback so that we can both correct misconceptions early and get the design right now. One of the misconceptions that I’ve seen a lot over the last few days in…

24

Instance-bound nested classes in JScript .NET

The other day someone asked me about a slightly odd but very useful feature in JScript.NET, and I figure if one person asks me about it, maybe more people want to know as well.  In JScript.NET you can say class alpha {  var foo;  class bravo {    function blah() {      print (foo);    }  }} var x…

2

Fun With Floating Point Arithmetic, Part Six

One more thing — I said earlier that the VBScript float-to-string algorithm was a little bit different than the JScript algorithm. We can demonstrate quite easily by comparing the outputs of two nigh-identical programs: ‘ VBScriptprint 9.2 * 100.0 < 920.0print 919.9999999999999 < 920.0 print 920.0000000000001 > 920.0 ‘ JScriptprint(9.2*100.00 < 920.0);print(919.9999999999999 < 920.0);print (920.0000000000001…

4

Fun with Floating Point Arithmetic, Part Five

I went to Joel Spolsky’s geek dinner at Crossroads the other night, which was a lot of fun. I didn’t get much of a chance to chat with Joel, as he was surrounded by a cadre of adoring fans three deep the whole time.  I mostly hung out with KC and Larry and some other…

11

JScript .NET Type Coercion Semantics, Part Four: Coercion at last

Before I get going, a couple notable milestones.  First, this is post number 200!  Who would have believed that I’d have so much to ramble on about?  (“Anyone who knows you” would be the correct answer to that rhetorical question I suppose.)  Second, as of Sunday I am now over (cue Dr. Evil) one billion…

8

JScript .NET Type Coercion Semantics, Part Three: Assignability

Before I begin today’s technical topic, a quick link to what promises to be a terrifying, I mean, terribly interesting blog.  Mario, the guy who tests the code that I write and thereby keeps me honest, the guy who’s application for a backyard barbecue was turned down by the Redmond fire department, the guy who, when…

4

JScript .NET Type Coercion Semantics, Part Two: Promotability

Last time I gave some vague, high-level definitions of the type system concepts promotable, assignable and coercible. Today I’ll give a more precise definition of promotable. The others I’ll define more precisely later. Suppose we have an assignment of an expression to a typed field. Left Hand Side Expression = Right Hand Side Expression; where…

2

JScript .NET Type Coercion Semantics

Stan Lippman has started an interesting series of blog entries on how Managed C++ determines which function foo to call when you call foo(bar) given that there may be several visible functions of that name in the current scope.  That’s quite coincidental, as just the other day I was going through some old mail when I…

0

A JScript .NET Design Donnybrook, Part Two

I am totally amused that the comments on yesterday’s entry are nigh-isomorphic to the argument that we had over this in October 2000. As noted, f.bar(f); does in fact call the base class function, not the derived class function as some might expect. I was on the fence back in 2000, but leaning towards the…

11