wiki:ProgrammingTips

Version 16 (modified by Matthäus Wander, 11 years ago) (diff)

--

General

  • You can use Kaxaml or OpenXMLWriter to create plugin descriptions in XAML file format.
  • You can use the following short license header and change the first line:
    /*
       Copyright 2009 Erika Musterfrau, University of Morrowland
    
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
    
           http://www.apache.org/licenses/LICENSE-2.0
    
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
    */
    
  • You can use the plugin review checklist? to check yourself whether your plugin has clean code.
  • You can use FXCop to analyze your assemblies for convention violations and improvement hints. Sometimes FXCop may point to a defect but in most cases it will show style and beautification issues.
  • Microsoft has some useful Design Guidelines.

Performance

  • Avoid using IndexOf(...) in loops. It's a quite costly operation.
  • Avoid using exceptions for normal program flow. Exceptions shall be used for (exceptional) error conditions. Do not use exceptions for your regular program control (as additional return point or similar).
  • Profile your application with VS 2008 Team System (similar to VS2010 Ultimate).
  • Set unneeded static or member variables to null. In most situations the GC knows by itself how to clean up data. However when you keep references in static or member variables, it can't see that the data is unused.
  • Avoid editing strings in loops. String objects are immutable which means that each change requires the instantiation of a new object. Use StringBuilder instead.
  • Avoid plain strings as output property type to pass non-textual data. Strings may appear as general purpose data type which can be read easily by any plugin. However strings still require a custom parsing. Apart from not improving interoperability, you pay a performance penalty for the parsing expenses. Do you need a delimiter character to pass your information as string? If the answer is yes, do not use a string. Instead consider using an array, a set, a dictionary or similar.
  • Use the .NET Attribute [Conditional("DEBUG")] for debug methods which should not be called in the Release version. Inside a conditional method you can print a stacktrace, check debugging assertions or similar.