SlideShare uma empresa Scribd logo
1 de 73
Syntactic Salt and Sugar



James Gould
Alex Holmes
Verisign
205
Alex




       2
Jim




      3
Introduction




               4
Format

          Discuss 5 Syntactic Elements
> >




          Lead discussion of each Element
              Introduce newer Elements
      – – –




              Identify Good
              Identify Bad
          Participation is encouraged!
>




                                            5
AGENDA

> DSL
> Project Lambda
> AOP 2
> CDI
> Grab Bag




                   6
AGENDA

> DSL
> Project Lambda
        2
> AOP
> CDI
> Grab Bag




                   7
omain specific language
Noun:   a computer programming language
        of limited expressiveness focused on
        a particular domain.
Rich languages
Domain specific language
DSL examples




  ELECT * FROM STATION WHERE LAT_N > 39.7;
Domain model
Grammatical Elements of a DSL
                           operators +
  verbs        nouns       separators

  deposit       account     () {} [] . -> => =
  withdraw      amount          < > ! ~ ? : ==
                                ++ || -- *=
                                <<< % ^ ; ,
                                %= && >= -1
                                >>>= // #
Internal DSL


  An internal DSL is a DSL
  represented within the syntax of
  a general-purpose language.
  It's a stylized use of that
  language for a domain-specific     Excerpt from Martin
                                     Fowler’s book “Domain
  purpose.                           Specific Languages”,
                                     published by Addison-
                                     Wesley
Java internal DSL




                    15
Java internal DSL
External DSL


   An external DSL is a domain-
   specific language represented in a
   separate language to the main
   programming language it's
   working with. This language may
   use a custom syntax, or it may       Excerpt from Martin
                                        Fowler’s book “Domain
   follow the syntax of another         Specific Languages”,
                                        published by Addison-
                                        Wesley
   representation such as XML.
External DSL for ATM


  d -> :a(0.95) :chk(12345)

    What do “d”, “a” and “chk” represent?
    What’s with the obfuscated syntax?
    Where is the language documented?
    YALTL – Yet another language to learn
Just call me Sherlock
Re-worked DSL grammar




   deposit amount 0.95
           into checking 12345
DSL Sugar


 diomatic way to communicate with domain experts

 an be used by non-programmers

 elf-documenting




                                                   21
DSL Salt


 SL syntax can quickly become salty

 o you really need a DSL?

 upporting a DSL is labor-intensive




                                      22
AGENDA

> DSL
> Project Lambda
        2
> AOP
> CDI
> Grab Bag




                   23
Project Lambda : Introduction


> Included in Java 8
> Defined in JSR-335
  – Lambda Expressions
  – Default Methods




                                24
Project Lambda : Lambda Expressions

