Skip to content
Snippets Groups Projects
Commit f0e006d4 authored by Ulf Hermann's avatar Ulf Hermann
Browse files

Add optional section about value type references

parent 37f4dbc6
No related branches found
No related tags found
No related merge requests found
......@@ -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."
]
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment