Today I had a discussion about coding guidelines and in particular about the size of a class, the number of methods in a class and the number of lines of code per class. What is right?
Ofcourse a little search on Google revealed millions of hits. Some of the more useful ones were:
Most standards don't say much about the size of a class, the number of methods in a class and the number of lines of code per class. The few that do say something come fairly close.
Here's the sum of guidelines that I think I'll stick by:
- A source file should only contain one class
- A method should be no more than 30 lines of code, excluding blank lines and comments
- A source file should contain no more than 1000 lines, including blanks and comments
- An interface should have no more than 10 methods, excluding overloads, ie. the combination of overloads counts as one methods
- C# 2.0 allows partial classes:
- a source file should only contain one partial class
- don't split the implementation of an interface across multiple files
- for large classes split the implementation of interfaces and implement one interface per file
- Filename: <classname>.<interfacename>.cs
- if you have a class which implements one interace, but has a lot of private methods, then create a partial class with just the private methods:
- Filename: <classname>.private.cs
Ad 2. This is the average I found and seems to make sense, since this means that with one look at the screen your brain can absorb the whole method.
Ad 3. I'm not convinced this is a very important rule. Having 2000 lines of code in one file or spread across two classes in two files doesn't really make that big a difference to me. See also ad 5.
Ad 4. This is mainly because of Intellisense. Ten methods will provide optimum use of Intellisense.
Ad 5. Partial classes are great!
I'll be speaking at the Software Developer Conference 2006. The biggest software developer usergroup meeting in The Netherlands and probably Europe. Are you going? If not, why not?
Ten reasons for coming to SDC 2006:
- The schedule: 90+ sessions about software development, software development and more software development, and to sum it up: more software development. - The speakers: the best of best, the cream of the crop from all over the world! - The sessions: educational, in depth, fun and repeated so you don't have to miss any. - The evenings: the monday nights at SDC are always great, for now still a suprise but it will be very amusing! - The Internet Cafe: there will be Wi-Fi at the conference, but for those who don't have a laptop with them there will be the Internet Cafe. - All-in price: the SDN is a no-nonsense usergroup, so no surprises and a crazy value for money conference. The registrationfee covers everything except for the bartab on Monday night. - Supplier access: all important industry supplies will be present and available for questions. - Goodiebag: with notebook, nice bag, extra's and extra's... - Location: to be at Papendal for two days is a great environment to leave your work behind and submerge in the sessions and the wealth of knowledge which will be shared. - Price: as a usergroup the SDN does not organize this conference for profit, but for you, the developer!
Want more information? Go to: www.sdc.nl
Ofcourse you're going! See you there!
So you're a developer and you want to get started with Windows Presentation Foundation (a.k.a.) Avalon? Well here are the steps I took to play around with this new and hip technology:
- Create a fresh VirtualPC image with WindowsXP SP2. I read that you can also use Windows Server 2003 if you wish.
- Install Visual Studio 2005. I use Professional edition, but the beta's also work with the Visual Studio Express editions.
- Download the WinFX software developer kit at: http://msdn.microsoft.com/windowsvista/getthebeta/default.aspx
I've downloaded the WinFX RTC plus the VS2005 extensions. Note that if you want to install the VS2005 extensions you also need to download the Windows SDK beta. If you don't install the SDK the VS2005 extensions will show a message saying that you need to install the Windows SDK and then also make sure that you install the beta SDK, the regular SDK will not suffice! Feels like my WindowsXP machine is being turned into a Vista machine already
- Install the WinFx RTC download. The installer will want to download another 16MB of data, so make sure your VirtualPC environment has Internet access.
- Install the Windows SDK beta.
- Install the VS2005 Extensions package.
- Install the VS2005 Extensions for Windows Workflow Foundation. These are obviously optional for playing around with the WPF beta, but since we're setting up a play area we might as well get it complete.
Done? Okay, time to test to see if all is well.
Make a little test XAML application, it ofcourse has to be:
a) Use notepad to create a file called 'test.xaml' b) Copy code below into file. <Page xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"> <TextBlock>Hello World!</TextBlock> </Page>
c) Save d) Double click the file. e) Yeah! A real life XAML application.
I also tried placing this test file on my webserver ( http://www.develop-one.net/presentations/code/wfm/test.xaml ) but opening this URL results in a security exception. I'll look into that some more later. Probably still need to add this URL my Trusted sites.
I've just been confirmed as a speaker at the Software Developer Event, the 24th of March 2006 in Ede, The Netherlands. I'll be doing an exciting session about Windows Presentation Foundation, a.k.a. Avalon.
For more information read the session abstract below. Hope to see you there!
Working with Windows Presentation Foundation This introductory session about Windows Presentation Foundation, formerly known as Avalon, consists of two parts. The first part is about the WPF fundamentals. Here the developer will get 'a look under the hood' in order to get a better understanding of what is happening when developing a WPF application. The second part of the session looks at two tools that can be used to actually develop a WPF application and be productive while doing it, because who really wants to manually program XAML, right? The first tool we'll look at is codenamed 'Cider'. This tool allows a developer to create WinForm-like applications with WPF. The second tool is codenamed 'Sparkle' and is used for creating more Flash-like applications.
Tech Ed Europe has been moved back to the 6th of November and will be held in Barcelona instead of Amsterdam.
Great! Barcelona is a great place to visit.
I've been wondering whether the following would be possibe:
In .NET 1.1 create a class library with form A. Compile and copy the assembly to a .NET 2.0 machine. In .NET 2.0 create a form B that inherits from form A. Run form A in .NET 2.0.
This works, no problems.
In .NET 1.1 create a winapp with form A which has a button that triggers the following code:
object temp = Activator.CreateObjectFrom( "Test.dll", "Test.FormB" ).Unwrap(); Form f = (Form) temp; f.Show();
Compile and copy the assembly to a .NET 2.0 machine. In .NET 2.0 create a class library with form B. Compile the assembly. Start the winapp, click the button, et voila, the .NET 1.1 assembly will start the .NET 2.0 form.
Also works without problems 
Just giving all this a try has taken away quite a bit of doubt about whether this would work or not and means that in a GUI .NET 1.1 and .NET 2.0 work together quite nicely.
Follow this link to view the recent episode of MSDN TV where they discuss LINQ for VB.NET.
Overview Visual Basic 9.0 will offer radical improvements in its ability to work with data in all its forms: as objects, as XML, and as relational data. Paul Vick and Amanda Silver discuss the latest Customer Tech Preview of the next version of Visual Basic to hit the Web. It includes support for DLinq (language integrated query over relational data) and expanded editor support for query statements and integrated XML.
Just came across a deadlink on www.theserverside.net refering to a post by Kevin Jones about Embedded Resources in ASP.NET. Couldn't find the item on Kevin's blog, but a Google search brought me to http://haacked.com/archive/2005/04/29/2879.aspx which explains it pretty well.
Embedding Javascript in your assembly resource seems a great way to avoid deployment issues.
I just received a mail from my friend Lucas pointing out that some products are getting close to the end of the Microsoft Support Lifecycle.
The mainstream support for the 2000 editions of several products is ending in the near future, as detailed in the following table (for more information on Support Lifecycle, visit www.microsoft.com/lifecycle).
|
Commerce Server 2000 Standard Edition BizTalk Server 2000 Standard Edition BizTalk Server 2000 Enterprise Edition Host Integration Server 2000 Standard Edition
|
3/31/2006 6/30/2006 6/30/2006 12/31/2006
|
With generic in C# 2.0 life just become so much easier. Today I was impressed by the ease with which you can now sort a list of T.
Code below shows how with one method you can now implement a sort. This used to be much more complex! public class Person
{
public Person(string name)
{
this.Name = name;
}
public string Name;
}
class Demo
{
public List GetAllPersons()
{
List result = new List();
result.Add(new Person("Mark"));
result.Add(new Person("Dennis"));
result.Add(new Person("Duncan"));
result.Add(new Person("Jeremy"));
result.Sort(SortByName);
return result;
}
public static int SortByName( Person x, Person y )
{
return x.Name.CompareTo(y.Name);
}
}
I was reading my way through the Internet and came across some interesting stuff about Smart Client Architecture. It seems that the definition of a Smart Client is not so clear. On the Microsoft site it says:
Smart client (n) Definition: Smart clients are easily deployed and managed client applications that provide an adaptive, responsive and rich interactive experience by leveraging local resources and intelligently connecting to distributed data sources.
But then it shows the following picture:

As you can see there are two features that are unique to a Smart Client: a) Online/Offline support b) Device Adaptability Without these features a Smart Client is really nothing more than either a Thick or Thin Client.
Personally I feel that from an architectural point of view offline/online support is much more important than device adaptability. Therefore I think that the definition for a Smart Client should read:
Smart client (n) Definition: Smart clients are easily deployed and managed client applications that provide an adaptive, responsive and rich interactive experience in both an online and offline scenario, by leveraging local resources and intelligently connecting to distributed data sources.
More interesting reading on: The ServerSide.NET and Clemens Vaster's Blog.
I always wondered how some sites managed to get their little logo in my list of Favourites. Turns out it is really quite easy, just add a favicon.ico file to the root of your website. Internet Explorer will pick it up automagically.
If you happen to have a different browser you can try:
<link rel="icon" href="favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
Found it on Matthias Benkmann's website: http://www.winterdrache.de/freeware/png2ico/favicon.html
I've recently moved to the United States. To Lincoln, Maine to be exact. I've started a new company called Develop-One and with the start of a new company I think it also time for a new blog. I'll still run my old blog as a more personal account of my life in Maine, but anything to do with .NET, C#, Windows Vista, LINQ, WWF, WCF, WPF and every other technology that keeps me occupied in my life as a developer I will post about on this weblog.
Happy reading.
- Mark
|