CSharp
From eqqon
(Difference between revisions)
(→C# Articles) |
|||
Line 4: | Line 4: | ||
{{ArticleTeaser|pagelink=[[Double Dispatch Mechanism]]|iconlink={{clickpic|Double Dispatch Mechanism|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|headline=the Visitor Pattern|intro=Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution.}} | {{ArticleTeaser|pagelink=[[Double Dispatch Mechanism]]|iconlink={{clickpic|Double Dispatch Mechanism|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|headline=the Visitor Pattern|intro=Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution.}} | ||
- | {{ArticleTeaser|pagelink=[[Events]]|intro=An event is just an accessor (+=, -=) to a field holding a MulticastDelegate. The difference between a publicly accessible delegate field and an event are that you cannot overwrite the existing registered delegates, only append or remove. You also cannot reset the private event handler field to null from outside.}} | + | {{ArticleTeaser|pagelink=[[Events]]|iconlink={{clickpic|Events|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=An event is just an accessor (+=, -=) to a field holding a MulticastDelegate. The difference between a publicly accessible delegate field and an event are that you cannot overwrite the existing registered delegates, only append or remove. You also cannot reset the private event handler field to null from outside.}} |
- | {{ArticleTeaser|pagelink=[[IDisposable]]|intro=Objects that implement IDisposable can be used in the using statement. After the block ends, the object's Dispose-method is guaranteed to be called. Note: The object's destructor is not guaranteed to be called immediately.}} | + | {{ArticleTeaser|pagelink=[[IDisposable]]|iconlink={{clickpic|IDisposable|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=Objects that implement IDisposable can be used in the using statement. After the block ends, the object's Dispose-method is guaranteed to be called. Note: The object's destructor is not guaranteed to be called immediately.}} |
- | {{ArticleTeaser|pagelink=[[Navigating in Exception Stack Traces in Visual C-Sharp]]|intro=Today I wrote a nice little debug helper function called PrintException. It prints the relevant informations about an exception and its inner exceptions to the output recursively. The clue is, that it does this in a format that is understood by the error parser of Microsoft Visual Studio. So if you get an exception you can easily navigate to the source locations by clicking on the lines in the printed stacktrace. It also prints inner exceptions recursively with increasing indent for better readability.}} | + | {{ArticleTeaser|pagelink=[[Navigating in Exception Stack Traces in Visual C-Sharp]]|iconlink={{clickpic|Navigating in Exception Stack Traces in Visual C-Sharp|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=Today I wrote a nice little debug helper function called PrintException. It prints the relevant informations about an exception and its inner exceptions to the output recursively. The clue is, that it does this in a format that is understood by the error parser of Microsoft Visual Studio. So if you get an exception you can easily navigate to the source locations by clicking on the lines in the printed stacktrace. It also prints inner exceptions recursively with increasing indent for better readability.}} |
- | {{ArticleTeaser|pagelink=[[Preventing Recursive Events]]|intro=Events that cause each other to be fired recursively are usually a problem when two classes need to sync data. In large programs these recursive call chains can be quite long and thus a recursion might not be expected when firing some event. The recursion ends in a StackOverflowException. There are many possibilities to resolve such a problem. The easiest one is to introduce a boolean locking field which prevents reentrancy.}} | + | {{ArticleTeaser|pagelink=[[Preventing Recursive Events]]|iconlink={{clickpic|Preventing Recursive Events|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=Events that cause each other to be fired recursively are usually a problem when two classes need to sync data. In large programs these recursive call chains can be quite long and thus a recursion might not be expected when firing some event. The recursion ends in a StackOverflowException. There are many possibilities to resolve such a problem. The easiest one is to introduce a boolean locking field which prevents reentrancy.}} |
- | {{ArticleTeaser|pagelink=[[Ruby-like instance variable syntax in C-Sharp]]|intro=Although I am very impressed by C#, Ruby is still my favorite programming language because of it's clean design and unreached flexibility. One of the things I like about Ruby is its way to mark instance variables (in Ruby's terminology) or member variables / fields (in C# terminology). They are prefixed with the @-sign. This makes code very easy to read. To get the same effect most C# programmers rely on a kind of Hungarian style notation which means prefixing with m_. Today I discovered that the C# compiler allows the @-sign as prefix for identifiers. This is useful if you need to name an identifier e.g. a variable like a keyword. How often have I been forced to unwillingly name variables which contain a class-object klass or _class when programming in Ruby. So this is really a nice feature of C#, isn't it?}} | + | {{ArticleTeaser|pagelink=[[Ruby-like instance variable syntax in C-Sharp]]|iconlink={{clickpic|Ruby-like instance variable syntax in C-Sharp|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=Although I am very impressed by C#, Ruby is still my favorite programming language because of it's clean design and unreached flexibility. One of the things I like about Ruby is its way to mark instance variables (in Ruby's terminology) or member variables / fields (in C# terminology). They are prefixed with the @-sign. This makes code very easy to read. To get the same effect most C# programmers rely on a kind of Hungarian style notation which means prefixing with m_. Today I discovered that the C# compiler allows the @-sign as prefix for identifiers. This is useful if you need to name an identifier e.g. a variable like a keyword. How often have I been forced to unwillingly name variables which contain a class-object klass or _class when programming in Ruby. So this is really a nice feature of C#, isn't it?}} |
- | {{ArticleTeaser|pagelink=[[SQLite and CSharp]]|intro=The easiest way for an application to set up a database back-end is SQLite. Here is a small sample that creates a table, inserts some data and queries them back in C#. We use LiteX which is a nice .Net wrapper for SQLite 3.}} | + | {{ArticleTeaser|pagelink=[[SQLite and CSharp]]|iconlink={{clickpic|SQLite and CSharp|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=The easiest way for an application to set up a database back-end is SQLite. Here is a small sample that creates a table, inserts some data and queries them back in C#. We use LiteX which is a nice .Net wrapper for SQLite 3.}} |
- | {{ArticleTeaser|pagelink=[[Streaming between Threads or Processes]]|intro=To let one thread send data to other threads without interfering with them we combined a Queue with an AutoResetEvent in our Stream class. The stream maintains it's own receiver thread which sleeps (without polling) until some token is available. Then the OnReceive event is fired which executes the processing routines without delaying the sender. This decouples the sender and the receiver's execution contexts from each other which is needed for realtime applications. For optimal efficiency the generic Queue<T> has been chosen to avoid a lot of boxing and unboxing operations.}} | + | {{ArticleTeaser|pagelink=[[Streaming between Threads or Processes]]|iconlink={{clickpic|Streaming between Threads or Processes|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=To let one thread send data to other threads without interfering with them we combined a Queue with an AutoResetEvent in our Stream class. The stream maintains it's own receiver thread which sleeps (without polling) until some token is available. Then the OnReceive event is fired which executes the processing routines without delaying the sender. This decouples the sender and the receiver's execution contexts from each other which is needed for realtime applications. For optimal efficiency the generic Queue<T> has been chosen to avoid a lot of boxing and unboxing operations.}} |
- | {{ArticleTeaser|pagelink=[[Using (special use in C-Sharp)]]|intro=Apart from including namespaces in C# the keyword using is also overloaded with another meaning related to IDisposable.}} | + | {{ArticleTeaser|pagelink=[[Using (special use in C-Sharp)]]|iconlink={{clickpic|Using (special use in C-Sharp)|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=Apart from including namespaces in C# the keyword using is also overloaded with another meaning related to IDisposable.}} |
- | {{ArticleTeaser|pagelink=[[Visitor Pattern]]|intro=Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution.}} | + | {{ArticleTeaser|pagelink=[[Visitor Pattern]]|iconlink={{clickpic|Visitor Pattern|http://www.eqqon.com/images/thumb/d/df/CSharp.jpg/32px-CSharp.jpg}}|intro=Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution.}} |
[[:Category:CSharp]] | [[:Category:CSharp]] |
Revision as of 20:59, 2 January 2009
C# Articles
Double Dispatch Mechanism - the Visitor Pattern
Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution. Read Double Dispatch Mechanism ...
An event is just an accessor (+=, -=) to a field holding a MulticastDelegate. The difference between a publicly accessible delegate field and an event are that you cannot overwrite the existing registered delegates, only append or remove. You also cannot reset the private event handler field to null from outside. Read Events ...
Objects that implement IDisposable can be used in the using statement. After the block ends, the object's Dispose-method is guaranteed to be called. Note: The object's destructor is not guaranteed to be called immediately. Read IDisposable ...
Today I wrote a nice little debug helper function called PrintException. It prints the relevant informations about an exception and its inner exceptions to the output recursively. The clue is, that it does this in a format that is understood by the error parser of Microsoft Visual Studio. So if you get an exception you can easily navigate to the source locations by clicking on the lines in the printed stacktrace. It also prints inner exceptions recursively with increasing indent for better readability. Read Navigating in Exception Stack Traces in Visual C-Sharp ...
Events that cause each other to be fired recursively are usually a problem when two classes need to sync data. In large programs these recursive call chains can be quite long and thus a recursion might not be expected when firing some event. The recursion ends in a StackOverflowException. There are many possibilities to resolve such a problem. The easiest one is to introduce a boolean locking field which prevents reentrancy. Read Preventing Recursive Events ...
Although I am very impressed by C#, Ruby is still my favorite programming language because of it's clean design and unreached flexibility. One of the things I like about Ruby is its way to mark instance variables (in Ruby's terminology) or member variables / fields (in C# terminology). They are prefixed with the @-sign. This makes code very easy to read. To get the same effect most C# programmers rely on a kind of Hungarian style notation which means prefixing with m_. Today I discovered that the C# compiler allows the @-sign as prefix for identifiers. This is useful if you need to name an identifier e.g. a variable like a keyword. How often have I been forced to unwillingly name variables which contain a class-object klass or _class when programming in Ruby. So this is really a nice feature of C#, isn't it? Read Ruby-like instance variable syntax in C-Sharp ...
The easiest way for an application to set up a database back-end is SQLite. Here is a small sample that creates a table, inserts some data and queries them back in C#. We use LiteX which is a nice .Net wrapper for SQLite 3. Read SQLite and CSharp ...
To let one thread send data to other threads without interfering with them we combined a Queue with an AutoResetEvent in our Stream class. The stream maintains it's own receiver thread which sleeps (without polling) until some token is available. Then the OnReceive event is fired which executes the processing routines without delaying the sender. This decouples the sender and the receiver's execution contexts from each other which is needed for realtime applications. For optimal efficiency the generic Queue<T> has been chosen to avoid a lot of boxing and unboxing operations. Read Streaming between Threads or Processes ...
Apart from including namespaces in C# the keyword using is also overloaded with another meaning related to IDisposable. Read Using (special use in C-Sharp) ...
Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution. Read Visitor Pattern ...
External C# Links
|
|
|
|