De lenguajes, estilo, arquitectura y bagatelas

Post on 22-Jul-2015

109 views 1 download

Transcript of De lenguajes, estilo, arquitectura y bagatelas

DynlangChile: Encuentro de Charlistas

Eduardo Díaz Cortés

@LNDS

http://www.lnds.net/

http://github.com/lnds

“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

¿Creadores de Universos?

De Lenguajes,

Estilo, Arquitectura y Bagatelas

Necessity is the mother

of invention.— Jonathan Swift

–Bjarne Stroustrup

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

Lenguajes

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

>

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

EVERY PROGRAM STARTS OFF WITH BUGS

ZX81-FORTH BY DAVID HUSBAND COPYRIGHT (c) 1983

: CTOF 9 * 5 / 32 + . ; OK

: FTOC 32 - 5 * 9 / . ; OK

77 FTOC

25 OK

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

–L. Peter Deutsch

“To Iterate is human, to recurse divine.”

Estilo

Tony HoareQuickSort, 1960

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

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

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

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

–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

Enterprise Application Architecture

VulnerabilidadM

icroservicios

Scripts perl

Multi Tier

Microservicios

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

Forma y Función

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

Un Ejemplo

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.

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.

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

Frameworks¡El framework no es la arquitectura!

Architecture Lost Years

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

DCI(Data, Context, Interaction)

Hexagonal Architecture

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.

Wikipedia

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

Bagatelas

23 de marzo 2015

Emmy Noether's 133rd Birthday

Teorema de Noether

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

correspondiente ley de conservación”.

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

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.

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

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;  

};

void g(Rectangle& r) {

r.SetWidth(5);

r.SetHeight(4);

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

}

Square s;

g(s);

"Principio de Noether (Aplicado a OOD)”

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

Conservación del Comportamiento

=> Diseño por Contrato

..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));

Lenguaje

=> Estilo

=> Simetría

=> Conservación

=> Arquitectura

gracias