Declarative versus Imperative programming

Marc Clifton added a nice introduction to declarative versus imperative programming.

Imperative programming (source) Describes computation in terms of a program state and statements that change the program state. Declarative programming (source) Gives the computer a list of instructions to execute in a particular order, declarative programming describes to the computer a set of conditions and lets the computer figure out how to satisfy them

Like Marc Clifton describes in the article, we are already using declarative techniques like resource files, config files, etc. Many libraries like FABRIQ, User Interface Process Application Block for .NET, log4net, etc. uses a XML file to describe a sort of workflow in a declarative way.

Therefore I try to use it where possible on every project. Certainly when it comes to making forms. I just hate the generated code inside the InitializeComponent of a form/control, it is more elegant, readable and maintainable by describing it in a declarative way. For example a menubar would look like this:

 <MENUBARITEM Text="Edit"> 
 <MENUITEMS> 
  <MENUBUTTONITEM Text="Cut" /> 
  <MENUBUTTONITEM Text="Copy" /> 
  <MENUBUTTONITEM Text="Paste" /> 
  ... 

instead of a bunch of statements that are needed for declaration, initialisation, setting properties and to composite the controls together. In this way it is also very hard to see the relationships between the objects!