May
31.
2005

Your wish is our command

Posted by: Drazen Dotlic in Categories: .NET (C#).
Tags:

This is really cool. Chris McKenzie just wrote how he would really, really like to see the .NET support different accessors for get and set on the properties.

You know what? It's already implemented :) (tried with beta 2 bits) Given the following definition (totally stupid example just to illustrate the point):

public class MyClass
{
  public MyClass()
  {
    m_Names = new String[42];
  }
  public string this[int index]
  {
    get
    {
      return m_Names[index];
    }
    private set
    {
      m_Names[index] = value;
    }
  }
  String[] m_Names;
  public void TestAccess()
  {
    this[1] = "Foo";
  }
}

In the following code snippet, last line does not compile with compiler complaining error CS0272: The property or indexer 'MyNamespace.MyClass.this[int]' cannot be used in this context because the set accessor is inaccessible (just like it should):

MyClass mc = new MyClass();
mc.TestAccess(); // works fine
String gotIt = mc[1]; // gotIt is "Foo"
mc[1] = "Bar"; // does not compile

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
31.
2005

Code Generation

Posted by: Drazen Dotlic in Categories: .NET (C#).
Tags:

I have recently finished Code Generation in Microsoft .NET, one of the many books on the hot topic of code generation. The reason I picked this and not some other book is because it appeals to the XML fan in me - I used to do a lot of XML/XSD/XSLT back in the day and XSLT is the main driver of this book's approach.

I find the book generally good, if a bit too overloaded with repetitive code snippets. It could have easily been 100-200 pages shorter without any loss of substance. There are a few quirks too - the chapter dedicated to generation of UI code does not contain a single screenshot!

The approach is sound and the text contains a lot of real life advice not so much on how and why to use the code generation tool (there's a lot of it too, of course), but a topic many skip too fast - how to properly prepare the metadata. Most of the fields where code generation is used are covered, including the most frequent one - anything related to the data layer or to database access. If you know XSLT (or at least are not afraid of it ;)) you should definitely give it a try.

The reason I write this is that I noticed something peculiar - throughout the course of the book, the author builds a tool called harness that drives the whole process - it reads the harness XML file describing where to find metadata, how to pre-process it, how to process it and where to put the results. It looks like this:

It does not look pretty, but it gets the job done. Thinking about this a bit more, I find that this is nothing more than a custom version of a general build tool like NAnt. After all, all it needs to do is to process a set of strict rules that define operations on files. If there are a few highly specialized tasks, they can always be implemented by NAnt tasks.

I will try to do a non-trivial code generation task using this approach (NAnt instead of custom harness tool) to verify its plausibility.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
30.
2005

Sadly, after all those millions spent by Microsoft, looks like Sony won. Even though they presented nothing more than some questionable numbers and mostly pre-rendered "demos" they wowed the crowd more and as one IGN reporter said "their bars were bigger than Microsoft bars" (on the graph charts of performance, presented by Sony).

A bit too little and a bit too late, Microsoft (indirectly) responded to some of the wildest performance claims by Sony through this site. Search the recent posts and you will find a strongly biased XBox360 performance analysis but an interesting read nevertheless.

All that glamour and show aside, I think this round Microsoft wins. Not because they have better hardware, but because they have a better package. It's not all about performance although it is very important and XBox360 seems to have more than enough of that. It's also about the user interface (there are some hints that all games will be able to use menu system provided by XBox360), XBox Live! and multimedia integration.

My only problem is that I don't want to buy XBox360 and use it with a plain old wide-screen CRT. It's all about HD, baby! I'm thinking of a projector more than, say, plasma or LCD TV. I'd also need a decent 5.1 sound setup (all I have now is one that is computer based and without a hardware decoder so I need PC to run it).

In any case future is bright and gaming will never be the same, regardless of the platform you choose. But make sure you see some games in action before you decide...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
27.
2005

While following the excellent Business of Software forum over at Joel I noticed a recurring theme: people often wonder how to avoid procrastination and get things done.

Usual recommendations are various complex tools and/or methodologies, time tracking and whatnot. But what it all boils down is discipline - if you can maintain certain pace, you can get many things done. You don't need advanced tools, just a way to formalize what you want to achieve and to organize yourself a bit. Here's what I found to be very effective, yet require absolutely minimal effort from me:

  • I read news (RSS) and forums at designated times every day; for example, I never read in the morning when I am most fresh, but wait for the lunch break (around noon); I have also cut down the number of feeds I follow, especially group feeds
  • I split work into categories that I never mix; focus is important
  • If I have actionable things in the mail, I use simplest thing that works - flags in Outlook 2003; they are crude, have only color that carries no meaning, yet relieve me from anxiety not being able to remember what was it in the recent email that I was supposed to act upon; when I find time, I clear them off one by one
  • I decided to catch up on my huge backlog of books I bought but never read by setting a reasonable pace of one book per week; so far (about 8 weeks later) I am still on time and doing good progress on the remainder of my bookshelf
  • I have cut down the (XBox) gaming time to about 1 hour per session/day; I don't stick to it 100% but most of the time it proves to be enough
  • I get up at the same time every day, and lot earlier than before; this means that I need to be in bed by midnight (again, I don't stick to it 100%) but it also means that I get a lot more time with my wife in the afternoon as I get out of work earlier

I guess it boils down to good old KISS principle...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
26.
2005

A thought provoking post about the necessity of C# now that C++/CLI is "all that and a bit more" in the .NET 2.0 could be found here.

As a hard-core C++ developer by day, and C# developer by night I feel the need to respond to the following:

So C# will become the natural home simply for those poor folk who have already invested time in it, and possibly for Java types moving to .NET and smart enough to avoid J#. It will be interesting to see how many ex C++ programmers slip back to C++ now that it is fully .NET enabled.

This is oversimplification. The main appeal of C# as I see it is its simplicity (at least compared to C++). You can't do everything in C# that you could in C++, but we're getting there. With generics (yes, poor man's templates, but nice nevertheless), anonymous methods and iterators you are getting quite a powerful platform. What C# lacks in expressiveness it more than makes up with simplicity - I have never seen C# complier die on me, while I manage to ICE a C++ compiler every few weeks or so.

Make no mistake, I am not a crybaby that can't write decent C++ code worth a damn (if you still don't believe me, check my article on C++ asynchronous delegates in November 2004 issue of C++ Users Journal). I have done my share of insanely complicated meta-programs in true spirit of Alexandrescu's most excellent book Modern C++ Design, and I liked it to a certain extent.

But I discovered that I can easily live with C#. I admit that I miss template support (generics help here) and deterministic "destruction" of locals but apart from that I don't miss C++ that much. I am also a bit irritated that with C++/CLI I will have to use yet another symbol to denote a pointer: "^" for reference types that live on garbage collected heap. Thus, we have "*" (normal pointer), "&" (reference, like a pointer but with a twist) and "^". I don't know about you, but not having to write any of these in C# feels good.

Besides, with .NET 2.0 I can freely mix the languages inside the project so I don't have to choose - I can use all available languages if I want. This will most likely lead to 80/20 ratio between C# and C++ in my future projects, mainly because I expect to use STL.NET a lot more than "regular" BCL collections and algorithms.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
21.
2005

Decoding HD content

Posted by: Drazen Dotlic in Categories: entertainment.
Tags:

While checking out what's new at E3 I, ahem, run into the HD video of babes - very nice looking girls that attract mostly male public and bring them closer to the booth of the company they are working for. You need relatively poweful machine to decode this kind of content - 1280x720 resolution and about 6MB/sec in Window Media Format.

I tried it on three machines - three years old Athlon XP 1500 (1.33GHz), Dual Xeon 2.4GHz and Centrino 1.7GHz laptop - all machines had 1GB of RAM and 7200 rpm hard drives.

It was totally unusable on the Athlon machine, Xeon machine had a bit of stuttering here and there while Centrino played it flawlessly. The kicker is that because this is a laptop the processor runs only at the speed it needs to in order to conserve power, thus it was running at 1 (!) GHz only.

Wow.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
19.
2005

Like every self-respecting geek I went to see Star Wars 3 the first day of showing. I was afraid that the city might be crowded with Cannes movie festival and all that, but we came there on time.

Movie was really good, much better than the previous two. Make sure you don't read any comments about the content (I deliberately don't say plot because we all mostly know what's gonna happen) or they will only make you look for this or that good (or bad) thing and distract you. If you even remotely like Star Wars, just go see it - you won't be disappointed.

Speaking of Cannes movie festival - since the movie ended about 1h in the morning I was expecting to find mostly empty streets, but it took us 20 minutes to get out of the croisette! The night life is blooming during the festival...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
May
11.
2005

Yahoo! Music might be The One

Posted by: Drazen Dotlic in Categories: rant.
Tags:

Yahoo! joins the game a bit late, but seems they might just finally get the right balance of DRM/freedom/price. I won't repeat the details of their offer (it's all over the Web)  but tell you about "Drazen test".

You see, whenever a new music download service shows up, I do a small test and try to find any album from two of my favorite authors. Both are rather unknown in the USA (or so I'm told) and occupy relatively strange genres. They are Stephan Micus and Wim Mertens. The reasoning is simple - if the service offers anything from these two authors, their choice is probably quite good (yes I know that statistically this sample sucks, but it's at least some kind of measure).

None of the music download services passed this test, at least until now - Yahoo! offers quite a good choice of Micus and only one album from Mertens, but they even have author's biographies!

I will definitely have to evaluate it ;)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
3 Comments
May
6.
2005

Premature optimization

Posted by: Drazen Dotlic in Categories: rant.
Tags:

If you're having trouble remembering if premature optimization is good or bad, remember this: treat it exactly as premature ejaculation.

Trust me on this one. Just don't do it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
1 Comments
May
5.
2005

As I was reading the first chapter of Code Generation in Microsoft .NET I noticed that the .NET 2.0 will help me in the area of code generation with the support for partial classes. You see, most of the time when you generate code you will have parts that will be hand-crafted and parts that are auto-generated. To avoid stomping on your hand-crafted code by the auto-generation and to try to prevent yourself from accidentally editing auto-generated code you will most likely keep auto-generated code in separate files. But what if you need to mix these two blocks of code inside one class?

Note that this is very similar to what ASP.NET does - you have a class that derives from Page in a code-behind class (hand-crafted by you) plus the runtime generates (automatically) one from your .aspx file and then combines them by derivation. That's the best you can do in .NET 1.1, but it's not the best solution always. If only we could have part of the class in one file and another part in the other file... exactly what partial class support in .NET 2.0 is for!

So now you can naturally split the auto-generated and hand-crafted code yet still get one coherent class.

Note also that ASP.NET 2.0 does exactly the same thing - no more derivation, now the auto-generated code is only a partial class part of your code (or vice versa, depending how you look at it).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments