Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I keep seeing this term being thrown around in blogs about frameworks. While I understand the difference between declarative and imperative programming, how does this apply specifically to UI? Why does there appear to be a special term for it? Are these different 'things'? If so, what is the alternative to Declarative UI and why would I want to use it?

share|improve this question
    
No, they're not different things. –  Telastyn Nov 2 '12 at 14:15
    
@Telastyn. Imperative and declarative are very different things. It is "what" vs "how". An HTML layout would be declarative. A sequence of drawing instructions would be imperative. –  mike30 Nov 2 '12 at 16:04
    
@mike: The OP asked if imperative/declarative UI was different from imperative/declarative programming. They're not. –  Telastyn Nov 2 '12 at 16:57
    
@Telastyn The OP is asking the difference between declarative UI and <foo> UI (such as "imperative UI"), and if an alternative to declarative UI even exists. –  Izkata Nov 3 '12 at 3:58

2 Answers 2

up vote 7 down vote accepted

"Declarative UI" means you describe in some kind of language what elements you need in your UI, and to some degree how they should look like, but you can leave out details like the exact position and visual style of the elements. For example, in HTML you can describe that you want an input field, but how and where this field will be placed at the UI is highly dependent on the browser you are using.

Today, the term is more often used for UI frameworks with a strict separation of the look of the UI from the behaviour, which means the code reacting to UI events. For example, using XAML, you declare the look of your UI in a specific XML dialect, but you implement the behaviour in separate program code.

share|improve this answer
    
Good answer. Nitpick: whether details like the "exact position" are specified or not, is orthogonal to the declarative/imperative divide. However, in practice the approach of letting the computer handle the details is more common in declarative systems (though I'm not sure why). –  sleske Nov 2 '12 at 23:00

Declarative UI is a UI that's designed in a declarative way (you describe what it should be like) rather than an imperative way (you code the steps to create it.) It's really nothing special or unusual; it's been around since at least the 1990s, when you had Visual Basic and Delphi with visual form designers that let you lay out the user interface of your program in an intuitive, WYSIWYG manner.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.