De lenguajes, estilo, arquitectura y bagatelas

52

Transcript of De lenguajes, estilo, arquitectura y bagatelas

Page 1: De lenguajes, estilo, arquitectura y bagatelas
Page 2: De lenguajes, estilo, arquitectura y bagatelas

DynlangChile: Encuentro de Charlistas

Page 3: De lenguajes, estilo, arquitectura y bagatelas

Eduardo Díaz Cortés

@LNDS

http://www.lnds.net/

http://github.com/lnds

Page 4: De lenguajes, estilo, arquitectura y bagatelas

“The computer programmer is a creator of universes for which he alone is responsible.

Universes of virtually unlimited complexity can be created in the form of computer programs.”

-- Joseph Weizenbaum, “Computer Power and Human Reason”

Creadores de Universos

Page 5: De lenguajes, estilo, arquitectura y bagatelas

¿Creadores de Universos?

Page 6: De lenguajes, estilo, arquitectura y bagatelas

De Lenguajes,

Estilo, Arquitectura y Bagatelas

Page 7: De lenguajes, estilo, arquitectura y bagatelas

Necessity is the mother

of invention.— Jonathan Swift

Page 8: De lenguajes, estilo, arquitectura y bagatelas

–Bjarne Stroustrup

“If someone claims to have the perfect programming language, he is either a fool or a salesman or both.”

Lenguajes

Page 9: De lenguajes, estilo, arquitectura y bagatelas
Page 10: De lenguajes, estilo, arquitectura y bagatelas

10 PRINT “INGRESE TEMPERATURA EN CELSIUS:” 20 INPUT C 30 LET F = (C * 9.0/5.0) + 32 40 PRINT “LA TEMPERATURA EN FARENHEIT ES:"+F

KRUN

>

Page 11: De lenguajes, estilo, arquitectura y bagatelas

http://www.worldofspectrum.org/ZX81BasicProgramming/

EVERY PROGRAM STARTS OFF WITH BUGS

Page 12: De lenguajes, estilo, arquitectura y bagatelas
Page 13: De lenguajes, estilo, arquitectura y bagatelas

ZX81-FORTH BY DAVID HUSBAND COPYRIGHT (c) 1983

: CTOF 9 * 5 / 32 + . ; OK

: FTOC 32 - 5 * 9 / . ; OK

77 FTOC

25 OK

Page 14: De lenguajes, estilo, arquitectura y bagatelas

FORTH- Reflection

- Extensibilidad y Modularidad

- "Programación concatenativa” (Monoid)

- Simetría (invarianza):

- Everything is a Word

- Word executes

- Words receives parameters exactly the same way another word

Page 15: De lenguajes, estilo, arquitectura y bagatelas
Page 16: De lenguajes, estilo, arquitectura y bagatelas
Page 17: De lenguajes, estilo, arquitectura y bagatelas
Page 18: De lenguajes, estilo, arquitectura y bagatelas

–L. Peter Deutsch

“To Iterate is human, to recurse divine.”

Estilo

Page 19: De lenguajes, estilo, arquitectura y bagatelas

Tony HoareQuickSort, 1960

Page 20: De lenguajes, estilo, arquitectura y bagatelas

QuickSort; COMMENT The recursive QUICKSORT procedure; PROCEDURE quickSort(data) from: (first) to: (last); VALUE first, last; INTEGER first, last; INTEGER ARRAY data; BEGIN INTEGER pivot, i, j, k; SWITCH ss := loop;

IF first LESS last THEN BEGIN pivot:=data[first]; j:=first; k:=last;

loop: FOR i:=0 WHILE data[j] LESS pivot AND j LESS last DO j:=j+1; FOR i:=0 WHILE data[k] GREQ pivot AND k GR first DO k:=k-1; IF j LESS k THEN BEGIN i:=data[j]; data[j]:=data[k]; data[k]:=i; GOTO loop; END;

quickSort(data, first, k); quickSort(data, k+1, last); END; END quickSort;

Fragmento ALGOL 60

Page 21: De lenguajes, estilo, arquitectura y bagatelas

Programming is complex because of the large number of conflicting objectives for each of our programming projects.

If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather than part of

Page 22: De lenguajes, estilo, arquitectura y bagatelas

qs :: (Ord a) => [a] -> [a]

qs [] = []

qs (x:xs) = (qs lesser) ++ [x] ++ (qs greater) where lesser = filter (< x) xs greater = filter (>= x) xs

QuickSort Haskell

Page 23: De lenguajes, estilo, arquitectura y bagatelas

El diseño de los lenguajes de programación

- The point of programming languages is to prevent our poor frail human brains from being overwhelmed by a mass of detail.

- Whereas designing programming languages is like designing chairs: it's all about dealing with human weaknesses.

"Five Questions About Language Design” - Paul Graham

Page 24: De lenguajes, estilo, arquitectura y bagatelas

–Alan Kay

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each

other, with no structural integrity, but just done by brute force and thousands of slaves..”

Arquitectura

Page 25: De lenguajes, estilo, arquitectura y bagatelas

Enterprise Application Architecture

VulnerabilidadM

icroservicios

Scripts perl

Multi Tier

Microservicios

Page 26: De lenguajes, estilo, arquitectura y bagatelas

ArquitecturaIt is the pervading law of all things organic and inorganic, of all things physical and metaphysical,of all things human and all things superhuman —of all true manifestations of the head, of the heart, of the soul— that the life is recognizable in its expression, that form ever follows function. This is the law.

Louis Sullivan The Tall Office Building Artistically Considered

Page 27: De lenguajes, estilo, arquitectura y bagatelas

