wiki:Documentation/DevelopmentCenter/BestPractices

General Coding Best Practices

  • use Environment.NewLine instead of the string constant "\n"
  • use Path.Combine() instead of string concatenation (with \ or /) to combine directory and file names
  • use String.Join() instead of concatenating your strings manually
  • throw and catch specific exceptions, don't catch generic exceptions try { ... } catch(Exception ex) {}
  • use a finally block to make sure that the state of the program is consistent even when Exceptions are thrown
  • if the mouse pointer was changed, set the mouse pointer back to normal in a finally {... } block
  • use string.Empty instead of the string constant ""
  • use string.IsEmptyOrNull(a) instead of if(a!=null && a!="")
  • check for InvokeRequired in methods that manipulate GUI elements in controls
  • instantiate all objects of classes implementing IDisposable with the using(...) { ... } statement to make sure the object is disposed correctly
  • Types and the namespaces they are defined in should not be named similarly, e.g. HeuristicLab.Encodings.MyEncoding should not contain the equally named class MyEncoding.

Developing Operators

  • When defining ValueParameters inside an operator also include a public property that allows get and set access to the parameter's Value property.
  • Use interfaces instead of concrete classes (e.g. when implementing parameter properties expose an IValueParameter<T> instead of a ValueParameter<T>)
  • Use ValueLookupParameter<T> for parameters that may also be defined in another higher level context such as problem or algorithm
Last modified 2 years ago Last modified on 12/07/14 18:30:41