28
© Zühlke 2014 Programmers rejoice: QML makes business people understand Qt Developer Days 2014 | Hinrich Specht 2. September 2014 Folie 1

Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

  • Upload
    vuminh

  • View
    218

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Programmers rejoice: QML makes business people understand Qt Developer Days 2014 | Hinrich Specht 2. September 2014 Folie 1

Page 2: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

About me My company

Where I live

What I do

at work

Page 3: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Agenda Motivation A real life example The hurdles of DSL creation What Qt has to offer PresentationSystem demo Extending Qml‘s type system When to use Qml for DSL creation and when not

What is it all about?

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 3

Page 4: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

A common problem in software development

Qt Developer Days 2014 | Hinrich Specht

25. September 2014 Folie 4

#?=&f\ (%) You mean If(obj != NULL) { name=„Qt“ }?

Page 5: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

What if…

• Stakeholders and developers could share a common language?

• changes to the software could be made in that language, too?

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 5

Page 6: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

A real life example

2. September 2014 Qt Developer Days 2014 | Hinirch Specht Folie 6

Page 7: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

The heating system example. Before.

Qt Developer Days 2014 | Hinrich Specht 25. September 2014 Folie 7

Adjust requirements

Implementation

Build & Deploy

Rollout to test site

Gather data

Up to 4 weeks, only in winter

Page 8: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

The heating system example. After.

Qt Developer Days 2014 | Hinrich Specht 25. September 2014

Adjust requirements

Adjust software via DSL

Cont.Integration

Rollout to test site

Gather data

< 1 week

Folie 8

Page 9: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Why...

Qt Developer Days 2014 | Hinrich Specht

25. September 2014 Folie 9

…isn‘t there a DSL in every software project?

Page 10: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

DSLs are hard to develop

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

Folie 10

Formal definition

• Grammar

• Schema

• Metamodel

• Abstract Syntax

Tooling

• Parser

• Validator

• Compiler

• Editor / IDE

Page 11: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

DSL creation with XText

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

Folie 11

XText is a powerful, DSL-based language development framework Steps to create a DSL using Xtext: Textual definition of syntax and semantic model for your DSL.

Language: Grammar Configure generator that creates java packages and editor for

your DSL. Language: MWE2 Set up Maven builds for CI of your DSL Update Eclipse Use your DSL Not targeting Java? Use Xtend for code generation

Page 12: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Programming languages compared

Qt Developer Days 2014 | Hinrich Specht 25. September 2014 Folie 12

C, COBOL

C++, Java, C#

QML, WPF, Silverlight Object oriented, declarative, special purpose, Model driven

Procedure oriented, imperative

Object oriented, imperative,general purpose

Assembler Code Processor instruction set, no abstraction at all

Comes with an extensible type system!

Page 13: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

DSL creation with Qml – what Qt has to offer

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

• Custom types can be made available in Qml

• Types used are backed by C++ classes

• CodeCompletion for custom types immediately available in Creator

• Easy to learn

• Effort needed to create a (simple) DSL is low

• No other programming languages needed!

Folie 13

Page 14: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Extending the Qml type system

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

• Any custom types can be registered with QML‘s type system (but must inherit from QObject)

• Different forms of registration are available to define the runtime behaviour of your types: – Creatable types – Uncreatable types – Interfaces – Singletons

Folie 14

Page 15: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

The QmlPresentationSystem

• is a DSL for creating slide decks

• makes use of QML‘s extensible type system

• is easy to use (compared to programming a slide deck with C++ or any other general purpose language)

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 15

Page 16: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

How to use your own custom types in Qml

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 16

qmlRegisterType<YourType>("com.your.namespace", 1, 0, „QmlTypeName");

Q_PROPERTY(DataElementIds::EnDataElementIds identifier

READ getIdentifier MEMBER m_id)

Public class YourType : public Qobject {…}

1. Derive from QObject

3. Register type in Qml

2. Define Properties

Page 17: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

How to use your own custom types in Qml

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

YourType{

displayName: „YourInstanceName"

value: false

identifier: YourId

}

import com.your.namespace 1.0

4. Import custom namespace in Qml file

6. Ready to use custom type in Qml

5. Run qmake

Folie 17

Page 18: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Using singleton types

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

int qmlRegisterSingletonType(const char * uri, int versionMajor, int versionMinor, const char * typeName, QJSValue(* ) ( QQmlEngine *, QJSEngine * ) callback)

QObject and QJSValue types can be registered as singleton types. Registering types that are defined in C++:

Folie 18

int qmlRegisterSingletonType(const char * uri, int versionMajor, int versionMinor, const char * typeName, QObject *(* ) ( QQmlEngine *, QJSEngine * ) callback)

Page 19: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Using singleton types

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

int qmlRegisterSingletonType(const QUrl & url, const char * uri, int versionMajor, intversionMinor, const char * qmlName)

Folie 19

Registering types that are defined in Qml:

Page 20: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Using uncreatable types

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

int qmlRegisterUncreatableType(const char * uri, int versionMajor, int versionMinor, const char * qmlName, const QString & message)

Folie 20

Note: To use enums in Qml, they must be wrapped in a class.

Page 21: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Drawbacks you have to deal with

2. September 2014 Qt Developer Days 2014 | Hinrich Specht

• Mingling with QtQuick types and QObject properties

• No integrated code generator for creation of non-Qt-code

• Editor is not always as smart as it could be

• Fixed syntax

Folie 21

Page 22: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

See how it works

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 22

Page 23: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

The sample application

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 23

HardwareLayer

GPIOs

DataLayer

DataElements

DataSwitch

GpioMappings

Page 24: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

When is a Qml based DSL the right choice?

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 24

Page 25: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

What is a domain?

Qt Developer Days 2014 | Hinrich Specht 25. September 2014

Stakeholders‘ domains Your domains

Heating system

Drive control

Accounting

Routing

System composition

StateMachines

UIs

Data layer

Simply said: Everything is a domain

Folie 25

Page 26: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Think about a QML based DSL, when

Qt Developer Days 2014 | Hinrich Specht

25. September 2014

• other tools would require too much effort

• simple DSL features are needed

• no code generation is required

• the DSL will mainly be used to define static aspects

Folie 26

Page 27: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Think about using other tools

Qt Developer Days 2014 | Hinrich Specht 25. September 2014

• when you want your own syntax / semantics

• code generation for different languages is required

• when you want to have a clean DSL (without artifacts from QObject)

Folie 27

Page 28: Programmers rejoice: QML makes business people … rejoice: QML makes business people understand ... PresentationSystem demo ... •is a DSL for creating slide decks

© Zühlke 2014

Q&A / Discussion

2. September 2014 Qt Developer Days 2014 | Hinrich Specht Folie 28