[Mono-devel-list] mono style guidelines

Miguel de Icaza miguel at ximian.com
Sun Mar 7 11:59:43 EST 2004


Hello,

I have updated the mcs/class/README file, but maybe we should move this
into mcs/CodingStyle.txt

> * What about the bracket style for Classes/ Namespaces? I would
> suggest:
>  
> namespace System
> {
>  [Serializable]
>  public class ApplicationException : Exception
>  {
>   // Constructors
>   public ApplicationException ()
>    : base (Locale.GetText ("An application exception has occurred."))
>   {
>   }
>  
> because I think it is the most readable way, however some classes also
> use:
>  
> namespace System {
>  [Serializable]
>  public class ApplicationException : Exception {
>   // Constructors
>   public ApplicationException ()
>    : base (Locale.GetText ("An application exception has occurred."))
>   {
>   }

Since namespaces occur very rarely, I do not have a particular opinion
on this one.  Either one works for me.

>  
> * Comments about what kind of content follows (like the //
> Constructors above):
>  Do we want to keep that? Put that in everywhere or leave as it is.
>  What to do for new classes?

I think it is good to separate the code:

	// 
	// Constructors
	//


> * Linebreaks: Should we do any linebreaks and if, at which column?
>  Currently some classes do linebreaks, some do none at all and some do
> linebreaks sometimes.
>  I would suggest not doing linebreaks unless a line gets terribly long
> (maybe more than 120 or 150 chars?)
>  80 chars seems just about impossible if we suggest using
> 8-space-tabs. The general code already starts
>  at charpos 32!

The compiler uses 134.  I think is a good limit for line breaks.


> * How to break lines?
>  
> public int RegSetValueEx (IntPtr keybase, string valuename, IntPtr
> reserved,
>  int type, ref int data, int datalength)
>  
> public int RegSetValueEx (IntPtr keybase, string valuename, IntPtr
> reserved,
>                           int type, ref int data, int datalength)

The later.

> * Another general suggestion: We should try to avoid having spaces at
> the end of lines or having spaces
>  in empty lines

Yes.

> * Should Error messages (or msgs in general) generally end with an
> "."? They sometimes do, sometimes don't.

They should, that is a bug.


> * What does an empty constructor/ method look like?:
> public Foo ()
> {
>  DoSomething();
> }
>  
> public Foo ()
> {
> }
>  
> public Foo () {}
>  
> public Foo ()
> {}

I have used all of them, but for consistency, I think we should use:

	public Foo ()
	{
	}

> I would suggest the first one because it is consistent with the rest.
> However I've also seen all three in mono.





More information about the Mono-devel-list mailing list