Groovy.v2
-
Upload
nicolas-bello-camilletti -
Category
Technology
-
view
543 -
download
0
description
Transcript of Groovy.v2
![Page 1: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/1.jpg)
Nicolás Bello Camilletti@nbellocam
![Page 2: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/2.jpg)
¿Que es Groovy?
![Page 3: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/3.jpg)
Esto era Groovy
![Page 4: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/4.jpg)
![Page 5: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/5.jpg)
Lenguaje ágil y dinámico para
la JVM
![Page 6: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/6.jpg)
Integración con Java
JVM
Java Groovy Scala …
![Page 7: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/7.jpg)
Curva de aprendizaje
casi nula
![Page 8: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/8.jpg)
![Page 9: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/9.jpg)
Facilita la escritura de
scripts
![Page 10: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/10.jpg)
Soporta Domain
Specific
Languages
![Page 11: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/11.jpg)
Fuertemente tipado
![Page 12: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/12.jpg)
Orientado a
objetos
![Page 13: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/13.jpg)
Duck Typing
![Page 14: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/14.jpg)
Historia
29/08/2003
Nacimiento
16/03/2004
Propuesta JSR 241
29/03/2004 Se
aprueba la JSR 241
02/01/2007 Versión
1.0
07/12/2007 Versión
1.5
Actualmente Versión
1.8.#y beta de
2
![Page 15: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/15.jpg)
Algunasparticularidades
![Page 16: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/16.jpg)
Variables
• Tipado estático– Escribiendo el tipo explícitamente
• Tipado dinámico– Utilizando la palabra reservada def
![Page 17: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/17.jpg)
Sistema de Tipos
• Numeros Enteros– Integer
– Long
– BigInteger
– Byte
– Short
• Punto flotante– BigDecimal
– Float
– Double
• Boolean
• Strings
• Colecciones
– List
– Map
– Set
• Rangos
• Expresiones Regulares
![Page 18: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/18.jpg)
Colecciones – Listas
![Page 19: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/19.jpg)
Colecciones - Maps
![Page 20: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/20.jpg)
Colecciones - Rangos
![Page 21: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/21.jpg)
Strings y GStrings
![Page 22: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/22.jpg)
Expresiones Regulares
![Page 23: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/23.jpg)
Groovy Truth
• Boolean• Cosas que son false– Colecciones vacías(listas, maps)– Iteradores y enumeradores sin mas
elementos– Strings vacios–Matchers de regex que no coinciden (=~)– Cero– null
![Page 24: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/24.jpg)
Métodos
![Page 25: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/25.jpg)
Closures (1)
• { [param1, param2 …] -> sentencia1; sentencia2... }
![Page 26: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/26.jpg)
Closures (2)
![Page 27: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/27.jpg)
Ciclos con closures (1)
• Each
• EachWithIndex
• Times
![Page 28: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/28.jpg)
Ciclos con closures (2)
• Collect
• FindAll
![Page 29: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/29.jpg)
Operadores (1)
• Colección*.operación Spread Operator
• objeto?.operación Safe Navigation
Operator
– Similar a:
![Page 30: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/30.jpg)
Operadores (2)
• objeto?:valorDefault Elvis Operator
def displayName = user.name ?: "Anonymous"
– Operador ternario equivalente
def displayName = user.name ? user.name :
"Anonymous“
![Page 31: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/31.jpg)
Orientación a Objetos
![Page 32: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/32.jpg)
GroovyBeans (1)
![Page 33: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/33.jpg)
GroovyBeans (2)
• Con access modifier – Field
• Sin access modifier– Field privado– Mas getter y setter públicos (una property)
• Se pueden sobreescribir
• Property final– Field privado como final– Solo getter
![Page 34: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/34.jpg)
Expando
![Page 35: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/35.jpg)
Implementando Interfaces con Map
![Page 36: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/36.jpg)
Domain Specific Languages
• Muy buen soporte
• Concepto de Builders
• Sobrecarga de operadores
• Closures como parámetros
• Y muchos mas…
![Page 37: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/37.jpg)
Soporte para Lenguajes de Marcado
![Page 38: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/38.jpg)
Diferencias con java
• Defaults imports
• == es equals
• Return opcional
• This en métodos estáticos para clase
• The Groovy way…
![Page 39: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/39.jpg)
Ejemplos
• Java
• Groovy
![Page 40: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/40.jpg)
Ejemplo concurrencia• Groovy
• Java
![Page 41: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/41.jpg)
Programación de GUI
• Wrapper de Swing Usa Builders
![Page 42: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/42.jpg)
Conclusiones
![Page 43: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/43.jpg)
![Page 44: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/44.jpg)
Usar Groovy en:
• Integración de componentes
• Modelos de negocio muy dinámicos
• Pruebas de concepto
• Proyectos rápidos y chicos
• Scripting
![Page 45: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/45.jpg)
No usar Groovy en:
• Algoritmos complejos
– Cálculos intensivos
• Manejo de grandes cantidades de datos
– Problema con creación de objetos por ser dinámico
• Sistemas con
– Requerimientos bien definidos
– Pocas posibilidades de evolución
• Proyectos muy grandes
![Page 46: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/46.jpg)
No trabajen
duro.
Trabajen de forma
inteligente!
![Page 48: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/48.jpg)
Pruébenlo!
![Page 49: Groovy.v2](https://reader033.fdocuments.co/reader033/viewer/2022060111/5562d7f6d8b42a6c498b51b6/html5/thumbnails/49.jpg)
Muchas Gracias!!!