- SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By...
Transcript of - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By...
![Page 1: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/1.jpg)
<codeware/>how to present code
![Page 2: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/2.jpg)
your slides are not your IDE
![Page 3: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/3.jpg)
$> not your console either
![Page 4: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/4.jpg)
here are five rules forpresenting code
![Page 5: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/5.jpg)
rule 1:$ use monospaced font$
![Page 6: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/6.jpg)
or
monospace
proportional
![Page 7: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/7.jpg)
monospace
proportional
fixed or variable
fixed or variable
![Page 8: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/8.jpg)
var power = function(base, exponent) { var result = 1; for (var count = 0; count < exponent; count++) result *= base; return result;};
var power = function(base, exponent) { var result = 1; for (var count = 0; count < exponent; count++) result *= base; return result;};
monospace
proportional
![Page 9: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/9.jpg)
var power = function(base, exponent) { var result = 1; for (var count = 0; count < exponent; count++) result *= base; return result;};
var power = function(base, exponent) { var result = 1; for (var count = 0; count < exponent; count++) result *= base; return result;};
monospace
proportional
![Page 10: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/10.jpg)
monospacemonospaced fontshave better readability when presenting code
proportional
![Page 11: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/11.jpg)
monospace
proportional it is harder to follow code with proportional fonts
monospaced fontshave better readability when presenting code
![Page 12: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/12.jpg)
use monospaced fontsfor code readability
![Page 13: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/13.jpg)
rule 2:$ use big fonts$
![Page 14: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/14.jpg)
presenting for a big audience?
$ this is not your desktop monitor$ font size should be bigger$
![Page 15: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/15.jpg)
I mean BIGGERthan your think
![Page 16: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/16.jpg)
I really mean BIGGER than your think
![Page 17: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/17.jpg)
console.log(“even BIGGER where possible”)
![Page 18: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/18.jpg)
console .log(“use line breaks”)
![Page 19: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/19.jpg)
<body> <button onClick=“coolFunction()” autofocus>too small</button></body>
![Page 20: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/20.jpg)
<body> <button onClick=“coolFunction()” autofocus> same but BIGGER </button></body>
![Page 21: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/21.jpg)
BIGGER is betterhow do you expect people in the back to read this?
![Page 22: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/22.jpg)
rule 3:$ smart syntax highlighting$
![Page 23: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/23.jpg)
this is not your IDEuse syntax highlighting only where needed
![Page 24: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/24.jpg)
this is not your IDEuse syntax highlighting only where needed
![Page 25: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/25.jpg)
Presenting code on your slides usually results in a wall of text.Highlight only the specific parts you want your audience to focus on.
![Page 26: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/26.jpg)
Presenting code on your slides usually results in a wall of text.Highlight only the specific parts you want your audience to focus on.
![Page 27: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/27.jpg)
Presenting code on your slides usually results in a wall of text.Highlight only the specific parts you want your audience to focus on.
![Page 28: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/28.jpg)
3 slides example - Ruby map function
1
2
3
![Page 29: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/29.jpg)
names = ['rey', 'fin', 'poe']
names.map! {|name| name.capitalize }
puts names
3 slides example - Ruby map function
1
2
3
![Page 30: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/30.jpg)
names = ['rey', 'fin', 'poe']
names.map! {|name| name.capitalize }
puts names
3 slides example - Ruby map function
1
2
3
![Page 31: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/31.jpg)
names = ['rey', 'fin', 'poe']
names.map! {|name| name.capitalize }
puts names
# output Rey Fin Poe
3 slides example - Ruby map function
1
2
3
![Page 32: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/32.jpg)
rule 4:$ using ellipsis…$
![Page 33: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/33.jpg)
import sys
from ortools.constraint_solver import pywrapcp
# By default, solve the 8x8 problem.n = 8 if len(sys.argv) < 2 else int(sys.argv[1])
# Creates the solver.solver = pywrapcp.Solver("n-queens")# Creates the variables.# The array index is the row, and the value is the column.queens = [solver.IntVar(0, n - 1, "x%i" % i) for i in range(n)]# Creates the constraints.
# All columns must be different.# (The "not on the same row" constraint is implicit from the array we're# using to store our variables; since no two elements of an array# can have the same index, there can be no queens with the same row.)solver.Add(solver.AllDifferent(queens))
# No two queens can be on the same diagonal.solver.Add(solver.AllDifferent([queens[i] + i for i in range(n)]))solver.Add(solver.AllDifferent([queens[i] - i for i in range(n)]))
db = solver.Phase(queens, solver.CHOOSE_MIN_SIZE_LOWEST_MAX, solver.ASSIGN_CENTER_VALUE)
solver.NewSearch(db)
# Iterates through the solutions, displaying each.num_solutions = 0while solver.NextSolution(): queen_columns = [int(queens[i].Value()) for i in range(n)]
# Displays the solution just computed. for i in range(n): for j in range(n): if queen_columns[i] == j: print "Q", else: print "_", print print num_solutions += 1
solver.EndSearch()
printprint "Solutions found:", num_solutionsprint "Time:", solver.WallTime(), "ms"
Solving the N-queens Problem
![Page 34: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/34.jpg)
import sys
from ortools.constraint_solver import pywrapcp
# By default, solve the 8x8 problem.n = 8 if len(sys.argv) < 2 else int(sys.argv[1])
# Creates the solver.solver = pywrapcp.Solver("n-queens")# Creates the variables.# The array index is the row, and the value is the column.queens = [solver.IntVar(0, n - 1, "x%i" % i) for i in range(n)]# Creates the constraints.
# All columns must be different.# (The "not on the same row" constraint is implicit from the array we're# using to store our variables; since no two elements of an array# can have the same index, there can be no queens with the same row.)solver.Add(solver.AllDifferent(queens))
# No two queens can be on the same diagonal.solver.Add(solver.AllDifferent([queens[i] + i for i in range(n)]))solver.Add(solver.AllDifferent([queens[i] - i for i in range(n)]))
db = solver.Phase(queens, solver.CHOOSE_MIN_SIZE_LOWEST_MAX, solver.ASSIGN_CENTER_VALUE)
solver.NewSearch(db)
# Iterates through the solutions, displaying each.num_solutions = 0while solver.NextSolution(): queen_columns = [int(queens[i].Value()) for i in range(n)]
# Displays the solution just computed. for i in range(n): for j in range(n): if queen_columns[i] == j: print "Q", else: print "_", print print num_solutions += 1
solver.EndSearch()
printprint "Solutions found:", num_solutionsprint "Time:", solver.WallTime(), "ms"
Solving the N-queens Problem
what’s the point in presenting all you code if people can’t follow?
![Page 35: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/35.jpg)
import sys
from ortools.constraint_solver import pywrapcp
# By default, solve the 8x8 problem.n = 8 if len(sys.argv) < 2 else int(sys.argv[1])
# Creates the solver.solver = pywrapcp.Solver("n-queens")# Creates the variables.# The array index is the row, and the value is the column.queens = [solver.IntVar(0, n - 1, "x%i" % i) for i in range(n)]# Creates the constraints.
# All columns must be different.# (The "not on the same row" constraint is implicit from the array we're# using to store our variables; since no two elements of an array# can have the same index, there can be no queens with the same row.)solver.Add(solver.AllDifferent(queens))
# No two queens can be on the same diagonal.solver.Add(solver.AllDifferent([queens[i] + i for i in range(n)]))solver.Add(solver.AllDifferent([queens[i] - i for i in range(n)]))
db = solver.Phase(queens, solver.CHOOSE_MIN_SIZE_LOWEST_MAX, solver.ASSIGN_CENTER_VALUE)
solver.NewSearch(db)
# Iterates through the solutions, displaying each.num_solutions = 0while solver.NextSolution(): queen_columns = [int(queens[i].Value()) for i in range(n)]
# Displays the solution just computed. for i in range(n): for j in range(n): if queen_columns[i] == j: print "Q", else: print "_", print print num_solutions += 1
solver.EndSearch()
printprint "Solutions found:", num_solutionsprint "Time:", solver.WallTime(), "ms"
Solving the N-queens Problem
keep just the relevant code
![Page 36: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/36.jpg)
import sys
from ortools.constraint_solver import pywrapcp
# By default, solve the 8x8 problem.n = 8 if len(sys.argv) < 2 else int(sys.argv[1])
# Creates the solver.solver = pywrapcp.Solver("n-queens")# Creates the variables.# The array index is the row, and the value is the column.queens = [solver.IntVar(0, n - 1, "x%i" % i) for i in range(n)]# Creates the constraints.
# All columns must be different.# (The "not on the same row" constraint is implicit from the array we're# using to store our variables; since no two elements of an array# can have the same index, there can be no queens with the same row.)solver.Add(solver.AllDifferent(queens))
# No two queens can be on the same diagonal.solver.Add(solver.AllDifferent([queens[i] + i for i in range(n)]))solver.Add(solver.AllDifferent([queens[i] - i for i in range(n)]))
db = solver.Phase(queens, solver.CHOOSE_MIN_SIZE_LOWEST_MAX, solver.ASSIGN_CENTER_VALUE)
solver.NewSearch(db)
# Iterates through the solutions, displaying each.num_solutions = 0while solver.NextSolution(): queen_columns = [int(queens[i].Value()) for i in range(n)]
# Displays the solution just computed. for i in range(n): for j in range(n): if queen_columns[i] == j: print "Q", else: print "_", print print num_solutions += 1
solver.EndSearch()
printprint "Solutions found:", num_solutionsprint "Time:", solver.WallTime(), "ms"
Solving the N-queens Problem
use ellipsis…
![Page 37: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/37.jpg)
...
# Creates the solver.solver = pywrapcp.Solver("n-queens")...
# Iterates through the solutions, displaying each.num_solutions = 0while solver.NextSolution(): queen_columns = [int(queens[i].Value()) for i in range(n)]
# Displays the solution just computed. for i in range(n): for j in range(n): if queen_columns[i] == j: print "Q", else: print "_", print print num_solutions += 1
solver.EndSearch()
...
Solving the N-queens Problem
![Page 38: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/38.jpg)
...
# Creates the solver.solver = pywrapcp.Solver("n-queens")...
# Iterates through the solutions, displaying each.num_solutions = 0while solver.NextSolution(): queen_columns = [int(queens[i].Value()) for i in range(n)]
# Displays the solution just computed. for i in range(n): for j in range(n): if queen_columns[i] == j: print "Q", else: print "_", print print num_solutions += 1
solver.EndSearch()
...
Solving the N-queens Problem
the focus is now on the algorithm not the boilerplate
![Page 39: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/39.jpg)
rule 5:$ use screen annotation$
![Page 40: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/40.jpg)
do you want to focus your audience’s attention on a specific area in the screen?
![Page 41: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/41.jpg)
thinking of using a laser pointer?
![Page 42: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/42.jpg)
do you expect your audience to track this?
![Page 43: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/43.jpg)
always create slides as if you are the person sitting in the last row of the conference hall.use screen annotations.
![Page 44: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/44.jpg)
always create slides as if you are the person sitting in the last row of the conference hall.use screen annotations.
![Page 45: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/45.jpg)
always create slides as if you are the person sitting in the last row of the conference hall.use screen annotations.
![Page 46: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/46.jpg)
always create slides as if you are the person sitting in the last row of the conference hall.use screen annotations.
![Page 47: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/47.jpg)
putting it all together$ ECMAScript 2015 Promise example$
![Page 48: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/48.jpg)
putting it all together$ ECMAScript 2015 Promise example$
the next slides will introduce the ECMAScript 2015 Promise Object
![Page 49: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/49.jpg)
fetchGraphData(graphName, function(error, graphData)) { if (error) { // handle error } // ... renderGraph(graphData, function(error)) { if (error) { // handle error } // ... notifyClients(msg, result, function(error, response)) { if (error) { // handle error } // ... }); });}); Typical JS code results with
many nested callbacks
![Page 50: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/50.jpg)
fetchGraphData(graphName, function(error, graphData)) { if (error) { // handle error } // ... renderGraph(graphData, function(error)) { if (error) { // handle error } // ... notifyClients(msg, result, function(error, response)) { if (error) { // handle error } // ... }); });}); makes it hard to follow
![Page 51: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/51.jpg)
fetchGraphData(graphName, function(error, graphData)) { if (error) { // handle error } // ... renderGraph(graphData, function(error)) { if (error) { // handle error } // ... notifyClients(msg, result, function(error, response)) { if (error) { // handle error } // ... }); });}); error handling is duplicated
![Page 52: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/52.jpg)
ECMAScript 2015 Promiseto the rescue!
![Page 53: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/53.jpg)
function fetchGraphData(graphName) { return new Promise(function(resolve, reject)) { let request = new XMLHttpRequest(); ...
// XMLHttpRequest to server request.open(‘GET’, ‘http://example.com', true); request.onload = function() { if (request.status == 200) { resolve(request.response); } else { reject(new Error(request.status)); } };});
The Promise object is used for deferred and asynchronous computations
![Page 54: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/54.jpg)
function fetchGraphData(graphName) { return new Promise(function(resolve, reject)) { let request = new XMLHttpRequest(); ...
// XMLHttpRequest to server request.open(‘GET’, ‘http://example.com', true); request.onload = function() { if (request.status == 200) { resolve(request.response); } else { reject(new Error(request.status)); } };});
resolve is called once operation has completed successfully
![Page 55: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/55.jpg)
function fetchGraphData(graphName) { return new Promise(function(resolve, reject)) { let request = new XMLHttpRequest(); ...
// XMLHttpRequest to server request.open(‘GET’, ‘http://example.com', true); request.onload = function() { if (request.status == 200) { resolve(request.response); } else { reject(new Error(request.status)); } };});
reject is called if the operation has been rejected
![Page 56: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/56.jpg)
fetchGraphData(graphName) .then(renderGraph) .then(notifyClients) .catch(function(error)) { console.log(“Error:”, error) });
Calling a Promise
Promise code is easy to read
![Page 57: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/57.jpg)
fetchGraphData(graphName) .then(renderGraph) .then(notifyClients) .catch(function(error)) { console.log(“Error:”, error) });
you can nest multiple Promise calls
Calling a Promise
![Page 58: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/58.jpg)
fetchGraphData(graphName) .then(renderGraph) .then(notifyClients) .catch(function(error)) { console.log(“Error:”, error) });
Calling a Promise
one error handling call
![Page 59: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/59.jpg)
remember! your slides are not your IDE
![Page 60: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/60.jpg)
1
codeware - 5 rules
2 3
4 5
![Page 61: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/61.jpg)
codeware - 5 rules
2 3
4 5
monospacedfont
![Page 62: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/62.jpg)
codeware - 5 rules
3
4 5
monospacedfont BIG
![Page 63: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/63.jpg)
codeware - 5 rules
4 5
monospacedfont BIG
smart syntax
highlighting
![Page 64: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/64.jpg)
codeware - 5 rules
5
monospacedfont BIG
smart syntax
highlighting
ellipsis...
![Page 65: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/65.jpg)
monospacedfont
codeware - 5 rules
BIGsmart syntax
highlighting
ellipsis...screen
annotation
![Page 66: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/66.jpg)
CreditsThe Noun Project: Check by useiconic.com Close by Thomas Drach
N-queens problem: OR-tools solution to the N-queens problem. Inspired by Hakan Kjellerstrand's solution at http://www.hakank.org/google_or_tools/, which is licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
https://developers.google.com/optimization/puzzles/queens#python
![Page 67: - SQA Days · 2018. 5. 20. · import sys from ortools.constraint_solver import pywrapcp # By default, solve the 8x8 problem. n = 8 if len(sys.argv) < 2 else](https://reader035.fdocuments.us/reader035/viewer/2022070213/610a1cb590d8a178040ec768/html5/thumbnails/67.jpg)
for more tips follow me on twitter and slideshare