Navigation


Markus on Development and Publishing

This is Markus Egger's professional blog, which covers topics such as development, publishing, and business in general. As the publisher of CoDe and CoDe Focus magazines, and as the President and Chief Software Architect of EPS Software Corp., Markus shares his insights and opinions on this blog.

Content Area Footer

Saturday, April 22, 2006
A Nice Generics Example

The .NET Runtime 2.0 has a very nice new feature called "Generics". Generics have a lot to do with strong-typing. As you probably know, everything one does in .NET is supposed to be strongly types, since it has such a positive impact on code quality (among other things). However, there are some areas where strong typing had to be violated in .NET up to version 1.1, or - as an alternative - the developer had to do an insane amount of work to get the advantages of strong typing.

One example are lists of objects stored in collections. For this purpose, .NET offers various classes, such as the ArrayList class. An array list can store any object type. For instance, an array list can store form classes:

ArrayList myForms = new ArrayList();
myForms.Add(new Form());
myForms.Add(new Form());
myForms.Add(new CustomerEditForm());

Having collections of objects is very useful in many ways. For instance, we can now iterate over these forms to show them all on screen:

foreach (Form frm in myForms)
{
    frm.Show();
}

Now here is the problem: What if someone stored something other than a Form instance into that collection? An ArrayList can store any object, not just forms. So this would be a disaster:

ArrayList myForms = new ArrayList();
myForms.Add(new Form());
myForms.Add(new Form());
myForms.Add(new Button());
foreach (Form frm in myForms)
{
    frm.Show();
}

This would fail at runtime, since there is no way for the ArrayList class to control that only a certain type of object can be stored in that particular instance.

So how can we solve this problem? In .NET 1.1, this problem is solved by subclassing the ArrayList class and changing a number of members (such as the Add() method) to accept only Form classes. The problem with this is that it is very time consuming to do this. One has to create a subclass for forms, another for buttons, another for DataSets, and so on. (Keep in mind that there are thousands of different object types in the .NET Framework).

This is why .NET 2.0 introduces a the "Generics" feature. It allows for the generic definition of classes (such as an ArrayList-like class), but then when it is used, define a more specific purpose. This example shows the new List class, which is a generics-enabled version of the ArrayList:

List<Form> myForms = new List<Form>();
myForms.Add(new Form());
myForms.Add(new Form());
myForms.Add(new Button()); // Compiler Error!!!

In this case, a new List object is instantiated, but it is stated that in this instance, only Form objects can be stored in it. This is defined in the angle brackets. Instead of saying "we instantiate an ArrayList", we would now say "we instantiate a List of Form".

This is very cool, because is is great for code quality as well as productivity.

Now here is a very cool example for the use of generics in a non-collection example: I recently helped a customer to create business rules. The customer uses our Milos Solution Platform (framework) to create their application, and Milos (like many other frameworks) allows for the definition of business rules as classes (this is only one of the ways of doing this... but exact workings of Milos are not the subject of this post). The customer wanted to create a generic rule that allowed them to compare any data field to a value and say "this is only valid of the value is greater than X".

In .NET 1.1, this sort of rule could be implemented through objects that "implement IComparable". Many objects, such as integers, decimals, strings,... implement IComparable. This way, it is possible to say "if (x > 0)", which compares x to 0 and evaluates to true if x is indeed greater than 0. It also allows us to say 'if ("B" > "A")', which evaluates to true, since A is before B in the alphabet. So this works with every object that implements IComparable. Therefore, a method that compares to values could be implemented like this in C#:

public class MyRule
    public bool
