wiki:ProgrammingTips

Version 9 (modified by Matthäus Wander, 12 years ago) (diff)

added OpenXMLWriter

General

  • You can use Kaxaml or OpenXMLWriter to create plugin descriptions in XAML file format.
  • You can use the following PostBuild events which do not require adaption of the assembly name:
    SET outdir="$(ProjectDir)..\..\CrypWin\$(OutDir)"
    if exist %outdir% (
    	cd %outdir%
    	if not exist "./CrypPlugins" mkdir "./CrypPlugins"
    
    	del /S /Q /A:-S-R-H "$(TargetName)*.*"
    	copy "$(TargetDir)$(TargetName)*.*" "./CrypPlugins"
    
    	if not exist "./Data" mkdir "./Data"
    	if exist "$(TargetDir)Data" xcopy /Y /S "$(TargetDir)Data" "./Data"
    )
    
  • 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.
    */
    

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 Suite.
  • 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.

Review checklist

Structure and testing:

  • Is the class namespace Cryptool.Plugins.{NameOfPlugin}?
  • Is the chosen IPlugin subinterface meaningful?
  • Are the following identifier equal to each other?
    • Plugin name (attribute)
    • Project name (solution, directory)
    • Assembly Name (dll)
    • Main class (if applicable)
  • Is the AssemblyVersion set correctly?
  • Are the PostBuild events set? Are the assembly and any data files copied to destination directory?
  • Does the plugin compile? Does it initialize?
  • Is there a project sample? Does it work? Are there any exceptions or errors?
  • Are the types of the data properties meaningful? Are they compatible with interacting plugins?
  • Is the plugin included in ListOfPlugins?? Are the values up-to-date?

In-depth code review:

  • Is HasChanges in settings set correctly?
  • Is there a null query before each event call?
  • Are CryptoolStreams initialized and disposed correctly?
  • Is the progress kept up-to-date?
  • Are changes to output properties correctly announced?