public class Calculator {
    ublic class Calculator {
     static interface Calculate {
          int calc(int op1, int op2);
         static interface Calculate {
     }

              int calc(int op1, int op2);
     public static void main(String... args) {
         } Calculate addition = (op1, op2) -> op1 + op2;



         public static void main(String... args) {
          System.out.println("Addition = " + addition.calc(10, 20));

             Calculate addition = new Calculate() {
          Calculate multiply = (op1, op2) -> op1 * op2;

                    public int calc(int op1, int op2) {

          System.out.println("Multiply = " + multiply.calc(10, 20));
                       return op1 + op2;}};
     }
}             System.out.println("Addition = " + addition.calc(10, 20));   25
Project Lambda : Type Targeting


> How “Calculate addition = (op1, op2) -> op1 + op2;” works?
  – Type expression is inferred by type expected in context
  – Calculate is a Functional Interface
  – Expression compatible to Function Interface
     Interface is Functional Interface
     Expression has same number of parameters
     Expression return is compatible
     Expression exception thrown is allowed by Interface
> Lambda’s are strongly typed

                                                            26
Project Lambda : Type Targeting Sample

 ublic class HelloWorld {



     public static void main(String... args) throws Exception {

          Callable<Void> helloCall =

               () -> {System.out.println("Hello World!"); return null;};

          Runnable helloRun =

               () -> {System.out.println("Hello World!");};

                                                                           27


          helloCall.call();
Lambda’s and Collections



 raditional iteration:   ewritten for lambda’s:


 or (Car c : cars) {     ars.forEach(c -> c.setColor(RED));


    c.setColor(RED);     arallelized:


                         ars.parallel()

                            .forEach(c -> c.setColor(RED));
                                                         28
Project Lambda : Lambda Expression Sugar


 nonymous addition = (op1, op2)in aop1 + op2;
 Calculate Inner Classes done -> clean way
  Calculate addition = new Calculate() {
               public int calc(int op1, int op2) {
                     return op1 + op2;
               }};

 atches feature of other languages
     C#, C++, Ruby, Python, JavaScript, …
   Take advantage of multicore processors
     Mark Reinhold – “the real reason is multicore
 processors; the best way to handle them is with     29


 Lambda”
Project Lambda : Lambda Expression Salt


 ark Reinhold – “Some would say adding
 Lambda expressions is just to keep up with the
 cool kids, and there’s some truth in that”

 ava as a Object Oriented language

 o you want Anonymous Inner Classes on
 steroids?

 ack of code clarity

                                                  30
Project Lambda : Default Methods
 nterface A {

     void execute() default {

          System.out.println("A.execute()");

     }




 lass ClassA implements A {




 lassA classA = new ClassA();                  31
Project Lambda : Default Methods
 nterface A {

     void execute() default {

          System.out.println("A.execute()");

     }



 nterface B extends A {

     void execute() default {

          System.out.println(“B.execute()");
                                               32

     }
Project Lambda : Default Methods
 nterface A {

     void execute() default {

          System.out.println("A.execute()");

     }



 nterface B {

     void execute() default {

          System.out.println(“B.execute()");

     }



 lass ClassHuh implements A, B {                                  33



                                               void execute() {
Project Lambda : Default Methods and Lambda
 nterface A {

     void execute() default {

          System.out.println("A.execute()");

     }



 nterface B extends A {

     void execute() default {

          System.out.println(“B.execute()");

     }

  void execute2();
                                               34



 nterface C extends A, B {}
Project Lambda : Default Methods Sugar


 inally able to add code to interfaces!




                                          35
Project Lambda : Default Methods Salt


 dding multiple inheritance to Java

 ixing Default Methods and Lambda Expressions
 adds more confusion




                                                36
AGENDA

> DSL
> Project Lambda
        2
> AOP
> CDI
> Grab Bag




                   37
AOP 2 : Introduction



          spect Oriented Programming (AOP)



         nnotation Oriented Programming (AOP)


                            2

                         OP

                                                38
AOP 2 : Aspect Oriented Programming


> When should aspects be used?
  – By container?
      By container?
  – Extraneous functions?
      Extraneous functions?
  – Semantics of the language?
       A = B?
          = B?




                                      39
AOP 2 : Annotation Oriented Programming


> Annotations designed in similar goals as AOP
  – Special markers to classes, methods, and fields
  – Processed by libraries and tools
> Everything seems to be annotated now!




                                                      40
AOP 2 : Annotation Oriented Programming Sample

@Data
   RequiredArgsConstructor
public class Sample {
  private final int age;
  @NonNull private String name;
   EqualsAndHashCode
}
   ToString

   ublic class Sample {

Sample sample = new Sample(21, “James”);
   @Getter private final int age;
assert ( sample.getAge() == 21);
assert ( sample.getName().equals(“James”));
sample.setName(“Jim”);@Setter private String name;
   @NonNull @Getter
System.out.println(“sample = “ + sample);


“sample = Sample(age=21, name=Jim)                   41
AOP 2 : Annotations Sugar


   Communication with compiler
     @Override, @Deprecated, @SuppressWarnings
   Communication with frameworks
     Java Persistence API, Spring




                                                 42
AOP 2 : Annotations Salt


  Configuration
  Added Dependencies
  Used for code generation




                             43
2          2
AOP : AOP


> Annotations and aspects together is a natural fit
  – Annotations provide meta-data
   – Aspects to drive cross-cutting logic based on Annotations




                                                                 44
AOP 2 : Java EE Interceptors

  ublic class PrintInterceptor {

  @AroundInvoke

  public Object execute(InvocationContext ctx) throws Exception {

                       System.out.println("Intercepting method " +


  ctx.getMethod().getDeclaringClass().getName() + ":" +

                                               ctx.getMethod().getName());




                       Object result = ctx.proceed();                        45



                       return result;
AOP 2 : What is This?



  Procedure(name = "Account.deposit")

  ublic void deposit (

                     @In(Types.NUMERIC) final Long accountId,

                     @In(Types.NUMERIC) final Long locationId,

                     @In(Types.NUMERIC) final BigDecimal amount,

                     @In(Types.TIMESTAMP) final Date transactionDate,

  @Out(Types.NUMERIC) Ref<BigDecimal> balance) {                    46
AGENDA

> DSL
> Project Lambda
        2
> AOP
> CDI
> Grab Bag




                   47
Changing Landscape of Dependency Injection
Huh?
JSR-330 + JSR-299 Compared
JSR-330 Annotations

• @Inject
• @Named
• @Provider
• @Qualified
• @Scope
• @Singleton
Basic Injection
Named Injections
Qualifiers
Pop Quiz




   Question: Do both garage instances
   refer to the same object?
   Answer: No, the default scoping in
   JSR-330 is “@Dependent”
                                        55
Scopes
JSR-299 – Context Dependency Injection

•   Uses JSR-330 as foundation
•   Adds Java EE-specific extensions
    • Producers
    • Decorators
    • Interceptor enhancements
JSR-299 – Additional Scopes


  built-in scopes:



  RequestScoped

  SessionScoped

  ApplicationScoped

  ConversationScoped
Pop Quiz
CDI Extensions
CDI Sugar


 tandards for Dependency Injection

 nnotation-driven injection, decorators, interceptors

 xtensible SPI




                                                        62
CDI Salt


  hy are there 2 standards?

  ack of Java SE DI support

  o dynamic DI injection




                              63
AGENDA

> DSL
> Project Lambda
        2
> AOP
> CDI
> Grab Bag




                   64
Binary Literals and Underscores
Handling multiple exceptions
Multi-Catch
Resource cleaning
Try-with-resources
Strings in switch
Diamonds (are a geek’s best friend)
Java 7 Language Enhancements: Sugar or Salt?




                                               72
James Gould   verisigninc.com
Verisign      jgould@verisign.com



Alex Holmes   verisign.com
Verisign      alholmes@verisign.com

Mais conteúdo relacionado

Mais procurados

Comparing IDL to C++ with IDL to C++11
Comparing IDL to C++ with IDL to C++11Comparing IDL to C++ with IDL to C++11
Comparing IDL to C++ with IDL to C++11Remedy IT
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoTaro L. Saito
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java langer4711
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingPositive Hack Days
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOLiran Zvibel
 
Verilog HDL Training Course
Verilog HDL Training CourseVerilog HDL Training Course
Verilog HDL Training CoursePaul Laskowski
 
Ankara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with ScalaAnkara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with ScalaEnsar Basri Kahveci
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Eelco Visser
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Ruslan Shevchenko
 

Mais procurados (20)

Comparing IDL to C++ with IDL to C++11
Comparing IDL to C++ with IDL to C++11Comparing IDL to C++ with IDL to C++11
Comparing IDL to C++ with IDL to C++11
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
Java SE 8 library design
Java SE 8 library designJava SE 8 library design
Java SE 8 library design
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
Functional Programming in Scala
Functional Programming in ScalaFunctional Programming in Scala
Functional Programming in Scala
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash Cracking
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Verilog HDL Training Course
Verilog HDL Training CourseVerilog HDL Training Course
Verilog HDL Training Course
 
Ankara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with ScalaAnkara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with Scala
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
 

Semelhante a Syntactic Salt and Sugar Presentation

Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Vitaly Baum
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part IIEugene Lazutkin
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkDatabricks
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkPatrick Wendell
 
Apache spark sneha challa- google pittsburgh-aug 25th
Apache spark  sneha challa- google pittsburgh-aug 25thApache spark  sneha challa- google pittsburgh-aug 25th
Apache spark sneha challa- google pittsburgh-aug 25thSneha Challa
 
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalRMADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalRPivotalOpenSourceHub
 
Tailoring Redis Modules For Your Users’ Needs
Tailoring Redis Modules For Your Users’ NeedsTailoring Redis Modules For Your Users’ Needs
Tailoring Redis Modules For Your Users’ NeedsRedis Labs
 
AutoDesk
AutoDeskAutoDesk
AutoDeskSE3D
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...Yandex
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneJames Long
 
11. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/211. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/2Fabio Fumarola
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
Madeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareMadeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareESUG
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaDmitry Buzdin
 

Semelhante a Syntactic Salt and Sugar Presentation (20)

Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache Spark
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache Spark
 
Apache spark sneha challa- google pittsburgh-aug 25th
Apache spark  sneha challa- google pittsburgh-aug 25thApache spark  sneha challa- google pittsburgh-aug 25th
Apache spark sneha challa- google pittsburgh-aug 25th
 
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalRMADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
 
Tailoring Redis Modules For Your Users’ Needs
Tailoring Redis Modules For Your Users’ NeedsTailoring Redis Modules For Your Users’ Needs
Tailoring Redis Modules For Your Users’ Needs
 
AutoDesk
AutoDeskAutoDesk
AutoDesk
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 
11. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/211. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/2
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
Madeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareMadeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable Hardware
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
 
Rsltollvm
RsltollvmRsltollvm
Rsltollvm
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Syntactic Salt and Sugar Presentation

  • 1. Syntactic Salt and Sugar James Gould Alex Holmes Verisign 205
  • 2. Alex 2
  • 3. Jim 3
  • 5. Format Discuss 5 Syntactic Elements > > Lead discussion of each Element Introduce newer Elements – – – Identify Good Identify Bad Participation is encouraged! > 5
  • 6. AGENDA > DSL > Project Lambda > AOP 2 > CDI > Grab Bag 6
  • 7. AGENDA > DSL > Project Lambda 2 > AOP > CDI > Grab Bag 7
  • 8. omain specific language Noun: a computer programming language of limited expressiveness focused on a particular domain.
  • 11. DSL examples ELECT * FROM STATION WHERE LAT_N > 39.7;
  • 13. Grammatical Elements of a DSL operators + verbs nouns separators deposit account () {} [] . -> => = withdraw amount < > ! ~ ? : == ++ || -- *= <<< % ^ ; , %= && >= -1 >>>= // #
  • 14. Internal DSL An internal DSL is a DSL represented within the syntax of a general-purpose language. It's a stylized use of that language for a domain-specific Excerpt from Martin Fowler’s book “Domain purpose. Specific Languages”, published by Addison- Wesley
  • 17. External DSL An external DSL is a domain- specific language represented in a separate language to the main programming language it's working with. This language may use a custom syntax, or it may Excerpt from Martin Fowler’s book “Domain follow the syntax of another Specific Languages”, published by Addison- Wesley representation such as XML.
  • 18. External DSL for ATM d -> :a(0.95) :chk(12345) What do “d”, “a” and “chk” represent? What’s with the obfuscated syntax? Where is the language documented? YALTL – Yet another language to learn
  • 19. Just call me Sherlock
  • 20. Re-worked DSL grammar deposit amount 0.95 into checking 12345
  • 21. DSL Sugar diomatic way to communicate with domain experts an be used by non-programmers elf-documenting 21
  • 22. DSL Salt SL syntax can quickly become salty o you really need a DSL? upporting a DSL is labor-intensive 22
  • 23. AGENDA > DSL > Project Lambda 2 > AOP > CDI > Grab Bag 23
  • 24. Project Lambda : Introduction > Included in Java 8 > Defined in JSR-335 – Lambda Expressions – Default Methods 24
  • 25. Project Lambda : Lambda Expressions public class Calculator { ublic class Calculator { static interface Calculate { int calc(int op1, int op2); static interface Calculate { } int calc(int op1, int op2); public static void main(String... args) { } Calculate addition = (op1, op2) -> op1 + op2; public static void main(String... args) { System.out.println("Addition = " + addition.calc(10, 20)); Calculate addition = new Calculate() { Calculate multiply = (op1, op2) -> op1 * op2; public int calc(int op1, int op2) { System.out.println("Multiply = " + multiply.calc(10, 20)); return op1 + op2;}}; } } System.out.println("Addition = " + addition.calc(10, 20)); 25
  • 26. Project Lambda : Type Targeting > How “Calculate addition = (op1, op2) -> op1 + op2;” works? – Type expression is inferred by type expected in context – Calculate is a Functional Interface – Expression compatible to Function Interface  Interface is Functional Interface  Expression has same number of parameters  Expression return is compatible  Expression exception thrown is allowed by Interface > Lambda’s are strongly typed 26
  • 27. Project Lambda : Type Targeting Sample ublic class HelloWorld { public static void main(String... args) throws Exception { Callable<Void> helloCall = () -> {System.out.println("Hello World!"); return null;}; Runnable helloRun = () -> {System.out.println("Hello World!");}; 27 helloCall.call();
  • 28. Lambda’s and Collections raditional iteration: ewritten for lambda’s: or (Car c : cars) { ars.forEach(c -> c.setColor(RED)); c.setColor(RED); arallelized: ars.parallel() .forEach(c -> c.setColor(RED)); 28
  • 29. Project Lambda : Lambda Expression Sugar nonymous addition = (op1, op2)in aop1 + op2; Calculate Inner Classes done -> clean way Calculate addition = new Calculate() { public int calc(int op1, int op2) { return op1 + op2; }}; atches feature of other languages C#, C++, Ruby, Python, JavaScript, … Take advantage of multicore processors Mark Reinhold – “the real reason is multicore processors; the best way to handle them is with 29 Lambda”
  • 30. Project Lambda : Lambda Expression Salt ark Reinhold – “Some would say adding Lambda expressions is just to keep up with the cool kids, and there’s some truth in that” ava as a Object Oriented language o you want Anonymous Inner Classes on steroids? ack of code clarity 30
  • 31. Project Lambda : Default Methods nterface A { void execute() default { System.out.println("A.execute()"); } lass ClassA implements A { lassA classA = new ClassA(); 31
  • 32. Project Lambda : Default Methods nterface A { void execute() default { System.out.println("A.execute()"); } nterface B extends A { void execute() default { System.out.println(“B.execute()"); 32 }
  • 33. Project Lambda : Default Methods nterface A { void execute() default { System.out.println("A.execute()"); } nterface B { void execute() default { System.out.println(“B.execute()"); } lass ClassHuh implements A, B { 33 void execute() {
  • 34. Project Lambda : Default Methods and Lambda nterface A { void execute() default { System.out.println("A.execute()"); } nterface B extends A { void execute() default { System.out.println(“B.execute()"); } void execute2(); 34 nterface C extends A, B {}
  • 35. Project Lambda : Default Methods Sugar inally able to add code to interfaces! 35
  • 36. Project Lambda : Default Methods Salt dding multiple inheritance to Java ixing Default Methods and Lambda Expressions adds more confusion 36
  • 37. AGENDA > DSL > Project Lambda 2 > AOP > CDI > Grab Bag 37
  • 38. AOP 2 : Introduction spect Oriented Programming (AOP) nnotation Oriented Programming (AOP) 2 OP 38
  • 39. AOP 2 : Aspect Oriented Programming > When should aspects be used? – By container? By container? – Extraneous functions? Extraneous functions? – Semantics of the language?  A = B? = B? 39
  • 40. AOP 2 : Annotation Oriented Programming > Annotations designed in similar goals as AOP – Special markers to classes, methods, and fields – Processed by libraries and tools > Everything seems to be annotated now! 40
  • 41. AOP 2 : Annotation Oriented Programming Sample @Data RequiredArgsConstructor public class Sample { private final int age; @NonNull private String name; EqualsAndHashCode } ToString ublic class Sample { Sample sample = new Sample(21, “James”); @Getter private final int age; assert ( sample.getAge() == 21); assert ( sample.getName().equals(“James”)); sample.setName(“Jim”);@Setter private String name; @NonNull @Getter System.out.println(“sample = “ + sample); “sample = Sample(age=21, name=Jim) 41
  • 42. AOP 2 : Annotations Sugar Communication with compiler @Override, @Deprecated, @SuppressWarnings Communication with frameworks Java Persistence API, Spring 42
  • 43. AOP 2 : Annotations Salt Configuration Added Dependencies Used for code generation 43
  • 44. 2 2 AOP : AOP > Annotations and aspects together is a natural fit – Annotations provide meta-data – Aspects to drive cross-cutting logic based on Annotations 44
  • 45. AOP 2 : Java EE Interceptors ublic class PrintInterceptor { @AroundInvoke public Object execute(InvocationContext ctx) throws Exception { System.out.println("Intercepting method " + ctx.getMethod().getDeclaringClass().getName() + ":" + ctx.getMethod().getName()); Object result = ctx.proceed(); 45 return result;
  • 46. AOP 2 : What is This? Procedure(name = "Account.deposit") ublic void deposit ( @In(Types.NUMERIC) final Long accountId, @In(Types.NUMERIC) final Long locationId, @In(Types.NUMERIC) final BigDecimal amount, @In(Types.TIMESTAMP) final Date transactionDate, @Out(Types.NUMERIC) Ref<BigDecimal> balance) { 46
  • 47. AGENDA > DSL > Project Lambda 2 > AOP > CDI > Grab Bag 47
  • 48. Changing Landscape of Dependency Injection
  • 49. Huh?
  • 50. JSR-330 + JSR-299 Compared
  • 51. JSR-330 Annotations • @Inject • @Named • @Provider • @Qualified • @Scope • @Singleton
  • 55. Pop Quiz Question: Do both garage instances refer to the same object? Answer: No, the default scoping in JSR-330 is “@Dependent” 55
  • 57. JSR-299 – Context Dependency Injection • Uses JSR-330 as foundation • Adds Java EE-specific extensions • Producers • Decorators • Interceptor enhancements
  • 58. JSR-299 – Additional Scopes built-in scopes: RequestScoped SessionScoped ApplicationScoped ConversationScoped
  • 60.
  • 62. CDI Sugar tandards for Dependency Injection nnotation-driven injection, decorators, interceptors xtensible SPI 62
  • 63. CDI Salt hy are there 2 standards? ack of Java SE DI support o dynamic DI injection 63
  • 64. AGENDA > DSL > Project Lambda 2 > AOP > CDI > Grab Bag 64
  • 65. Binary Literals and Underscores
  • 71. Diamonds (are a geek’s best friend)
  • 72. Java 7 Language Enhancements: Sugar or Salt? 72
  • 73. James Gould verisigninc.com Verisign jgould@verisign.com Alex Holmes verisign.com Verisign alholmes@verisign.com