SlideShare a Scribd company logo
1 of 39
Download to read offline
What have the
@nnotations done to
us?
@adamwarski
Kraków, 9-11 May 2018
PART 1
ABOUT ANNOTATIONS
@NNOTATIONS
▸ Introduced to Java in 2004
▸ Replaced xml programming
WHY @, IN THE FIRST PLACE?
▸ We need a way to express meta-data
▸ Describe classes, methods, fields (@Entity, @JsonProperty)
▸ Cross-cutting concerns (@Secure, @Transactional)
▸ Orchestrate the application (@Inject, @EnableWebMvc)
WHY @, IN THE FIRST PLACE?
▸ Easy to introduce, non-invasive
▸ Clearly separated
▸ Close to referenced elements
▸ Can be inspected statically & at run-time
MOST POPULAR != BEST
AS GOOD AS IT GETS IN JAVA <= 7
AN EMBEDDED MINI LANGUAGE,
INTERPRETED AT RUN-TIME
What @ really are?
ANNOTATION INTERPRETERS;
A RUN-TIME FOR THE DYNAMIC
LANGUAGE
What are containers?
WE PROGRAM THE CONTAINERS USING
ANNOTATIONS
What do we do?
PART 2
WHAT @ HAVE BECOME?
WHAT PATTERNS HAVE EMERGED?
@Functional

@Blockchain

@MachineLearning

@MicroService

@PleaseWork

public class DoesNotMatter {}
Fear of new ...()
MANUAL DEPENDENCY INJECTION
▸ Split object graph creation
▸ e.g. per-package, functionality
▸ package scope
▸ Create the objects how you want
▸ Reader vs writer convenience
Fear of public static void main()
STARTUP SEQUENCE
▸ Do you know how your JavaEE/Spring application starts?
▸ What happens and in what order?
▸ Reader vs writer convenience
CLASSPATH SCANNING
▸ a general mechanism to avoid main & new
▸ add a jar & it magically works
▸ very convenient for rapid bootstrapping
TRADE CERTAINTY & CONTROL
FAST & CONVENIENT BOOTSTRAP
for
EXPLORABILITY
Code should be easy to read

Easy to navigate
Understand what services are used, how and when

What's the ordering
Go-to-definition: best method to learn
META-DATA MAPPING
▸ Entities
▸ JSON
▸ HTTP endpoints
▸ ...
▸ Describe classes, methods and fields
TRANSFORMING A JAX-RS MAPPING
THE GOOD
‣ Meta-data separated from the business logic
‣ We can test the logic without the HTTP layer
‣ Readable code
‣ Automatically generate Swagger docs
THE BAD
‣ Is this the right combination of annotations? Maybe
something is missing?
‣ Where is the endpoint exposed?
‣ What are all the endpoints exposed at a given path?
‣ Are the JAX-RS annotations tested?
‣ Stringly-typed parameter references
WHAT IF ...
▸ The endpoint is represented as a Java value
▸ Separation & testability of business logic
maintained
▸ The description of the endpoint is also
testable
▸ Basing on Endpoint values, Swagger docs
could be generated
▸ Programmatically define endpoints
JUST LOOKING AT THE CODE, IT’S
CRYSTAL CLEAR WHAT’S HAPPENING
AND WHEN.
JUST USE JAVA! (OR A MORE ADVANCED JVM LANGUAGE OF YOUR CHOICE)
▸ Meta-data becomes first-class values
▸ A single language for code and meta-data
▸ Can be generated using:
▸ loops
▸ conditionals
▸ helper methods
STATIC VS DYNAMIC

IMAGINE THAT ...
▸ You don't have to copy ----------------->

to all entities
▸ Instead, loop over descriptions
@TableGenerator(

name="tab", 

initialValue=0, 

allocationSize=50)

@GeneratedValue(

strategy=GenerationType.TABLE,

generator="tab")

@Id
IF THAT'S NOT ENOUGH ...
▸ http://annotatiomania.com
▸ Jarek Ratajski's presentation

on the same subject
▸ composability:

