SlideShare a Scribd company logo
1 of 66
Download to read offline
Exercises in Style
Crista Lopes
Available on Amazon
Ejercicios de estilo en la programación
PROGRAMMING STYLES
Rules and constraints in software construction
Programming Styles
⊳ Ways of expressing tasks
⊳ Exist and recur at all scales
⊳ Frozen in Programming
Languages
Why Are Styles Important?
⊳ Basic frames of reference for
solutions
• Like scaffolding
⊳ Common vocabularies
• It’s a cultural thing
⊳ Some better than others
• Depending on many things!
Programming Styles
How do you teach this?
Raymond Queneau
Queneau’s Exercises in Style
⊳ Metaphor
⊳ Surprises
⊳ Dream
⊳ Prognostication
⊳ Hesitation
⊳ Precision
⊳ Negativities
⊳ Asides
⊳ Anagrams
⊳ Logical analysis
⊳ Past
⊳ Present
⊳ …
⊳ (99)
Queneau’s “Styles”
⊳ Constraints
⊳ “A Void” (La Disparition)
by Georges Perec
• No letter ‘e’
Exercises in Programming Style
The story:
Term Frequency
given a text file,
output a list of the 25
most frequently-occurring
words, ordered by decreasing
frequency
Exercises in Programming Style
The story:
Term Frequency
given a text file,
output a list of the 25
most frequently-occurring
words, ordered by decreasing
frequency
mr - 786
elizabeth - 635
very - 488
darcy - 418
such - 395
mrs - 343
much - 329
more - 327
bennet - 323
bingley - 306
jane - 295
miss - 283
one - 275
know - 239
before - 229
herself - 227
though - 226
well - 224
never - 220
…
TFPride and Prejudice
STYLE #1
@cristalopes #style1 name
Ejercicios de estilo en la programación
# the global list of [word, frequency] pairs
word_freqs = []
# the list of stop words
with open('../stop_words.txt') as f:
stop_words = f.read().split(',')
stop_words.extend(list(string.ascii_lowercase))
for line in open(sys.argv[1]):
for c in line:
Style #1 Main Characteristics
⊳ No abstractions
⊳ No use of library functions
@cristalopes #style1 name
Style #1 Main Characteristics
⊳ No abstractions
⊳ No use of library functions
Brain-dump Style
@cristalopes #style1 name
STYLE #2
@cristalopes #style2 name
import re, string, sys
stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase))
words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops]
unique_words = list(set(words))
unique_words.sort(lambda x, y: cmp(words.count(y), words.count(x)))
print "n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]])
Credit: Laurie Tratt, Kings College London
import re, string, sys
stops = set(open("../stop_words.txt").read().split(",") +
list(string.ascii_lowercase))
words = [x.lower() for x in re.split("[^a-zA-Z]+",
open(sys.argv[1]).read())
if len(x) > 0 and x.lower() not in stops]
unique_words = list(set(words))
unique_words.sort(lambda x, y: cmp(words.count(y),
words.count(x)))
print "n".join(["%s - %s" % (x, words.count(x))
for x in unique_words[:25]])
import re, string, sys
stops = set(open("../stop_words.txt").read().split(",") +
list(string.ascii_lowercase))
words = [x.lower() for x in re.split("[^a-zA-Z]+",
open(sys.argv[1]).read())
if len(x) > 0 and x.lower() not in stops]
unique_words = list(set(words))
unique_words.sort(lambda x,y:cmp(words.count(y),
words.count(x)))
print "n".join(["%s - %s" % (x, words.count(x))
for x in unique_words[:25]])
Style #2 Main Characteristics
⊳ As few lines of code as possible
@cristalopes #style2 name
Style #2 Main Characteristics
⊳ As few lines of code as possible
Code Golf Style
@cristalopes #style2 name
Style #2 Main Characteristics
⊳ As few lines of code as possible
Try Hard Style
@cristalopes #style2 name
STYLE #3
@cristalopes #style3 name
Ejercicios de estilo en la programación
#
# Main
#
read_file(sys.argv[1])
filter_normalize()
scan()
rem_stop_words()
frequencies()
sort()
for tf in word_freqs[0:25]:
print tf[0], ' - ', tf[1]
def read_file(path):
def filter_normalize():
def scan():
def rem_stop_words():
def frequencies():
def sort():
data=[]
words=[]
freqs=[]
Style #3 Main Characteristics
⊳ Procedural abstractions
• maybe input, no output
⊳ Shared state
⊳ Larger problem solved by
applying procedures, one after
the other, changing the shared
state
@cristalopes #style3 name
Style #3 Main Characteristics
⊳ Procedural abstractions
• maybe input, no output
⊳ Shared state
⊳ Commands
Cook Book Style
@cristalopes #style3 name
STYLE #4
@cristalopes #style4 name
Ejercicios de estilo en la programación
#
# Main
#
wfreqs=st(fq(r(sc(n(fc(rf(sys.argv[1])))))))
for tf in wfreqs[0:25]:
print tf[0], ' - ', tf[1]
def read_file(path):
def filter(str_data):
def scan(str_data):
def rem_stop_words(wordl):
def frequencies(wordl):
def sort(word_freqs):
def normalize(str_data):
return ...
return ...
return ...
return ...
return ...
return ...
return ...
Style #4 Main Characteristics
⊳ Function abstractions
• f: Input  Output
⊳ No shared state
⊳ Function composition f º g
@cristalopes #style4 name
Style #4 Main Characteristics
⊳ Function abstractions
• f: Input  Output
⊳ No shared state
⊳ Function composition f º g
Chocolate Factory Style
Image credit: Nykamp DQ, From Math Insight. http://mathinsight.org/image/function machines composed
g
f
@cristalopes #style4 name
STYLE #5
@cristalopes #style5 name
Ejercicios de estilo en la programación
def read_file(path, func):
...
return func(…, normalize)
def filter_chars(data, func):
...
return func(…, scan)
def normalize(data, func):
...
return func(…,remove_stops)
# Main
w_freqs=read_file(sys.argv[1],
filter_chars)
for tf in w_freqs[0:25]:
print tf[0], ' - ', tf[1]
def scan(data, func):
...
return func(…, frequencies)
def remove_stops(data, func):
...
return func(…, sort)
Etc.
Style #5 Main Characteristics
⊳ Functions take one additional
parameter, f
• called at the end
• given what would normally be the
return value plus the next function
@cristalopes #style5 name
Style #5 Main Characteristics
⊳ Functions take one additional
parameter, f
• called at the end
• given what would normally be the
return value plus the next function
Crochet Style
@cristalopes #style5 name
STYLE #6
@cristalopes #style6 name
Ejercicios de estilo en la programación
class DataStorageManager(TFExercise):
class TFExercise():
class StopWordManager(TFExercise):
class WordFreqManager(TFExercise):
class WordFreqController(TFExercise):
# Main
WordFreqController(sys.argv[1]).run()
def words(self):
def info(self):
def info(self): def info(self):
def info(self):
def is_stop_word(self, word):
def inc_count(self, word):
def sorted(self):
def run(self):
Style #6 Main Characteristics
⊳ Things, things and more things!
• Capsules of data and procedures
⊳ Data is never accessed directly
⊳ Capsules can reappropriate
procedures from other capsules
@cristalopes #style6 name
Style #6 Main Characteristics
⊳ Things, things and more things!
• Capsules of data and procedures
⊳ Data is never accessed directly
⊳ Capsules can reappropriate
procedures from other capsules
@cristalopes #style6 name
Kingdom of Nouns Style
STYLE #7
@cristalopes #style7 name
Ejercicios de estilo en la programación
class DataStorageManager():
class StopWordManager():
class WordFrequencyManager():
class WordFrequencyController():
def dispatch(self, message):
def dispatch(self, message):
def dispatch(self, message):
def dispatch(self, message):
# Main
wfcntrl = WordFrequencyController()
wfcntrl.dispatch([‘init’,sys.argv[1]])
wfcntrl.dispatch([‘run’])
Style #7 Main Characteristics
⊳ (Similar to #6)
⊳ Capsules receive messages via
single receiving procedure
@cristalopes #style7 name
Style #7 Main Characteristics
⊳ (Similar to #6)
⊳ Capsules receive messages via
single receiving procedure
@cristalopes #style7 name
Letterbox Style
STYLE #8
@cristalopes #style8 name
Ejercicios de estilo en la programación
# Main
splits = map(split_words,
partition(read_file(sys.argv[1]), 200))
splits.insert(0, [])
word_freqs = sort(reduce(count_words, splits))
for tf in word_freqs[0:25]:
print tf[0], ' - ', tf[1]
def split_words(data_str)
"""
Takes a string (many lines), filters, normalizes to
lower case, scans for words, and filters the stop words.
Returns a list of pairs (word, 1), so
[(w1, 1), (w2, 1), ..., (wn, 1)]
"""
...
result = []
words = _rem_stop_words(_scan(_normalize(_filter(data_str))))
for w in words:
result.append((w, 1))
return result
def count_words(pairs_list_1, pairs_list_2)
"""
Takes two lists of pairs of the form
[(w1, 1), ...]
and returns a list of pairs [(w1, frequency), ...],
where frequency is the sum of all occurrences
"""
mapping = dict((k, v) for k, v in pairs_list_1)
for p in pairs_list_2:
if p[0] in mapping:
mapping[p[0]] += p[1]
else:
mapping[p[0]] = 1
return mapping.items()
Style #8 Main Characteristics
⊳ Two key abstractions:
map(f, chunks) and
reduce(g, results)
@cristalopes #style8 name
Style #8 Main Characteristics
⊳ Two key abstractions:
map(f, chunks) and
reduce(g, results)
@cristalopes #style8 name
Map-Reduce Style
STYLE #9
@cristalopes #style9 name
Ejercicios de estilo en la programación
# Main
connection = sqlite3.connect(':memory:')
create_db_schema(connection)
load_file_into_database(sys.argv[1], connection)
# Now, let's query
c = connection.cursor()
c.execute("SELECT value, COUNT(*) as C FROM words GROUP BY value ORDER BY C DESC")
for i in range(25):
row = c.fetchone()
if row != None:
print row[0] + ' - ' + str(row[1])
connection.close()
def create_db_schema(connection):
c = connection.cursor()
c.execute('''CREATE TABLE documents(id PRIMARY KEY AUTOINCREMENT, name)'''
c.execute('''CREATE TABLE words(id, doc_id, value)''')
c.execute('''CREATE TABLE characters(id, word_id, value)''')
connection.commit()
c.close()
# Now let's add data to the database
# Add the document itself to the database
c = connection.cursor()
c.execute("INSERT INTO documents (name) VALUES (?)", (path_to_f
c.execute("SELECT id from documents WHERE name=?", (path_to_fil
doc_id = c.fetchone()[0]
# Add the words to the database
c.execute("SELECT MAX(id) FROM words")
row = c.fetchone()
word_id = row[0]
if word_id == None:
word_id = 0
for w in words:
c.execute("INSERT INTO words VALUES (?, ?, ?)", (word_id, d
# Add the characters to the database
char_id = 0
for char in w:
c.execute("INSERT INTO characters VALUES (?, ?, ?)", (c
char_id += 1
word_id += 1
connection.commit()
c.close()
Style #9 Main Characteristics
⊳ Entities and relations between them
⊳ Query engine
• Declarative queries
@cristalopes #style9 name
Style #9 Main Characteristics
⊳ Entities and relations between them
⊳ Query engine
• Declarative queries
@cristalopes #style9 name
Tabular Style
Take Home
⊳ Many ways of solving problems
• Know them, assess them
⊳ Constraints are important for
communication
• Make them explicit
⊳ Don’t be hostage of one way of
doing things
Available on Amazon

More Related Content

What's hot

Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in REshwar Sai
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...PROIDEA
 
R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)Christopher Roach
 
Advanced geoprocessing with Python
Advanced geoprocessing with PythonAdvanced geoprocessing with Python
Advanced geoprocessing with PythonChad Cooper
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with RShareThis
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentalsMauro Palsgraaf
 
Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In ScalaKnoldus Inc.
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!priort
 

What's hot (15)

Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in R
 
R learning by examples
R learning by examplesR learning by examples
R learning by examples
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
 
R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)
 
Advanced geoprocessing with Python
Advanced geoprocessing with PythonAdvanced geoprocessing with Python
Advanced geoprocessing with Python
 
P2 2017 python_strings
P2 2017 python_stringsP2 2017 python_strings
P2 2017 python_strings
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
 
Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In Scala
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 

Similar to Ejercicios de estilo en la programación

Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching moduleSander Timmer
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming languageJulian Hyde
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slidejonycse
 
Introduction to R
Introduction to RIntroduction to R
Introduction to Ragnonchik
 
Cypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semanticsCypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semanticsopenCypher
 
Poetry with R -- Dissecting the code
Poetry with R -- Dissecting the codePoetry with R -- Dissecting the code
Poetry with R -- Dissecting the codePeter Solymos
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingAlberto Labarga
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Basic and logical implementation of r language
Basic and logical implementation of r language Basic and logical implementation of r language
Basic and logical implementation of r language Md. Mahedi Mahfuj
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In RRsquared Academy
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in rubyKoen Handekyn
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a MomentSergio Gil
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasGanesh Samarthyam
 

Similar to Ejercicios de estilo en la programación (20)

Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
 
R language introduction
R language introductionR language introduction
R language introduction
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Cypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semanticsCypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semantics
 
Poetry with R -- Dissecting the code
Poetry with R -- Dissecting the codePoetry with R -- Dissecting the code
Poetry with R -- Dissecting the code
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
R workshop
R workshopR workshop
R workshop
 
Python basic
Python basicPython basic
Python basic
 
Basic and logical implementation of r language
Basic and logical implementation of r language Basic and logical implementation of r language
Basic and logical implementation of r language
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In R
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
 

More from Software Guru

Hola Mundo del Internet de las Cosas
Hola Mundo del Internet de las CosasHola Mundo del Internet de las Cosas
Hola Mundo del Internet de las CosasSoftware Guru
 
Estructuras de datos avanzadas: Casos de uso reales
Estructuras de datos avanzadas: Casos de uso realesEstructuras de datos avanzadas: Casos de uso reales
Estructuras de datos avanzadas: Casos de uso realesSoftware Guru
 
Building bias-aware environments
Building bias-aware environmentsBuilding bias-aware environments
Building bias-aware environmentsSoftware Guru
 
El secreto para ser un desarrollador Senior
El secreto para ser un desarrollador SeniorEl secreto para ser un desarrollador Senior
El secreto para ser un desarrollador SeniorSoftware Guru
 
Cómo encontrar el trabajo remoto ideal
Cómo encontrar el trabajo remoto idealCómo encontrar el trabajo remoto ideal
Cómo encontrar el trabajo remoto idealSoftware Guru
 
Automatizando ideas con Apache Airflow
Automatizando ideas con Apache AirflowAutomatizando ideas con Apache Airflow
Automatizando ideas con Apache AirflowSoftware Guru
 
How thick data can improve big data analysis for business:
How thick data can improve big data analysis for business:How thick data can improve big data analysis for business:
How thick data can improve big data analysis for business:Software Guru
 
Introducción al machine learning
Introducción al machine learningIntroducción al machine learning
Introducción al machine learningSoftware Guru
 
Democratizando el uso de CoDi
Democratizando el uso de CoDiDemocratizando el uso de CoDi
Democratizando el uso de CoDiSoftware Guru
 
Gestionando la felicidad de los equipos con Management 3.0
Gestionando la felicidad de los equipos con Management 3.0Gestionando la felicidad de los equipos con Management 3.0
Gestionando la felicidad de los equipos con Management 3.0Software Guru
 
Taller: Creación de Componentes Web re-usables con StencilJS
Taller: Creación de Componentes Web re-usables con StencilJSTaller: Creación de Componentes Web re-usables con StencilJS
Taller: Creación de Componentes Web re-usables con StencilJSSoftware Guru
 
El camino del full stack developer (o como hacemos en SERTI para que no solo ...
El camino del full stack developer (o como hacemos en SERTI para que no solo ...El camino del full stack developer (o como hacemos en SERTI para que no solo ...
El camino del full stack developer (o como hacemos en SERTI para que no solo ...Software Guru
 
¿Qué significa ser un programador en Bitso?
¿Qué significa ser un programador en Bitso?¿Qué significa ser un programador en Bitso?
¿Qué significa ser un programador en Bitso?Software Guru
 
Colaboración efectiva entre desarrolladores del cliente y tu equipo.
Colaboración efectiva entre desarrolladores del cliente y tu equipo.Colaboración efectiva entre desarrolladores del cliente y tu equipo.
Colaboración efectiva entre desarrolladores del cliente y tu equipo.Software Guru
 
Pruebas de integración con Docker en Azure DevOps
Pruebas de integración con Docker en Azure DevOpsPruebas de integración con Docker en Azure DevOps
Pruebas de integración con Docker en Azure DevOpsSoftware Guru
 
Elixir + Elm: Usando lenguajes funcionales en servicios productivos
Elixir + Elm: Usando lenguajes funcionales en servicios productivosElixir + Elm: Usando lenguajes funcionales en servicios productivos
Elixir + Elm: Usando lenguajes funcionales en servicios productivosSoftware Guru
 
Así publicamos las apps de Spotify sin stress
Así publicamos las apps de Spotify sin stressAsí publicamos las apps de Spotify sin stress
Así publicamos las apps de Spotify sin stressSoftware Guru
 
Achieving Your Goals: 5 Tips to successfully achieve your goals
Achieving Your Goals: 5 Tips to successfully achieve your goalsAchieving Your Goals: 5 Tips to successfully achieve your goals
Achieving Your Goals: 5 Tips to successfully achieve your goalsSoftware Guru
 
Acciones de comunidades tech en tiempos del Covid19
Acciones de comunidades tech en tiempos del Covid19Acciones de comunidades tech en tiempos del Covid19
Acciones de comunidades tech en tiempos del Covid19Software Guru
 
De lo operativo a lo estratégico: un modelo de management de diseño
De lo operativo a lo estratégico: un modelo de management de diseñoDe lo operativo a lo estratégico: un modelo de management de diseño
De lo operativo a lo estratégico: un modelo de management de diseñoSoftware Guru
 

More from Software Guru (20)

Hola Mundo del Internet de las Cosas
Hola Mundo del Internet de las CosasHola Mundo del Internet de las Cosas
Hola Mundo del Internet de las Cosas
 
Estructuras de datos avanzadas: Casos de uso reales
Estructuras de datos avanzadas: Casos de uso realesEstructuras de datos avanzadas: Casos de uso reales
Estructuras de datos avanzadas: Casos de uso reales
 
Building bias-aware environments
Building bias-aware environmentsBuilding bias-aware environments
Building bias-aware environments
 
El secreto para ser un desarrollador Senior
El secreto para ser un desarrollador SeniorEl secreto para ser un desarrollador Senior
El secreto para ser un desarrollador Senior
 
Cómo encontrar el trabajo remoto ideal
Cómo encontrar el trabajo remoto idealCómo encontrar el trabajo remoto ideal
Cómo encontrar el trabajo remoto ideal
 
Automatizando ideas con Apache Airflow
Automatizando ideas con Apache AirflowAutomatizando ideas con Apache Airflow
Automatizando ideas con Apache Airflow
 
How thick data can improve big data analysis for business:
How thick data can improve big data analysis for business:How thick data can improve big data analysis for business:
How thick data can improve big data analysis for business:
 
Introducción al machine learning
Introducción al machine learningIntroducción al machine learning
Introducción al machine learning
 
Democratizando el uso de CoDi
Democratizando el uso de CoDiDemocratizando el uso de CoDi
Democratizando el uso de CoDi
 
Gestionando la felicidad de los equipos con Management 3.0
Gestionando la felicidad de los equipos con Management 3.0Gestionando la felicidad de los equipos con Management 3.0
Gestionando la felicidad de los equipos con Management 3.0
 
Taller: Creación de Componentes Web re-usables con StencilJS
Taller: Creación de Componentes Web re-usables con StencilJSTaller: Creación de Componentes Web re-usables con StencilJS
Taller: Creación de Componentes Web re-usables con StencilJS
 
El camino del full stack developer (o como hacemos en SERTI para que no solo ...
El camino del full stack developer (o como hacemos en SERTI para que no solo ...El camino del full stack developer (o como hacemos en SERTI para que no solo ...
El camino del full stack developer (o como hacemos en SERTI para que no solo ...
 
¿Qué significa ser un programador en Bitso?
¿Qué significa ser un programador en Bitso?¿Qué significa ser un programador en Bitso?
¿Qué significa ser un programador en Bitso?
 
Colaboración efectiva entre desarrolladores del cliente y tu equipo.
Colaboración efectiva entre desarrolladores del cliente y tu equipo.Colaboración efectiva entre desarrolladores del cliente y tu equipo.
Colaboración efectiva entre desarrolladores del cliente y tu equipo.
 
Pruebas de integración con Docker en Azure DevOps
Pruebas de integración con Docker en Azure DevOpsPruebas de integración con Docker en Azure DevOps
Pruebas de integración con Docker en Azure DevOps
 
Elixir + Elm: Usando lenguajes funcionales en servicios productivos
Elixir + Elm: Usando lenguajes funcionales en servicios productivosElixir + Elm: Usando lenguajes funcionales en servicios productivos
Elixir + Elm: Usando lenguajes funcionales en servicios productivos
 
Así publicamos las apps de Spotify sin stress
Así publicamos las apps de Spotify sin stressAsí publicamos las apps de Spotify sin stress
Así publicamos las apps de Spotify sin stress
 
Achieving Your Goals: 5 Tips to successfully achieve your goals
Achieving Your Goals: 5 Tips to successfully achieve your goalsAchieving Your Goals: 5 Tips to successfully achieve your goals
Achieving Your Goals: 5 Tips to successfully achieve your goals
 
Acciones de comunidades tech en tiempos del Covid19
Acciones de comunidades tech en tiempos del Covid19Acciones de comunidades tech en tiempos del Covid19
Acciones de comunidades tech en tiempos del Covid19
 
De lo operativo a lo estratégico: un modelo de management de diseño
De lo operativo a lo estratégico: un modelo de management de diseñoDe lo operativo a lo estratégico: un modelo de management de diseño
De lo operativo a lo estratégico: un modelo de management de diseño
 

Recently uploaded

Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 

Recently uploaded (20)

Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 

Ejercicios de estilo en la programación

  • 4. PROGRAMMING STYLES Rules and constraints in software construction
  • 5. Programming Styles ⊳ Ways of expressing tasks ⊳ Exist and recur at all scales ⊳ Frozen in Programming Languages
  • 6. Why Are Styles Important? ⊳ Basic frames of reference for solutions • Like scaffolding ⊳ Common vocabularies • It’s a cultural thing ⊳ Some better than others • Depending on many things!
  • 7. Programming Styles How do you teach this?
  • 9. Queneau’s Exercises in Style ⊳ Metaphor ⊳ Surprises ⊳ Dream ⊳ Prognostication ⊳ Hesitation ⊳ Precision ⊳ Negativities ⊳ Asides ⊳ Anagrams ⊳ Logical analysis ⊳ Past ⊳ Present ⊳ … ⊳ (99)
  • 10. Queneau’s “Styles” ⊳ Constraints ⊳ “A Void” (La Disparition) by Georges Perec • No letter ‘e’
  • 11. Exercises in Programming Style The story: Term Frequency given a text file, output a list of the 25 most frequently-occurring words, ordered by decreasing frequency
  • 12. Exercises in Programming Style The story: Term Frequency given a text file, output a list of the 25 most frequently-occurring words, ordered by decreasing frequency mr - 786 elizabeth - 635 very - 488 darcy - 418 such - 395 mrs - 343 much - 329 more - 327 bennet - 323 bingley - 306 jane - 295 miss - 283 one - 275 know - 239 before - 229 herself - 227 though - 226 well - 224 never - 220 … TFPride and Prejudice
  • 15. # the global list of [word, frequency] pairs word_freqs = [] # the list of stop words with open('../stop_words.txt') as f: stop_words = f.read().split(',') stop_words.extend(list(string.ascii_lowercase))
  • 16. for line in open(sys.argv[1]): for c in line:
  • 17. Style #1 Main Characteristics ⊳ No abstractions ⊳ No use of library functions @cristalopes #style1 name
  • 18. Style #1 Main Characteristics ⊳ No abstractions ⊳ No use of library functions Brain-dump Style @cristalopes #style1 name
  • 20. import re, string, sys stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase)) words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops] unique_words = list(set(words)) unique_words.sort(lambda x, y: cmp(words.count(y), words.count(x))) print "n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]]) Credit: Laurie Tratt, Kings College London
  • 21. import re, string, sys stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase)) words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops] unique_words = list(set(words)) unique_words.sort(lambda x, y: cmp(words.count(y), words.count(x))) print "n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]])
  • 22. import re, string, sys stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase)) words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops] unique_words = list(set(words)) unique_words.sort(lambda x,y:cmp(words.count(y), words.count(x))) print "n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]])
  • 23. Style #2 Main Characteristics ⊳ As few lines of code as possible @cristalopes #style2 name
  • 24. Style #2 Main Characteristics ⊳ As few lines of code as possible Code Golf Style @cristalopes #style2 name
  • 25. Style #2 Main Characteristics ⊳ As few lines of code as possible Try Hard Style @cristalopes #style2 name
  • 28. # # Main # read_file(sys.argv[1]) filter_normalize() scan() rem_stop_words() frequencies() sort() for tf in word_freqs[0:25]: print tf[0], ' - ', tf[1] def read_file(path): def filter_normalize(): def scan(): def rem_stop_words(): def frequencies(): def sort(): data=[] words=[] freqs=[]
  • 29. Style #3 Main Characteristics ⊳ Procedural abstractions • maybe input, no output ⊳ Shared state ⊳ Larger problem solved by applying procedures, one after the other, changing the shared state @cristalopes #style3 name
  • 30. Style #3 Main Characteristics ⊳ Procedural abstractions • maybe input, no output ⊳ Shared state ⊳ Commands Cook Book Style @cristalopes #style3 name
  • 33. # # Main # wfreqs=st(fq(r(sc(n(fc(rf(sys.argv[1]))))))) for tf in wfreqs[0:25]: print tf[0], ' - ', tf[1] def read_file(path): def filter(str_data): def scan(str_data): def rem_stop_words(wordl): def frequencies(wordl): def sort(word_freqs): def normalize(str_data): return ... return ... return ... return ... return ... return ... return ...
  • 34. Style #4 Main Characteristics ⊳ Function abstractions • f: Input  Output ⊳ No shared state ⊳ Function composition f º g @cristalopes #style4 name
  • 35. Style #4 Main Characteristics ⊳ Function abstractions • f: Input  Output ⊳ No shared state ⊳ Function composition f º g Chocolate Factory Style Image credit: Nykamp DQ, From Math Insight. http://mathinsight.org/image/function machines composed g f @cristalopes #style4 name
  • 38. def read_file(path, func): ... return func(…, normalize) def filter_chars(data, func): ... return func(…, scan) def normalize(data, func): ... return func(…,remove_stops) # Main w_freqs=read_file(sys.argv[1], filter_chars) for tf in w_freqs[0:25]: print tf[0], ' - ', tf[1] def scan(data, func): ... return func(…, frequencies) def remove_stops(data, func): ... return func(…, sort) Etc.
  • 39. Style #5 Main Characteristics ⊳ Functions take one additional parameter, f • called at the end • given what would normally be the return value plus the next function @cristalopes #style5 name
  • 40. Style #5 Main Characteristics ⊳ Functions take one additional parameter, f • called at the end • given what would normally be the return value plus the next function Crochet Style @cristalopes #style5 name
  • 43. class DataStorageManager(TFExercise): class TFExercise(): class StopWordManager(TFExercise): class WordFreqManager(TFExercise): class WordFreqController(TFExercise): # Main WordFreqController(sys.argv[1]).run() def words(self): def info(self): def info(self): def info(self): def info(self): def is_stop_word(self, word): def inc_count(self, word): def sorted(self): def run(self):
  • 44. Style #6 Main Characteristics ⊳ Things, things and more things! • Capsules of data and procedures ⊳ Data is never accessed directly ⊳ Capsules can reappropriate procedures from other capsules @cristalopes #style6 name
  • 45. Style #6 Main Characteristics ⊳ Things, things and more things! • Capsules of data and procedures ⊳ Data is never accessed directly ⊳ Capsules can reappropriate procedures from other capsules @cristalopes #style6 name Kingdom of Nouns Style
  • 48. class DataStorageManager(): class StopWordManager(): class WordFrequencyManager(): class WordFrequencyController(): def dispatch(self, message): def dispatch(self, message): def dispatch(self, message): def dispatch(self, message): # Main wfcntrl = WordFrequencyController() wfcntrl.dispatch([‘init’,sys.argv[1]]) wfcntrl.dispatch([‘run’])
  • 49. Style #7 Main Characteristics ⊳ (Similar to #6) ⊳ Capsules receive messages via single receiving procedure @cristalopes #style7 name
  • 50. Style #7 Main Characteristics ⊳ (Similar to #6) ⊳ Capsules receive messages via single receiving procedure @cristalopes #style7 name Letterbox Style
  • 53. # Main splits = map(split_words, partition(read_file(sys.argv[1]), 200)) splits.insert(0, []) word_freqs = sort(reduce(count_words, splits)) for tf in word_freqs[0:25]: print tf[0], ' - ', tf[1]
  • 54. def split_words(data_str) """ Takes a string (many lines), filters, normalizes to lower case, scans for words, and filters the stop words. Returns a list of pairs (word, 1), so [(w1, 1), (w2, 1), ..., (wn, 1)] """ ... result = [] words = _rem_stop_words(_scan(_normalize(_filter(data_str)))) for w in words: result.append((w, 1)) return result
  • 55. def count_words(pairs_list_1, pairs_list_2) """ Takes two lists of pairs of the form [(w1, 1), ...] and returns a list of pairs [(w1, frequency), ...], where frequency is the sum of all occurrences """ mapping = dict((k, v) for k, v in pairs_list_1) for p in pairs_list_2: if p[0] in mapping: mapping[p[0]] += p[1] else: mapping[p[0]] = 1 return mapping.items()
  • 56. Style #8 Main Characteristics ⊳ Two key abstractions: map(f, chunks) and reduce(g, results) @cristalopes #style8 name
  • 57. Style #8 Main Characteristics ⊳ Two key abstractions: map(f, chunks) and reduce(g, results) @cristalopes #style8 name Map-Reduce Style
  • 60. # Main connection = sqlite3.connect(':memory:') create_db_schema(connection) load_file_into_database(sys.argv[1], connection) # Now, let's query c = connection.cursor() c.execute("SELECT value, COUNT(*) as C FROM words GROUP BY value ORDER BY C DESC") for i in range(25): row = c.fetchone() if row != None: print row[0] + ' - ' + str(row[1]) connection.close()
  • 61. def create_db_schema(connection): c = connection.cursor() c.execute('''CREATE TABLE documents(id PRIMARY KEY AUTOINCREMENT, name)''' c.execute('''CREATE TABLE words(id, doc_id, value)''') c.execute('''CREATE TABLE characters(id, word_id, value)''') connection.commit() c.close()
  • 62. # Now let's add data to the database # Add the document itself to the database c = connection.cursor() c.execute("INSERT INTO documents (name) VALUES (?)", (path_to_f c.execute("SELECT id from documents WHERE name=?", (path_to_fil doc_id = c.fetchone()[0] # Add the words to the database c.execute("SELECT MAX(id) FROM words") row = c.fetchone() word_id = row[0] if word_id == None: word_id = 0 for w in words: c.execute("INSERT INTO words VALUES (?, ?, ?)", (word_id, d # Add the characters to the database char_id = 0 for char in w: c.execute("INSERT INTO characters VALUES (?, ?, ?)", (c char_id += 1 word_id += 1 connection.commit() c.close()
  • 63. Style #9 Main Characteristics ⊳ Entities and relations between them ⊳ Query engine • Declarative queries @cristalopes #style9 name
  • 64. Style #9 Main Characteristics ⊳ Entities and relations between them ⊳ Query engine • Declarative queries @cristalopes #style9 name Tabular Style
  • 65. Take Home ⊳ Many ways of solving problems • Know them, assess them ⊳ Constraints are important for communication • Make them explicit ⊳ Don’t be hostage of one way of doing things