[2021 kcdc] Algebraic in Java: Pattern Matching

This post is my live blog from KCDC. For more, see the 2021 KCDC live blog TOC

Speaker: Chandra Guntur

Twitter: @cguntur

————————-

Background

  • This is part two of a talk. Part 1 covered algebraic types (ex: enums). Don’t need to have seen it for this talk
  • Pattern matching came froM SNOBOL (string oriented and symbolic language) in 1960s
  • This presentation is in https://github.com/c-guntur/algebraic-in-java

Switch case pattern matching

  • case can be type of object. ex: case Integer i -> “int”
  • Must put “case null” in order to avoid a null pointer
  • Guarded expressions: case Integer i && i < 50
  • Can use same pattern variable name across case statements
  • Flow scoping

If statement pattern matching

Deconstructing is from JDK 18 preview – https://openjdk.java.net/jeps/405 (preview features can change)

  • if (o instanceof Point p)
  • if (o instanceof Point(int x, int y) – deconstruct value. Implicitly type safe because null won’t reach branch (null instanceof X is always false)
  • if (r instanceOf Rect(Point(var x, var y), var lr) – nested deconstruction
  • If have varargs, can match by coordinates/number of elements. Ex Point() matches no params, Point(var a) matches one, Point(var a, …) matches one or more
  • For array, if (o instanceof String[] { String s1, … } – one or more elements in array

Pattern matching isn’t new

  • Always had instanceof
  • Visitor pattern
  • Regular expressions

My take

I’m excited Java is going to be adding a lot of this. The format of presenting from inside IntelliJ is interesting. The presentation was short though. Only half an hour. I liked the answer to my question about scope – pretend there is an else block!

[kcdc 2021] Java 17’s Project Panama Newbies

This post is my live blog from KCDC. For more, see the 2021 KCDC live blog TOC

Speaker: Carl Dea (Azul)

Twitter: @carldea

————————-

Foojay.io has more

JEP 412 – Foreign Access API

  • https://openjdk.java.net/jeps/412 – ties together other JEPs
  • incubator module. Third incubabor
  • in making for at teast 6 years

Problems with old way

  • Communicating with required wrapper code and distributing a .ddl
  • Have to do a lo of work yourself to interfaces with C

URLs

  • jdk.java.net/panama
  • https://github.com/openjdk/panama-foreign
  • panama-dev@openjdk.java.net
  • https://foojay.io/today/project-panama-for-newbies-part-1/
  • https://foojay.io/today/project-panama-for-newbies-part-2/
  • https://foojay.io/today/project-panama-for-newbies-part-3/
  • https://github.com/carldea/panama4newbies

Using

  • java -version. Make sure says 17-panama. (Not part of main JDK)
  • jextract -h to get help
  • jextract will generate Java code for you by looking at C header file
  • Most important options
    • -I (capital Eye) – include file path
    • -d – destination for generate files
    • -l (lowercase ell) – specify a library
    • -t – target package
  • Must add incubator module and enable native access flag to run
  • Can call C methods from Java by importing them
  • Java wil hande the memory allocation/cleanup based on scope

Include

  • Copies file and puts in this file.
  • Not like import where it a reference

My take

This is a topic I knew nothing about. (Or forgot what I had known.) It was really cool to see!

[2021 kcdc] How to equitably close the CS education gap

This post is my live blog from KCDC. For more, see the 2021 KCDC live blog TOC

Speaker: Allison Hartnett

Twitter: @dralllisonhart

————————-

Stats

  • 67% of new jobs in STEM are in computing
  • Over 400K opening
  • Only 47% of US schools teach CS
  • Black students almost 3x less likely to take AP (advanced placemen CS Principles) than White or Asian students

TEALS

  • Technology Education and Literacy in Schools
  • Microsoft pays for this but volunteers from many companies
  • Finds volunteers to pair teach for a year so a teacher can teach CS by themseves
  • Both in person an remote instruction
  • Four courses: Intro CS, AP CS Principles, AP CS A, CS Topics

Think about

  • How give feedback and be encouraging

My take

This session has speech to text/captioning on the screen. It heard everyone in the room. Some more accurately than others. I knew the session was largely about TEALS. I was hoping there would be more general points as well. (I didn’t read the abstract carefully enough)

Ended with good call for volunteeers: aka.s/TEALSContact