Forma y Función

Forma, es lo que el sistema es, función es lo que el sistema hace

Page 28: De lenguajes, estilo, arquitectura y bagatelas

Un Ejemplo

Page 29: De lenguajes, estilo, arquitectura y bagatelas

La función- Queremos desarrollar un sistema que permita a las

personas indicar donde están y qué están haciendo en cada momento.

- Para esto los usuarios ingresarán su “Estado”, que corresponde a un mensaje breve que indica qué está haciendo en cada momento relevante.

- La idea es que otros puedan saber donde está y que está haciendo, pues es útil para coordinar las tareas de un equipo.

- Para indicar su estado las personas no necesariamente deberán tener acceso a un computador. Esa es la función.

Page 30: De lenguajes, estilo, arquitectura y bagatelas

La Forma- Para cumplir esta función, permitiremos que los usuarios

envíen sus mensajes de estado a un sitio central, y permitiremos que cualquiera pueda observar una linea de tiempo con los estados de cada uno de los participantes del sistema.

- Las personas que usen este sistema podrán elegir a quienes seguir, y podrán saber quienes les siguen.

- Como queremos acceso desde cualquier parte, permitiremos que los mensajes también puedan ser enviados vía SMS. Esto impone una limitación al mensaje de estado, que para ser compatible con todos los sistemas de mensajería por celular de la época, implica que el estado estará limitado a 140 caracteres.

Page 31: De lenguajes, estilo, arquitectura y bagatelas

Usaremos un sitio web para consultar la linea de tiempo de los demás participantes, y para elaborar nuestras listas de usuarios que nos interesa seguir, junto con consultar el estado de nuestros seguidores.

Con todo esto, podemos construir este sitio usando Ruby On Rails, en poco tiempo, y podemos publicar en la web.

Lo llamaremos Twitter.

El Producto

Page 32: De lenguajes, estilo, arquitectura y bagatelas
Page 33: De lenguajes, estilo, arquitectura y bagatelas

Frameworks¡El framework no es la arquitectura!

Page 34: De lenguajes, estilo, arquitectura y bagatelas

Architecture Lost Years

Uncle Bob Martin http://bit.ly/1CYOVp8

Page 35: De lenguajes, estilo, arquitectura y bagatelas
Page 36: De lenguajes, estilo, arquitectura y bagatelas
Page 37: De lenguajes, estilo, arquitectura y bagatelas

DCI(Data, Context, Interaction)

Page 38: De lenguajes, estilo, arquitectura y bagatelas

Hexagonal Architecture

Page 39: De lenguajes, estilo, arquitectura y bagatelas
Page 40: De lenguajes, estilo, arquitectura y bagatelas

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.

Page 41: De lenguajes, estilo, arquitectura y bagatelas

Wikipedia

“Bagatela: una composición musical ágil y corta, sin mayores pretensiones.”

Bagatelas

Page 42: De lenguajes, estilo, arquitectura y bagatelas

23 de marzo 2015

Emmy Noether's 133rd Birthday

Page 43: De lenguajes, estilo, arquitectura y bagatelas

Teorema de Noether

"Cualquier simetría diferenciable, proveniente de un sistema físico, tiene su

correspondiente ley de conservación”.

Page 44: De lenguajes, estilo, arquitectura y bagatelas

Simetría

En un sistema físico corresponde a una característica (observada o intrínseca) que permanece sin cambio ante una transformación

Por Teorema de Noether

Simetría del Espacio => Conservación del Momentum

Simetría del Tiempo => Conservación de la Energía

Page 45: De lenguajes, estilo, arquitectura y bagatelas

Principio de Sustitución de Liskov

(LSP)

Sea q (x) una propiedad comprobable acerca de los objetos x de tipo T.

Entonces q (y) debe ser verdad para los objetos y del tipo S donde S, es un subtipo de T.

Page 46: De lenguajes, estilo, arquitectura y bagatelas

void DrawShape(const Shape& s) {

if (typeid(s) == typeid(Square))

DrawSquare(static_cast<Square&>(s));

else if (typeid(s) == typeid(Circle))

DrawCircle(static_cast<Circle&>(s));

}

void DrawShape(const Shape& s) { s.draw() }

vs

Page 47: De lenguajes, estilo, arquitectura y bagatelas

class  Rectangle  {  

public:  

void  SetWidth(double  w)  {itsWidth=w;}  

void  SetHeight(double  h)  {itsHeight=w;}  

double  GetHeight()  const  {return  itsHeight;}  

double  GetWidth()  const  {return  itsWidth;}  

private:  

double  itsWidth;  

double  itsHeight;  

};

Page 48: De lenguajes, estilo, arquitectura y bagatelas

void g(Rectangle& r) {

r.SetWidth(5);

r.SetHeight(4);

assert(r.GetWidth() *r.GetHeight()) == 20);

}

Square s;

g(s);

Page 49: De lenguajes, estilo, arquitectura y bagatelas

"Principio de Noether (Aplicado a OOD)”

LSP => la relación ISA está asociada al comportamiento.

Conservación del Comportamiento

=> Diseño por Contrato

Page 50: De lenguajes, estilo, arquitectura y bagatelas

..when redefining a routine [in a derivative], you may only replace its precondition by a weaker one, and its postcondition by a stronger one.

postcond Rectangle::SetWidth(double w) assert((itsWidth == w) && (itsHeight == old.itsHeight));

Page 51: De lenguajes, estilo, arquitectura y bagatelas

Lenguaje

=> Estilo

=> Simetría

=> Conservación

=> Arquitectura

Page 52: De lenguajes, estilo, arquitectura y bagatelas

gracias