@Retry + @Transactional?
PART 3
IS THIS JUST FANTASY?
OR DO PEOPLE ACTUALLY DO THAT?
SPARK (SPARKJAVA.COM)
JOOQ (JOOQ.ORG)
SPRING 5 (FUNCTIONAL WEB FRAMEWORK)
OTHERS?
▸ Scala
▸ macros & implicits
▸ Ceylon
▸ type-safe metamodel
PART 4
SUMMING UP
▸ Greats docs & integrations
▸ Learnable
▸ just as a separate language
▸ "Spring VM"
▸ teams can be efficient
▸ Local optimum
▸ As good as (pre-λ) Java gets
▸ Evolves in the same direction
SUMMARY
▸ Containers are interpreters for a "not very typesafe" language
▸ Instead: use a proper language, e.g. Java
▸ or Scala/Kotlin/Ceylon/...
▸ Don't fear! main() and new are OK
SUMMARY
▸ Writing a bit more code is OK, if that makes you:
▸ retain control
▸ more certain of what code does
▸ increase explorability
▸ Meta-data, descriptions, as first-class values
BLOG.SOFTWAREMILL.COM
THANK YOU!
@adamwarski

adam.warski@softwaremill.com

More Related Content

What's hot (16)

Javascript
JavascriptJavascript
Javascript
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
 
Introduction to the Actor Model
Introduction to the Actor ModelIntroduction to the Actor Model
Introduction to the Actor Model
 
Functional programing jargon
Functional programing jargonFunctional programing jargon
Functional programing jargon
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Appstate
AppstateAppstate
Appstate
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Actor Model & Reactive Manifesto
Actor Model & Reactive ManifestoActor Model & Reactive Manifesto
Actor Model & Reactive Manifesto
 
Java script
Java scriptJava script
Java script
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 
Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...
Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...
Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...
 
Javascript
JavascriptJavascript
Javascript
 
Rubyslava slides-26.09.2013
Rubyslava slides-26.09.2013Rubyslava slides-26.09.2013
Rubyslava slides-26.09.2013
 

Similar to What have the annotations done to us?

Better Testing Through Behaviour
Better Testing Through BehaviourBetter Testing Through Behaviour
Better Testing Through BehaviourTom Adams
 
Real Impact Testing Analysis For JVM
Real Impact Testing Analysis For JVMReal Impact Testing Analysis For JVM
Real Impact Testing Analysis For JVMRaquel Pau
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of JavascriptSamuel Abraham
 
Real Impact Testing Analysis for JVM developers
Real Impact Testing Analysis for JVM developersReal Impact Testing Analysis for JVM developers
Real Impact Testing Analysis for JVM developersRaquel Pau
 
CIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking ImplementationCIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking ImplementationGary Pamparà
 
Compass Framework
Compass FrameworkCompass Framework
Compass FrameworkLukas Vlcek
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your CodeNate Abele
 
Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0Nate Abele
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript TestingKissy Team
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to JavaSMIJava
 
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"GeeksLab Odessa
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Courseparveen837153
 
Java for android developers
Java for android developersJava for android developers
Java for android developersAly Abdelkareem
 
Create an architecture for web test automation
Create an architecture for web test automationCreate an architecture for web test automation
Create an architecture for web test automationElias Nogueira
 
Modern day jvm controversies
Modern day jvm controversiesModern day jvm controversies
Modern day jvm controversiesVictorSzoltysek
 

Similar to What have the annotations done to us? (20)

Better Testing Through Behaviour
Better Testing Through BehaviourBetter Testing Through Behaviour
Better Testing Through Behaviour
 
Reactjs
ReactjsReactjs
Reactjs
 
Real Impact Testing Analysis For JVM
Real Impact Testing Analysis For JVMReal Impact Testing Analysis For JVM
Real Impact Testing Analysis For JVM
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Real Impact Testing Analysis for JVM developers
Real Impact Testing Analysis for JVM developersReal Impact Testing Analysis for JVM developers
Real Impact Testing Analysis for JVM developers
 
CIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking ImplementationCIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking Implementation
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Java notes
Java notesJava notes
Java notes
 
Create an architecture for web test automation
Create an architecture for web test automationCreate an architecture for web test automation
Create an architecture for web test automation
 
Intro to react_v2
Intro to react_v2Intro to react_v2
Intro to react_v2
 
Modern day jvm controversies
Modern day jvm controversiesModern day jvm controversies
Modern day jvm controversies
 

More from Adam Warski

Hejdyk maleńka część mazur
Hejdyk maleńka część mazurHejdyk maleńka część mazur
Hejdyk maleńka część mazurAdam Warski
 
Slick eventsourcing
Slick eventsourcingSlick eventsourcing
Slick eventsourcingAdam Warski
 
Evaluating persistent, replicated message queues
Evaluating persistent, replicated message queuesEvaluating persistent, replicated message queues
Evaluating persistent, replicated message queuesAdam Warski
 
The no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkThe no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkAdam Warski
 
ElasticMQ: a fully asynchronous, Akka-based SQS server
ElasticMQ: a fully asynchronous, Akka-based SQS serverElasticMQ: a fully asynchronous, Akka-based SQS server
ElasticMQ: a fully asynchronous, Akka-based SQS serverAdam Warski
 
The ideal module system and the harsh reality
The ideal module system and the harsh realityThe ideal module system and the harsh reality
The ideal module system and the harsh realityAdam Warski
 
Recommendation systems with Mahout: introduction
Recommendation systems with Mahout: introductionRecommendation systems with Mahout: introduction
Recommendation systems with Mahout: introductionAdam Warski
 
CDI Portable Extensions
CDI Portable ExtensionsCDI Portable Extensions
CDI Portable ExtensionsAdam Warski
 

More from Adam Warski (9)

Hejdyk maleńka część mazur
Hejdyk maleńka część mazurHejdyk maleńka część mazur
Hejdyk maleńka część mazur
 
Slick eventsourcing
Slick eventsourcingSlick eventsourcing
Slick eventsourcing
 
Evaluating persistent, replicated message queues
Evaluating persistent, replicated message queuesEvaluating persistent, replicated message queues
Evaluating persistent, replicated message queues
 
The no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkThe no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection Framework
 
ElasticMQ: a fully asynchronous, Akka-based SQS server
ElasticMQ: a fully asynchronous, Akka-based SQS serverElasticMQ: a fully asynchronous, Akka-based SQS server
ElasticMQ: a fully asynchronous, Akka-based SQS server
 
The ideal module system and the harsh reality
The ideal module system and the harsh realityThe ideal module system and the harsh reality
The ideal module system and the harsh reality
 
Recommendation systems with Mahout: introduction
Recommendation systems with Mahout: introductionRecommendation systems with Mahout: introduction
Recommendation systems with Mahout: introduction
 
Scala Macros
Scala MacrosScala Macros
Scala Macros
 
CDI Portable Extensions
CDI Portable ExtensionsCDI Portable Extensions
CDI Portable Extensions
 

Recently uploaded

Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 

Recently uploaded (20)

Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 

What have the annotations done to us?

  • 1. What have the @nnotations done to us? @adamwarski Kraków, 9-11 May 2018
  • 2.
  • 4. @NNOTATIONS ▸ Introduced to Java in 2004 ▸ Replaced xml programming
  • 5. WHY @, IN THE FIRST PLACE? ▸ We need a way to express meta-data ▸ Describe classes, methods, fields (@Entity, @JsonProperty) ▸ Cross-cutting concerns (@Secure, @Transactional) ▸ Orchestrate the application (@Inject, @EnableWebMvc)
  • 6. WHY @, IN THE FIRST PLACE? ▸ Easy to introduce, non-invasive ▸ Clearly separated ▸ Close to referenced elements ▸ Can be inspected statically & at run-time
  • 8. AS GOOD AS IT GETS IN JAVA <= 7
  • 9. AN EMBEDDED MINI LANGUAGE, INTERPRETED AT RUN-TIME What @ really are?
  • 10. ANNOTATION INTERPRETERS; A RUN-TIME FOR THE DYNAMIC LANGUAGE What are containers?
  • 11. WE PROGRAM THE CONTAINERS USING ANNOTATIONS What do we do?
  • 12. PART 2 WHAT @ HAVE BECOME? WHAT PATTERNS HAVE EMERGED? @Functional
 @Blockchain
 @MachineLearning
 @MicroService
 @PleaseWork
 public class DoesNotMatter {}
  • 13. Fear of new ...()
  • 14.
  • 15. MANUAL DEPENDENCY INJECTION ▸ Split object graph creation ▸ e.g. per-package, functionality ▸ package scope ▸ Create the objects how you want ▸ Reader vs writer convenience
  • 16. Fear of public static void main()
  • 17.
  • 18. STARTUP SEQUENCE ▸ Do you know how your JavaEE/Spring application starts? ▸ What happens and in what order? ▸ Reader vs writer convenience
  • 19. CLASSPATH SCANNING ▸ a general mechanism to avoid main & new ▸ add a jar & it magically works ▸ very convenient for rapid bootstrapping
  • 20. TRADE CERTAINTY & CONTROL FAST & CONVENIENT BOOTSTRAP for
  • 21. EXPLORABILITY Code should be easy to read
 Easy to navigate Understand what services are used, how and when
 What's the ordering Go-to-definition: best method to learn
  • 22. META-DATA MAPPING ▸ Entities ▸ JSON ▸ HTTP endpoints ▸ ... ▸ Describe classes, methods and fields
  • 23. TRANSFORMING A JAX-RS MAPPING THE GOOD ‣ Meta-data separated from the business logic ‣ We can test the logic without the HTTP layer ‣ Readable code ‣ Automatically generate Swagger docs THE BAD ‣ Is this the right combination of annotations? Maybe something is missing? ‣ Where is the endpoint exposed? ‣ What are all the endpoints exposed at a given path? ‣ Are the JAX-RS annotations tested? ‣ Stringly-typed parameter references
  • 24. WHAT IF ... ▸ The endpoint is represented as a Java value ▸ Separation & testability of business logic maintained ▸ The description of the endpoint is also testable ▸ Basing on Endpoint values, Swagger docs could be generated ▸ Programmatically define endpoints
  • 25. JUST LOOKING AT THE CODE, IT’S CRYSTAL CLEAR WHAT’S HAPPENING AND WHEN.
  • 26. JUST USE JAVA! (OR A MORE ADVANCED JVM LANGUAGE OF YOUR CHOICE) ▸ Meta-data becomes first-class values ▸ A single language for code and meta-data ▸ Can be generated using: ▸ loops ▸ conditionals ▸ helper methods
  • 27. STATIC VS DYNAMIC
 IMAGINE THAT ... ▸ You don't have to copy ----------------->
 to all entities ▸ Instead, loop over descriptions @TableGenerator(
 name="tab", 
 initialValue=0, 
 allocationSize=50)
 @GeneratedValue(
 strategy=GenerationType.TABLE,
 generator="tab")
 @Id
  • 28. IF THAT'S NOT ENOUGH ... ▸ http://annotatiomania.com ▸ Jarek Ratajski's presentation
 on the same subject ▸ composability:
 @Retry + @Transactional?
  • 29. PART 3 IS THIS JUST FANTASY? OR DO PEOPLE ACTUALLY DO THAT?
  • 32. SPRING 5 (FUNCTIONAL WEB FRAMEWORK)
  • 33. OTHERS? ▸ Scala ▸ macros & implicits ▸ Ceylon ▸ type-safe metamodel
  • 35. ▸ Greats docs & integrations ▸ Learnable ▸ just as a separate language ▸ "Spring VM" ▸ teams can be efficient ▸ Local optimum ▸ As good as (pre-λ) Java gets ▸ Evolves in the same direction
  • 36. SUMMARY ▸ Containers are interpreters for a "not very typesafe" language ▸ Instead: use a proper language, e.g. Java ▸ or Scala/Kotlin/Ceylon/... ▸ Don't fear! main() and new are OK
  • 37. SUMMARY ▸ Writing a bit more code is OK, if that makes you: ▸ retain control ▸ more certain of what code does ▸ increase explorability ▸ Meta-data, descriptions, as first-class values