Top Banner
Client Undertow Quando boas práticas não são recomendadas.
22

Client undertow

Jul 09, 2015

Download

Technology

sidneyfilho
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Client undertow

Client UndertowQuando boas práticas não são

recomendadas.

Page 2: Client undertow

Sobre Mim• Desenvolvedor – Há 11 anos e contando…

• Arquiteto– 5 anos e contando…

• Empresário– 3 anos e contando…

Page 3: Client undertow

Velho desenvolvimento. Novos paradigmas.

Será que sabemos realmente o que

estamos fazendo?

Page 4: Client undertow

Vou contar um pouco do que funcionou para mim e que pode

funcionar para você também!

Page 5: Client undertow

Hum, vou fazer igual naquele CRUD é o mesmo pattern!

Page 6: Client undertow

Dois idiomas, mesmo pensamento?

C# JavascriptServidor Cliente

Tipagem Forte Tipagem Fraca

Estática Dinâmica

OOP Prototypal Inheritage

Higher-order Functions TRUE First-Class Functions

Page 7: Client undertow

Que droga! Porque esse IF não funciona?

Page 8: Client undertow

What The Fu…• '' == '0' // false• 0 == '' // true• 0 == '0' // true• false == 'false' // false• false == '0' // true• false == undefined // false• false == null // false• null == undefined // true• " \t\r\n " == 0 // true

Page 9: Client undertow

Sintaxe não é gosto pessoal!

return

{

ok: false

};

• OK p/ C#• UNDEFINED!

return {

ok: true

};

• OK p/ C#• OK p/ JavaScript

Page 10: Client undertow

Var or not Varfunction teste(){ y = 1; }

alert(y); // 1

function teste(){ var y = 1; }

alert(y); // undefined

Page 11: Client undertow

Funções são: objetos, arrays, …

function teste(){}

teste.id = 1;

teste[“nome”]=“abc”;

teste[0] = 12;

var t = new teste();

/* Javascript OK */

/* Nem preciso escrever aquí porque sabemos

que não funciona no C# */

Page 12: Client undertow

“Prefer object composition to class inheritance”

Gang of 4

Page 13: Client undertow

Prototypal Inheritancefunction object(o) { 

  function F(){} 

  F.prototype = o; 

  return new F(); 

var parent = {a: 1}; 

var child = object(parent); 

alert(child.a);  // 1 

alert(child.hasOwnProperty(“a”));  // false

Page 14: Client undertow

Mixinsvar Bolo={};

var ingrediente1 = {a: 1, b: 2, c: 3}; 

var ingrediente2 = {d: 4, e: 5, f: 6}; 

var ingrediente3 = {g: 7, h: 8, i: 9};

for(var item1 in ingrediente1)

    Bolo[item1] = ingrediente1[item1];

for(var item2 in ingrediente2)

    Bolo[item2] = ingrediente2[item2];

for(var item3 in ingrediente3)

    Bolo[item3] = ingrediente3[item3];

alert(Bolo.g) // 7

/* Bolo contém todas as 

propriedades dos 

ingredientes 1, 2, 3 */

Page 15: Client undertow

Closure

function outer(){

  var local = 1;

  return function(){

    return local;

  };

}

Bolo.prototype = ingrediente1;

Page 16: Client undertow

Namespaces// Criando um exemplo de System.Web.UI

var System = {}; 

System.Web = {}; 

System.Web.UI = {};

System.Web.UI.MeuPlugin={

    Factory:{

  add:function(obj){}

      remove:function(obj){}

  }

}

Page 17: Client undertow

One-Executing Anonymous Function

(function (i){

  alert(i);

})(10);

• Permite usar closure;

• Só funciona uma unica vez;

Page 18: Client undertow

Com tantos recursos novos e diferentes, precisamos

aprender a reaprender!

Page 19: Client undertow

Se você estivesse começando aprender a desenvolver hoje e optasse por Javascript,

suas soluções seriam as mesmas?

Page 20: Client undertow

Design Patterns

• Mixins• Closure• Modules

• Self-Overwriting• Augmentation• SuperMethods

• Package• Modules• Namespaces

Além dos tradicionais Observer, Factory, Iterator, Proxy, devido a capacidade desta linguagem podemos pensar em novos e possiveis, como:

Page 21: Client undertow

“Desenvolvimento de software é a arte de criar maquinas escrevendo poesias!”

- Sidney Lima FIlho

Page 22: Client undertow

Obrigado!