Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qtws23
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ulf Hermann
qtws23
Commits
f0e006d4
Commit
f0e006d4
authored
1 year ago
by
Ulf Hermann
Browse files
Options
Downloads
Patches
Plain Diff
Add optional section about value type references
parent
37f4dbc6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SlideDeck.qml
+133
-3
133 additions, 3 deletions
SlideDeck.qml
with
133 additions
and
3 deletions
SlideDeck.qml
+
133
−
3
View file @
f0e006d4
...
...
@@ -85,7 +85,7 @@ Presentation
}
Slide
{
centeredText
:
"
<b>Named value types<
/b><
br>Containers of value types
"
centeredText
:
"
<b>
Value types</b><br>
Named value types<br>Containers of value types
"
}
Slide
{
...
...
@@ -106,7 +106,7 @@ Presentation
title
:
"
Value types
"
content
:
[
"
are generally <b>passed by value</b>
"
,
"
but still act like objects in JavaScript
"
,
"
but still act like objects in JavaScript
(value type references!)
"
,
"
common subset of object-like and value-like operations is compiled to C++
"
,
"
need to be <b>default-constructible</b> and <b>copyable</b>
"
,
"
are implicitly created and copied often
"
,
...
...
@@ -117,6 +117,10 @@ Presentation
]
}
Slide
{
centeredText
:
"
Value types<br><b>Named value types</b><br>Containers of value types
"
}
Slide
{
title
:
"
Precondition: Follow best practices
"
content
:
[
...
...
@@ -277,7 +281,7 @@ Item {
}
Slide
{
centeredText
:
"
Named value types<br><b>Containers of value types</b>
"
centeredText
:
"
Value types<br>
Named value types<br><b>Containers of value types</b>
"
}
Slide
{
...
...
@@ -508,4 +512,130 @@ Column {
]
}
Slide
{
title
:
"
Value type references
"
contentWidth
:
width
/
2
content
:
[
"
What does this program print?
"
]
QmlCodeSection
{
text
:
`import QtQuick
Text {
font {
pixelSize: 24
bold: false
}
function evil(f: font) : font {
font.pixelSize = 12
return f
}
Component.onCompleted: {
var f = font
var g = evil(f);
g.bold = true
console.log(font.bold, f.bold, g.bold)
console.log(font.pixelSize, f.pixelSize,
g.pixelSize)
}
}`
}
}
Slide
{
title
:
"
Value type references
"
contentWidth
:
width
/
2
content
:
[
"
What does this program print?
"
,
"
true true true
"
,
"
12 12 12
"
,
"
Wat?!
"
,
"
In JavaScript everything is an object
"
,
"
You cannot store a <b>font</b> on the stack
"
,
"
You cannot pass a <b>font</b> as value
"
,
"
Therefore, <b>value type references</b>
"
,
]
QmlCodeSection
{
text
:
`import QtQuick
Text {
font {
pixelSize: 24
bold: false
}
function evil(f: font) : font {
font.pixelSize = 12
return f
}
Component.onCompleted: {
var f = font
var g = evil(f);
g.bold = true
console.log(font.bold, f.bold, g.bold)
console.log(font.pixelSize, f.pixelSize,
g.pixelSize)
}
}`
}
}
Slide
{
title
:
"
Value type references
"
contentWidth
:
width
/
2
content
:
[
"
In JavaScript everything is an object
"
,
"
<b>f</b> and <b>g</b> are <b>value type references</b>
"
,
"
Act as if font was an object
"
,
"
<b>Write back</b> any modification into <b>font</b>
"
,
"
<b>Read back</b> any modification from <b>font</b>
"
,
"
Magic! Aw...esome?...ful? Naughty!
"
]
QmlCodeSection
{
text
:
`import QtQuick
Text {
font {
pixelSize: 24
bold: false
}
function evil(f: font) : font {
font.pixelSize = 12
return f
}
Component.onCompleted: {
var f = font
var g = evil(f);
g.bold = true
console.log(font.bold, f.bold, g.bold)
console.log(font.pixelSize, f.pixelSize,
g.pixelSize)
}
}`
}
}
Slide
{
title
:
"
Value type references: safe subset
"
content
:
[
"
Only change value types in the statement that retrieves them
"
,
"
Pass value types only to pure functions
"
,
"
Explicitly re-load any value type references
"
,
"
after changing any property
"
,
"
after calling any impure function
"
,
"
Result: most of your QML code will be compiled to C++.
"
,
"
Except: qmlcachegen cannot identify pure functions, yet.
"
]
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment