+ All Categories
Home > Documents > A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about...

A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about...

Date post: 12-Sep-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
39
A Type System for Tomorrow
Transcript
Page 1: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

A Type Systemfor Tomorrow

Page 2: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

github.com/gabesullice

[email protected]

Gabe SulliceBackend Engineer

drupal.org/u/gabesullice

@gabesullice

Page 3: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures
Page 4: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Bad programmersworry about the code. Good programmers worry aboutdata structures and their

relationships.”- Linus Torvalds

Page 5: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Smart data structuresand dumb code work better than the other way around.”

- Eric S. Raymond, The Cathedral and the Bazaar

Page 6: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Déjà Vu

Page 7: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

● Complex associativity● Hierarchical and ordered data● Nested data structures● Complex access control● Triggered events

Déjà Vu

Page 8: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Why does it matter?

Page 9: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Drupal is a terribleblogging platform.

Page 10: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Drupal is afantastic tool for building

a great blogging platform.

Page 11: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

The Mental Model

Page 12: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Data Structures, Concepts& Behavior

Page 13: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

What are our data structures?● Big clumps of simpler data.● Usually with some additional organization or schema.

Data Structures

Page 14: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Data Structures

Map

Page 15: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”

Data Structures

List

Page 16: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”

Data Structures

Queue

Page 17: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”

Data Structures

Tree

Page 18: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Data Structures

Set

Page 19: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Order● Priority● Precedence

Concepts

Page 20: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Hierarchy● Inheritance● Derivation● Belonging

Concepts

Page 21: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Identity● Addressable● Uniqueness● Random vs. Deterministic

Concepts

Page 22: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Composition● Embeddedness● Shared Behavior● Shared Structure

Concepts

Page 23: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Association● Relationship● Interaction

Concepts

Page 24: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”

Data Structures

Composition

Association

Page 25: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Observability● IFTT● Required trigger for any non-trivial application

Concepts

Page 26: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Where are we?

Page 27: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Order● Taxonomy weight● Field weight● Book weight● Views sorting

Where we are.

Page 28: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Hierarchy● Taxonomy terms● Book nodes● Ad-hoc entity references

Where we are.

Page 29: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Identity● UUIDs● Machine names

Where we are.

Page 30: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Composition● Entity references, entity references everywhere● Inconveniences

○ No behavioral opt-in/out○ Required fields

Where we are.

Page 31: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Association● Zilch, nada, zero

Where we are.

Page 32: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Association● Zilch, nada, zero● Organic Groups, sort of.

Where we are.

Page 33: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

A better way?

$membership = Og::createMembership($entity,$user

);$membership->save();

Where we are.

Page 34: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

A better way?

$ticket = Association::create(‘ticket’,$flight,$user

);$ticket->save();

Where we are.

Page 35: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

A better way?

$all_tickets_sold =$flight->associations(‘ticket’);

$all_passengers =$flight->associatedBy(‘ticket’);

Where we are.

$all_tickets_sold =$flight->associations(‘ticket’);

$all_passengers =$flight->associatedBy(‘ticket’);

Page 36: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Observability● Hooks● Action plugins● Condition plugins

Where we are.

Page 37: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

Takeaways

Page 38: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

Takeaways● Untangle useful behavior from our data types● Add the concept of fieldable associations● Expose condition plugins in meaningful ways● This will make action plugins a primary point of

extension, like hooks are today

Let’s do it!

Page 39: A Type System for Tomorrow · “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds “Smart data structures

“Your code”● The code for which you or your team is responsible

What do you think?● Let me know what you think @gabesullice● First DrupalCon session, so leave me a review● Don’t forget to take the Surveymonkey for the con

Contact


Recommended