IsGreater(IComparable val1, IComparable val2)
    {
        if (val1.CompareTo(val2) > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

We can now call this method passing two integers (numbers), since integers implement IComparable. So the following is perfectly valid:

MyRule x = new MyRule();
x.IsGreater(10,5);

The following is also valid, since strings implement IComparable:

MyRule x = new MyRule();
x.IsGreater("Athens","Rome");

So far so good. The only gotcha here is that both passed parameters need to be not just of a type that implements IComparable, but they in fact need to be the SAME type. In other words: This would not work despite both parameters being IComparable:

MyRule x = new MyRule();
x.IsGreater(10,"Rome");

And this can be a bummer, because sometimes this gets confusing. A typical failure scenario would be one where two different numeric types (decimal and integer for instance) are passed. What we need is a way to implement this as generically as demonstrated here, but when the method is used, it needs to be restricted to a specific type. And once again, this can be done when the same method is implemented through generics:

MyRule<int> x = new MyRule<int>();
x.IsGreater(10,20);
x.IsGreater(10,"Rome"); // Compiler Error!!!

I thought this was a very nice use of Generics. It saved us from having to create potentially hundreds of different strongly-typed rules and still get full compiler quality checking.

BTW: A little while back I blogged about the creation of a Length data type. At the time, some readers discussed whether there was a real advantage over creating a new data type, or whether the same advantages could be achieved through more procedural means in other languages (or even OOP concepts as in this case, where most of the readership came from VFP). This business rule example is a good demonstration of why it is advantageous to have custom types. The Length type I created in this example can be used with this same business rule class like so:

MyRule<Length> x = new MyRule<Length>();
x.IsGreater(new Length("5 foot 6 inch"),new Length("1m 25cm"));

There is no difference between the usage of this custom type and the intrinsic types. As long as the custom type implements IComparable, it will work in all the scenarios all the other types work.

BTW: If you are interested in more info about generics, check out the following CoDe Magazine search link:
http://www.code-magazine.com/SearchResults.aspx?search=Generics

 



Posted @ 6:32 PM by Egger, Markus (markus@code-magazine.com) -
Comments (6)


Saturday, April 22, 2006
About Magazines, Free Issues, (Online) Bills, and more...

Here's a bit of insider information from the magazine business: Magazines (especially trade magazines like our CoDe Magazine) get a lot of their business from selling subscriptions. Advertisement plays a big role too, but subscriptions are extremely important. This may not be a great revelation, but I would like to give you an insight in some of the behind-the-scenes aspects.

A magazine subscription sells for a usually modest fee (less than 30 bucks in our case). These 30 bucks have to cover the production of the magazine, creation of articles, editing, layout, art production, and of course printing and shipping, which is a huge part these days. (Note: Publishers are in the business of buying and selling paper... and paper has become very expensive...). In the case of CoDe Magazine, the subscription fee covers 6 regular issues a year, plus whatever special CoDe Focus issues we produce, as well as other services such as online content and electronic-only articles. At the end of the day, things work very similar as in any other business: Ideally, there is a little bit of a profit margin that makes it worthwhile to do it all. However, there are a few unusual catches in the business of publishing magazines...

What really makes publishing a magazine "interesting" is the issue of collecting one's money. When we sell software to someone, things are much easier: There is a contract and bills are paid with a fair degree of certainty and predictability. With magazines, things are different! Many subscribers just get out their credit card, but many do not. They choose the "bill-me" option instead, indicating that they want a bill at a later point. This is a standard thing to do in the magazine industry, but I sometimes think it might be the downfall of the industry. The problem is that it is very time consuming and expensive to collect on those invoices. Let's assume that a subscription has a $5-$8 profit margin. For a new subscription, the profit margin is perhaps between $0 and $3 (sometimes it is a loss, actually). Generally, due to the cost of producing a new subscriber by advertising to them (by sending free issues or trial issues for instance), publishers do not make money on the initial subscription but only on renewals. But that is a different subject, and I digress...

So let's say for argument's sake, that a subscription makes a theoretic profit of $5 (which is a best-case scenario in almost all cases), but we have not collected our money yet. What publishers do is they create "billing series". This means that there are several steps of trying to collect the money. This usually goes on for up to 6 months, which is defined by audit regulations. (Note: I blogged about magazine auditing before... you can check it out here). What this means is that a publisher may send a number of reminders and statements to the subscriber. Perhaps as many as 6 to 10. Now mull that over in your mind for a moment. If one sends 10 letters at say 50 cents each (counting all the labor it is usually more expensive than that... especially for a small publisher like us), then that is 5 bucks. And that eats the best-case profit margin! And sometimes, subscribers still don't pay! Take one such subscriber and your are 35 bucks in the hole! This takes a lot of other subscribers to just make up the loss.

This is the classical challenge of magazine publishing. This is also the reason why we try to work with email reminders and online statements as much as we can at CoDe Magazine. It simply is not sustainable for a small publisher like us to do all of the traditional paper trail. But what do people think about it? I don't know, and I am hoping some people will send us feedback. Of course, there always are a few people who sign up for a bill-me subscription and then when they get an email bill, claim it is spam! But I am not sure that is an accurate representation of the market. So let m know what you think, either by posting a comment on this post, or by sending me an email.

BTW: If you wonder where all that electronic stuff is for CoDe Magazine, check out the My Account section on the web site, where you can see the status of your subscription, renew it, and even pay an open bill and save a tree or two in the process... ;-)

 



Posted @ 5:23 PM by Egger, Markus (markus@code-magazine.com) -
Comments (6)


Thursday, April 20, 2006
Office 12 UI Video

Check out this video about the Office 12 user interface. This is quite interesting. It will take a little to get used to, especially for us geeks, but I think the results-driven approach is going to be the better way to go:

http://www.microsoft.com/office/preview/ui/demo.mspx

 



Posted @ 9:08 PM by Egger, Markus (markus@code-magazine.com) -
Comments (8)


Saturday, April 15, 2006
DevConnections Orlando Slides and Samples

I recently spoke at DevConnecitons 2006 in Orlando.I did an all-day pre-con on UI design and UI technologies. I also did a session on OOP.

The UI design session was a pre-con that people had to pay in addition. I therefore can not just put up my examples here (the closest I can get is the Avalon examples I posted today). However, there was a mixup with the exact session content, and I ended up adjusting the slides the night before. So in all fairness, here is a link to the slide deck I used.

I also did a session on basic OOP. The examples I created and used can be downloaded here.

In this session (as well as other occasion), I constantly seem to be referring back to a session about data access architecture I did a while back (since some of the OOP examples I use refer to an "appropriate data access architecture" more than once). For more info on that, check out the following links:\

 



Posted @ 2:59 PM by Egger, Markus (markus@code-magazine.com) -
Comments (9)


Saturday, April 15, 2006
LINQ Examples from Little Rock

At the Little Rock Tech Expo 2006, I also did a LINQ session. Click here to download the code samples.

If you are looking for more information on LINQ, I recently had an article about LINQ in CoDe Magazine. The article can be read online at the CoDe Magazine site:

There also are a few shorter articles on LINQ on this site:

Another interesting article that discusses LINQ's XML support (also known as "XLINQ") can be found at this URL:

 



Posted @ 2:49 PM by Egger, Markus (markus@code-magazine.com) -
Comments (16)


Saturday, April 15, 2006
WPF (Avalon) Examples from Little Rock

A few weeks ago, I did a presentation on WPF (Avalon) at the Little Rock Tech Expo 2006. I promised to make the examples available online, so here I go: Click here for the exact examples I used that day.

Note that you will need the March 2006 CTP of the WPF bits to run these examples. (Get them from www.Microsoft.com/vista, if you do not have them already).

What is interesting about these examples (asides from the core concepts the examples communicate) is that they are updated versions of earlier CTPs. All the examples I had in this post, are in these examples in a very similar fashion. So if you compare both sets of examples, you can learn quite a bit about syntax changes in between CTPs.

The examples include the animation fundamentals:



2D and 3D concepts:

Visual brush examples:

And the teapot shopping cart and product visualization example:

Enjoy!

 



Posted @ 2:45 PM by Egger, Markus (markus@code-magazine.com) -
Comments (7)


Friday, April 14, 2006
My Ink Analysis Article in MSDN Magazine

The May 2006 issue of MSDN Magazine has an article of mine covering a hot new Tablet PC topic. Here is a link to the article.

So "what is up with this?", you ask? "Don't I own my own magazine?". Yes I do (CoDe Magazine). So why am I writing for a competing magazine? Quite simply put, because other magazines are good too. I have written (and am writing) for other magazines, including MSDN, VS Magazine, ASP.NET Pro, and various other US and international magazines. And also because I am a magazine nut! But of course, I still do most of my writing for CoDe Magazine.

BTW: There is a (somewhat incomplete) list of my published articles at http://www.markusegger.com/Articles/Index.aspx

 



Posted @ 1:43 PM by Egger, Markus (markus@code-magazine.com) -
Comments (16)


Wednesday, April 12, 2006
Interesting Paper on XLinq (and my own article on LINQ)

Here is a pretty interesting paper on XLinq (short read too):

http://research.microsoft.com/~emeijer/Papers/PlanXDemo.pdf

BTW: I recently had my own article on LINQ published in CoDe Magazine. My article is "slightly" longer but it also covers many more aspects of LINQ. Here's the link to that:

http://www.code-magazine.com/Article.aspx?quickid=0603021

 



Posted @ 8:34 PM by Egger, Markus (markus@code-magazine.com) -
Comments (7)


Thursday, April 06, 2006
MS Expression Training Videos

Microsoft has recently published training videos for the new Microsoft Expression product line. In particular, the ones for the Interactive Designer (formerly known as "Sparkle") are very interesting.

Here is the URL:
http://www.microsoft.com/products/expression/en/demos.mspx

If you have not checked into the Expression product line, you should! This is going to impact every developer's life who has anything to do with building UIs...

 



Posted @ 9:00 PM by Egger, Markus (markus@code-magazine.com) -
Comments (4)


Thursday, April 06, 2006
Conference and Event Update

I am in the middle of a conference stint, which is why I was too busy to blog lately. I also owe people a whole bunch of session notes, slides, and examples that I promised to post here. I will do so ASAP.

Here is a quick update of where I have been, how things turned out, and what session materials I will be uploading soon:

  1. Little Rock Tech Expo: This is a while ago now, but I still owe people session notes for my Avalon and LINQ sessions. I will provide those soon. The event itself was interesting. I had reasonably good turnout for my session, especially considering that this wasn't a full conference. The user group that put this on did a good job.
  2. VFPConversion Workshops, Europe: Things went very well here. In fact, I blogged about this on the German VFPConversion Developer's Blog, and I will soon post a recap on the US VFPConversion Developer's Blog. More workshops are being planned. Watch for announcements on the www.VFPConversion.com site.
  3. DevConnections, Orlando: This conference is always a blast, and despite having next to no spare time, I enjoyed staying in one of my favorite hotels, the Hyatt Grand Regency Cypress. If you are interested in the location, I will soon post more information on my travel blog. As far as technical stuff goes, this conference is still a great resource and good bang for the buck. DevConnections certainly has more momentum than "comparable US conferences". The next one will be in Las Vegas this fall, which should be a blockbuster! I can't wait. This is one of the few conferences I am actually looking forward to these days.
    If you are looking for session notes: As soon as I get to a computer that actually allows me to upload files at a reasonable speed, I will post infos for my OOP session as well as my UI-design pre-con.

That is it for now. It actually turns out that the 3-day training (mobile .NET development) I was supposed to do in Dallas, Austin, and Houston got postponed by Microsoft. Works for me, I am extremely busy anyway.

Coming up, there still is the DevConnections conference in Nice which I am not completely sure I will be able to attend at this point. If you are in Europe however, make sure to check it out!

And then of course, there is my personal main event of the year: DevTeach in Montreal. This isn't "our" show, but based on their previous performance, we have decided to be a main sponsor of the show through CoDe Magazine. I feel that this conference has the best bang for the buck. There are great speakers there, and due to the great speaker-to-attendee ratio, this is the best conference if you actually want to meet any of them. Plus, Montreal is just a very nice place to visit! If you go to DevTeach, make sure to stop by and say hi!



Posted @ 8:58 PM by Egger, Markus (markus@code-magazine.com) -
Comments (11)


 

 

 

 

 

 

 

Syndication RSS 2.0 RSS 2.0

All My Blogs:
My personal blogs:
Dev and Publishing Dev and Publishing
Travel and Internat. Living Travel and Internat. Living
Other blogs I contribute to:
Milos Blog (US) Milos Blog (US)
VFPConv. Dev Blog (US) VFPConv. Dev Blog (US)
VFPConv. Dev Blog (DE) VFPConv. Dev Blog (DE)

 

Blog Archives
All Blog Posts

2015
    September (1)
2012
    September (1)
    April (1)
    March (1)
2011
    October (1)
    June (3)
    May (1)
    March (2)
    February (2)
    January (2)
2010
    December (3)
    November (2)
    October (2)
    September (1)
    August (2)
    July (1)
    June (1)
    April (3)
    March (1)
    February (5)
    January (1)
2009
    October (4)
    September (2)
    August (1)
    July (1)
    May (4)
    April (6)
    February (1)
    January (1)
2008
    December (3)
    November (11)
    October (8)
    September (1)
    July (1)
    June (3)
    May (3)
    April (6)
    March (6)
    February (4)
2007
    December (1)
    November (1)
    October (5)
    September (1)
    August (1)
    July (6)
    June (3)
    May (3)
    April (1)
    March (2)
    January (2)
2006
    December (3)
    November (4)
    October (1)
    September (2)
    August (2)
    July (4)
    June (1)
    May (2)
    April (10)
    March (2)
    February (3)
    January (1)
2005
    December (6)
    November (7)
    October (6)
    September (8)
    August (10)
    July (6)
    June (9)

 

 

 

This Blog is powered by MilosTM Collaboration Components.