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?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
"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.
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.