line keyword in CSharp

I was working on some WPF code today and ended up looking in the partial class generated for a UserControl I was working on. The code it was generating was very strange and littered throughout it were some #line statements. So I headed over to the #line MSDN article to see what it was all about. It turns out it is a way for you to tell the compiler, directly in your code, to pretend that a particular line of code is actually from somewhere else. You can also “hide” code from the debugger apparently.

From what I understand this is only useful for compile time errors, and even then probably only useful for code generation. I’m pretty excited about this though because it will really be useful for generating code in NBusiness. In this way if I generate a property (for example) based on a field declared in an entity I can add a #line statement to redirect any errors that come up back to the entity field rather than some murky, generated, partial class that no one want’s to look through.

Beyond uses for code generation I really have a hard time coming up with a practical reason why it would be used… but it seems like it could be a really fun way to obfuscate code and make your coworkers life a living hell. Maybe if you don’t like a particular piece of code they wrote in, say, GiantComponenent.cs just add a snippet to one of your classes such as:

#line 1 "GiantComponent.cs"
)()F@#K@N3fkn

 

Now just head over to their desk and complain about some compile error you’re running into in their code.

Well I guess it’s true that you learn something new everyday.

Lang.NET 2008 Wrap Up

I’ve recently returned from a trip to Redmond. I was at the Lang.NET conference sponsored by Microsoft. Overall it was great. Microsoft took care of us like royalty and the people and conversations were incredible. With all the big brains around I felt even more retarded than normal, I was definitely an amateur compared to a lot of the people who were attending. The only thing that was unfortunate was that I managed to get a cold just before going out there, which was mild at first, but caused me to miss out on a lot of the free beer supplied (and lots of breweries I haven’t had a chance to try out yet too!) as well as miss the 3rd day entirely! I was really looking forward to seeing the VSX presentation and get a chance to talk to someone about NBusiness and get some integration questions I have been kicking around answered. Also, based on the description of Don Box’s speech I’m really sad to have missed that.

I met a guy there named Ted Neward. He was going to hook me up with a chance to meet with Ken Levy to talk about VS integration. I had to miss it because I was too sick and had completely lost my voice but I have his email address and will probably be sending him an email with a few questions and ideas.
 
Besides Jason Bock and I there were at least two other people from Minneapolis, Wez Furlong from the PHP group as well as Charles Nutter who works on JRuby for Sun. There was another guy there from Sun named John Rose who had a lot of interesting things to say about the similarities between Java and .NET and also knew a lot about creating programming languages. He talked about a lot of interesting things with me at the Rock Bottom brewery. It’s really encouraging to see that it’s possible to collaborate and discuss topics such as programming languages even between competitors. It seems that programming languages might just unite nerds more than divide them after all.
Overall I’d say that this symposium really revealed an intense focus towards dynamic languages right now. Perhaps it’s just the language enthusiasts who are the most interested in dynamic languages. This was an overwhelming focal point for this event. It’s all very cool stuff and I’m completely sold on the idea of using a dynamic language for developing unit tests first then writing your application. I’m not completely sold on the idea of a dynamic language everywhere however. It seems like it’s perfect for the top tier of an application, where things change the most and need to be the most flexible, but the lower you go a nice strongly typed library with strict encapsulation is probably preferable.
I was able to see Anders Hejlsberg (C#), Jim Hugunin (Iron Ruby and the DLR), Erik Meijer and many others speak. The videos should be on Channel 9 any day now. Here is a channel9 interview that took place with some of the speakers called Erik Meijer, Gilad Bracha, Mads Torgersen: Perspectives on Programming Language Design and Evolution but this was not one of the actual presentations. I also recognized John Lam (Iron Ruby) and Miguel De Icaza (Mono) in the audience but I missed their talks because I was sick.
One other interesting thing was getting to talk to a guy from Intentional Software. Now this is real brain bending stuff and if you haven’t heard of intentional programming before I suggest you go look it up because it’s a fascinating idea… probably best left for another post.

 

Error Invoking AppDomain Proxy

I’m having one heck of an AppDomain bug. I have a situation where I am creating an AppDomain and then creating an instance and unwrapping it and invoking a method on that proxy instance. The first time I invoke this instance I get successful results and if I have a breakpoint inside of the proxy it will break on it, however the second time I invoke the method it will fail by yielding an incorrect return value.

Also, strangely enough, if I ever try to step INTO the method call with the debugger visual studio will suddenly shutdown. Examining the error code in the debugger doesn’t really reveal anything valuable either. Here is a link to the code in question:

ESharpCompiler.cs

Photoshop Usability Complaints

I’ve been using Photoshop CS2 a little bit lately for a project I am working on and I have come up with a few complaints about it already. For being so famously the defacto graphics editing standard I am really dissapointed in the quality of the user interface and the usability of the application in general. Perhaps I am a little biased since I was forced to use Adobe Framemaker not long ago (which is an atrocity of a WYSIWYG editor) and now I can see similarities between Frame Maker and other Adobe products and it scares me.

For example when I try to open a particular PSD I get this screen:

Photoshop usability

I realize I’m just an idiot user but what the hell does the button “Read composite data” have to do with having an error? Clicking ok or “Read composite data” seem to have the exact same results. Ugh. A little help button or mouse-hover tool tip would be useful here.