SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Adventures in
TclOOor, Here’s Some Tricks I’ve Been Up To
Donal Fellows
University of Manchester / Tcl Core
Team
Outline
 A Quick TclOO Refresher
 Support Class for REST
 Wrapping TDBC with ORM
 Extending TclOO with Annotations
 Where to go in the Future
2
Refresher
A Quick TclOO…
3
TclOO Refresher
 Object System
 Incorporated in 8.6, Package for 8.5
 Designed for
 Keeping Out of Your Way
 Being Tcl’ish and Dynamic
 Being Powerful and Extensible
 Key Features
 Single-Rooted Inheritance Hierarchy
 Classes are Objects and May be Extended
 Object’s Namespace contains Object’s Variables
 Class (Re-)Definition by Separate Command
4
The Anatomy Lesson
oo::object
Namespace
Method
Table
Mixin
List
Variables
NS Path
Commands
Instance
Method
Table
Mixin
List
Superclass List
oo::class
An object
has these
things…
A class also
has these,
which apply
to instances
Classes are objects
Objects are
made by
classes
You can subclass the class of
classes for custom construction 5
REST
Support Class for…
REpresentational State Transfer
 REST is Way of Doing Web Services
 Popular
 Easy to Use in Ad Hoc Way
 Strongly Leverages HTTP
 Verbs are GET, PUT, DELETE, POST, …
 Nouns are Resources with URLs
 View of Resources Determined by Content
Negotiation
7
Example…
 http://example.org/pizzas is a Pizza Parlor
 GET http://example.org/pizzas
 Returns Current List of Pizzas
 GET http://example.org/pizzas/123
 Returns Description of Pizza #123
 GET http://example.org/pizzas/123/pepperoni
 Returns Amount of Pepperoni on Pizza
8
Example… Updates
 PUT http://example.org/pizzas/123/pepperoni
 Sets Amount of Pepperoni on Pizza #123
 Idempotent
 POST http://example.org/pizzas
 Makes a New Pizza from Scratch
 Request document says what to make
 Redirects to Created Pizza
 DELETE http://example.org/pizzas/123
 Gets Rid of Pizza #123
 Idempotent
9
REST Class
 TclOO Class
 Wrapper for http package
 Models a Base Resource
 Methods for Each HTTP Verb
 Designed to be Subclassed!
 Some Production Use
 Testing Interface for Very Complex REST Service
 More than 35 Operations with non-fixed URLs
 Still Growing…
10
General Plan
oo::object
Service Instance Service InstanceService Instance
oo::class
REST
Specific Service
11
Code (Simplified)
methodDoRequest{
methodurl {type ""} {value ""}} {
for {setrs0} {$rs< 5} {incrrs} {
settok [http::geturl $url 
-method $method 
-type $type -query $value]
try {
if{[http::ncode $tok] > 399} {
# ERROR
setmsg [myExtractError $tok]
return -code error $msg
} elseif {[http::ncode $tok] > 299
||[http::ncode $tok]==201} {
# REDIRECT
try {
setlocation [dictget 
[http::meta $tok] Location]
} on error {} {
error"missing location!"
}
myOnRedirect $tok $location
} else{
# SUCCESS
return[http::data $tok]
}
} finally {
http::cleanup $tok
}
}
error"too many redirections!"
}
methodGETargs {
return [myDoRequest GET 
$base/[join $args"/"]]
}
12
Usage
oo::class create Service {
superclass REST
# … etc …
methodstatus {{status""}} {
if {$statuseq""} {
return[my GET status]
}
my PUT status text/plain $status
return
}
}
13
Bioscience
ServicesBioscience
ServicesBioscience
Services
What I Was Using This For
Workflow Server
Web
FrontEnd
Database Filesystem
Heliophysics
ServicesHeliophysics
ServicesHeliophysics
Services
Chemistry
ServicesChemistry
ServicesChemistry
Services
Workflow
Workflow Workflow
Taverna 2 Server
Taverna
Engine
Taverna
Engine
Taverna
EngineTesting
This Part
14
ORM
Wrapping TDBC with…
Object-Relational Mapping
 Objects are Natural Way to Model World
 Well, much of it…
 Relational Databases are Excellent at Managing
Data
 Build Links between Objects and Databases
 Many Languages Have Them
 Java, C#, Ruby, …
 Wanted to do in Tcl
 Leverage TclOO and TDBC
16
Data First or Objects First?
 Data First
 Data is already in the database
 How to introspect database’s structure
 How to represent naturally as objects
 Objects First
 Data is in objects
 How to construct database to store and restore
 My ORM Package is Data First
 Dynamic class construction!
17
Basic Class Plan
oo::object oo::class
Database Table
NamedRow AnonRow
Instance
makes
instance
subclass
18
CRM DB
Interaction Plan
Database
Table
NamedRow
Order
Descn CustI
D
DispID
Customer
FirstName Surname
Dispatch
ID House Street City
ID
ID
State
crmdb
orderorder#42
customer
dispatch
customer#7
dispatch#9
Introspects DB
Columns go to properties
Foreign keys make
inter-object links
Class per table
Instance per row
19
Example of Use
# Connect to Database with TDBC
setconn [tdbc::sqlite3::connection new"mydb.sqlite3"]
# Create all the classes holding the mapping
ORM::Databasecreatedb $conn
# Illustrate use by printing out all orders
db table order foreachordr {
puts"Order #[$ordr id]"
puts"Customer: [[$ordr customer] firstname]
[[$ordr customer] surname]"
puts"Address: [[$ordr dispatch] house]
[[$ordr dispatch] street]"
puts"Address: [[$ordr dispatch] city],
[[$ordr dispatch] state]"
puts"Description:nt[$ordr description]"
puts""
}
20
Annotations
Extending TclOO with…
What is an Annotation?
 Additional Arbitrary Metadata
 Attached to Class or Part of Class
 User-Defined Purpose
 Easy way to add information without doing big
changes to TclOO’s C implementation
 Uses from Other Languages
 Documentation
 Constraints
 Coupling to Container Frameworks
 Persistence, Web Apps, Management, …
22
Annotation Syntax
@SomeAnnotation -foo bar
oo::class createExample {
@AnotherAnnotation
variablex
@GuessWhatThisIs
constructor {} { … }
@HowAboutThis?
@More…
methodxyzzy {xy} { … }
}
# To read the annotations…
puts [infoclassannotation Example]
23
Types of Annotations
 Annotations Specify What They Attach To
 Classes
 Methods
 Any declaration…
 Examples
 @Description
 @Argument
 @Result
 @SideEffect
24
Declaring an Annotation
oo::class createAnnotation.Argument {
superclassAnnotation.Describe
variableannotationmethod 
argument
# Save what argument this applies to
constructor{type argNameargs} {
setargument $argName
next $type {*}$args
}
# How an annotation is introspected
methoddescribe{v {n""} {an""}} {
upvar 1 $vresult
if {[llength [infolevel 0]] == 3} {
lappendresult $method
return
}
if{$method ne $n} {
return
}
if{[llength [infolevel 0]] == 4} {
lappendresult $argument
return
} elseif {$argumenteq$a} {
setresult [join $annotation]
return -code break
}
}
}
25
Under the Hood
 Every Class has List of Annotations Applied to it
 Attaching to Classes
 Uses Standard Unknown Handler
 Rewrites oo::class Command
 Attaching to Declarations
 Rewrites Whole TclOO Declaration System
 Change Declaration
 Local Unknown Handler
 Adding Introspection
 Extra commands in [info class] via ensemble
26
Under the Hood
TclOO Package Annotation Package
oo::class
oo::define
[info class]
interceptor
interceptors
extensions
Annotation
Class
Annotation
Store
Meddleswithinternals
27
Future?
Where to go in the
Future of REST Class
 Contribute to Tcllib
 Needs More Features First
 Authentication Support
 Cookie Handling
 WADL Parser
 Well, maybe…
29
Future of ORM
 Much Work Needed
 What is natural way to handle object deletion?
 What is best way to handle complex keys?
 What is best way to bring in objects?
 What sort of cache policy should be used?
 Support Object-First Style
 With annotations?
30
Future of Annotations
 Too Hard to Declare
 Far too much work!
 Introspection Axes Wrong
 Current code uses very unnatural order
 Add to TclOO?
 Depends on issues being resolved
 Find Cool Things to Do, e.g…
 Augment ORM?
 Ways of creating server-side REST bindings
31

Weitere ähnliche Inhalte

Was ist angesagt?

Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developersJohn Stevenson
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Ken Kousen
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of FlatteryJosé Paumard
 
Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)RichardWarburton
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196Mahmoud Samir Fayed
 
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Chris Richardson
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Tcl2012 8.6 Changes
Tcl2012 8.6 ChangesTcl2012 8.6 Changes
Tcl2012 8.6 Changeshobbs
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
DevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreDevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreXavier Coulon
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2José Paumard
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonMax Klymyshyn
 

Was ist angesagt? (20)

Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Tcl2012 8.6 Changes
Tcl2012 8.6 ChangesTcl2012 8.6 Changes
Tcl2012 8.6 Changes
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
DevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreDevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a Datastore
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
 

Ähnlich wie Adventures in TclOO

RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRsquared Academy
 
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)Rathod Shukar
 
Powershell Training
Powershell TrainingPowershell Training
Powershell TrainingFahad Noaman
 
Breaking down data silos with the open data protocol
Breaking down data silos with the open data protocolBreaking down data silos with the open data protocol
Breaking down data silos with the open data protocolWoodruff Solutions LLC
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceMaarten Balliauw
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
PythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programmingPythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programmingKhadijaKhadijaAouadi
 
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxCertification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxRohit Radhakrishnan
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing ScenarioTara Hardin
 

Ähnlich wie Adventures in TclOO (20)

RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
 
Angular Schematics
Angular SchematicsAngular Schematics
Angular Schematics
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Breaking down data silos with the open data protocol
Breaking down data silos with the open data protocolBreaking down data silos with the open data protocol
Breaking down data silos with the open data protocol
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
Lesson11
Lesson11Lesson11
Lesson11
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
PythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programmingPythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programming
 
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxCertification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptx
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
Python - Lecture 12
Python - Lecture 12Python - Lecture 12
Python - Lecture 12
 

Kürzlich hochgeladen

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 

Kürzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Adventures in TclOO

  • 1. Adventures in TclOOor, Here’s Some Tricks I’ve Been Up To Donal Fellows University of Manchester / Tcl Core Team
  • 2. Outline  A Quick TclOO Refresher  Support Class for REST  Wrapping TDBC with ORM  Extending TclOO with Annotations  Where to go in the Future 2
  • 4. TclOO Refresher  Object System  Incorporated in 8.6, Package for 8.5  Designed for  Keeping Out of Your Way  Being Tcl’ish and Dynamic  Being Powerful and Extensible  Key Features  Single-Rooted Inheritance Hierarchy  Classes are Objects and May be Extended  Object’s Namespace contains Object’s Variables  Class (Re-)Definition by Separate Command 4
  • 5. The Anatomy Lesson oo::object Namespace Method Table Mixin List Variables NS Path Commands Instance Method Table Mixin List Superclass List oo::class An object has these things… A class also has these, which apply to instances Classes are objects Objects are made by classes You can subclass the class of classes for custom construction 5
  • 7. REpresentational State Transfer  REST is Way of Doing Web Services  Popular  Easy to Use in Ad Hoc Way  Strongly Leverages HTTP  Verbs are GET, PUT, DELETE, POST, …  Nouns are Resources with URLs  View of Resources Determined by Content Negotiation 7
  • 8. Example…  http://example.org/pizzas is a Pizza Parlor  GET http://example.org/pizzas  Returns Current List of Pizzas  GET http://example.org/pizzas/123  Returns Description of Pizza #123  GET http://example.org/pizzas/123/pepperoni  Returns Amount of Pepperoni on Pizza 8
  • 9. Example… Updates  PUT http://example.org/pizzas/123/pepperoni  Sets Amount of Pepperoni on Pizza #123  Idempotent  POST http://example.org/pizzas  Makes a New Pizza from Scratch  Request document says what to make  Redirects to Created Pizza  DELETE http://example.org/pizzas/123  Gets Rid of Pizza #123  Idempotent 9
  • 10. REST Class  TclOO Class  Wrapper for http package  Models a Base Resource  Methods for Each HTTP Verb  Designed to be Subclassed!  Some Production Use  Testing Interface for Very Complex REST Service  More than 35 Operations with non-fixed URLs  Still Growing… 10
  • 11. General Plan oo::object Service Instance Service InstanceService Instance oo::class REST Specific Service 11
  • 12. Code (Simplified) methodDoRequest{ methodurl {type ""} {value ""}} { for {setrs0} {$rs< 5} {incrrs} { settok [http::geturl $url -method $method -type $type -query $value] try { if{[http::ncode $tok] > 399} { # ERROR setmsg [myExtractError $tok] return -code error $msg } elseif {[http::ncode $tok] > 299 ||[http::ncode $tok]==201} { # REDIRECT try { setlocation [dictget [http::meta $tok] Location] } on error {} { error"missing location!" } myOnRedirect $tok $location } else{ # SUCCESS return[http::data $tok] } } finally { http::cleanup $tok } } error"too many redirections!" } methodGETargs { return [myDoRequest GET $base/[join $args"/"]] } 12
  • 13. Usage oo::class create Service { superclass REST # … etc … methodstatus {{status""}} { if {$statuseq""} { return[my GET status] } my PUT status text/plain $status return } } 13
  • 14. Bioscience ServicesBioscience ServicesBioscience Services What I Was Using This For Workflow Server Web FrontEnd Database Filesystem Heliophysics ServicesHeliophysics ServicesHeliophysics Services Chemistry ServicesChemistry ServicesChemistry Services Workflow Workflow Workflow Taverna 2 Server Taverna Engine Taverna Engine Taverna EngineTesting This Part 14
  • 16. Object-Relational Mapping  Objects are Natural Way to Model World  Well, much of it…  Relational Databases are Excellent at Managing Data  Build Links between Objects and Databases  Many Languages Have Them  Java, C#, Ruby, …  Wanted to do in Tcl  Leverage TclOO and TDBC 16
  • 17. Data First or Objects First?  Data First  Data is already in the database  How to introspect database’s structure  How to represent naturally as objects  Objects First  Data is in objects  How to construct database to store and restore  My ORM Package is Data First  Dynamic class construction! 17
  • 18. Basic Class Plan oo::object oo::class Database Table NamedRow AnonRow Instance makes instance subclass 18
  • 19. CRM DB Interaction Plan Database Table NamedRow Order Descn CustI D DispID Customer FirstName Surname Dispatch ID House Street City ID ID State crmdb orderorder#42 customer dispatch customer#7 dispatch#9 Introspects DB Columns go to properties Foreign keys make inter-object links Class per table Instance per row 19
  • 20. Example of Use # Connect to Database with TDBC setconn [tdbc::sqlite3::connection new"mydb.sqlite3"] # Create all the classes holding the mapping ORM::Databasecreatedb $conn # Illustrate use by printing out all orders db table order foreachordr { puts"Order #[$ordr id]" puts"Customer: [[$ordr customer] firstname] [[$ordr customer] surname]" puts"Address: [[$ordr dispatch] house] [[$ordr dispatch] street]" puts"Address: [[$ordr dispatch] city], [[$ordr dispatch] state]" puts"Description:nt[$ordr description]" puts"" } 20
  • 22. What is an Annotation?  Additional Arbitrary Metadata  Attached to Class or Part of Class  User-Defined Purpose  Easy way to add information without doing big changes to TclOO’s C implementation  Uses from Other Languages  Documentation  Constraints  Coupling to Container Frameworks  Persistence, Web Apps, Management, … 22
  • 23. Annotation Syntax @SomeAnnotation -foo bar oo::class createExample { @AnotherAnnotation variablex @GuessWhatThisIs constructor {} { … } @HowAboutThis? @More… methodxyzzy {xy} { … } } # To read the annotations… puts [infoclassannotation Example] 23
  • 24. Types of Annotations  Annotations Specify What They Attach To  Classes  Methods  Any declaration…  Examples  @Description  @Argument  @Result  @SideEffect 24
  • 25. Declaring an Annotation oo::class createAnnotation.Argument { superclassAnnotation.Describe variableannotationmethod argument # Save what argument this applies to constructor{type argNameargs} { setargument $argName next $type {*}$args } # How an annotation is introspected methoddescribe{v {n""} {an""}} { upvar 1 $vresult if {[llength [infolevel 0]] == 3} { lappendresult $method return } if{$method ne $n} { return } if{[llength [infolevel 0]] == 4} { lappendresult $argument return } elseif {$argumenteq$a} { setresult [join $annotation] return -code break } } } 25
  • 26. Under the Hood  Every Class has List of Annotations Applied to it  Attaching to Classes  Uses Standard Unknown Handler  Rewrites oo::class Command  Attaching to Declarations  Rewrites Whole TclOO Declaration System  Change Declaration  Local Unknown Handler  Adding Introspection  Extra commands in [info class] via ensemble 26
  • 27. Under the Hood TclOO Package Annotation Package oo::class oo::define [info class] interceptor interceptors extensions Annotation Class Annotation Store Meddleswithinternals 27
  • 29. Future of REST Class  Contribute to Tcllib  Needs More Features First  Authentication Support  Cookie Handling  WADL Parser  Well, maybe… 29
  • 30. Future of ORM  Much Work Needed  What is natural way to handle object deletion?  What is best way to handle complex keys?  What is best way to bring in objects?  What sort of cache policy should be used?  Support Object-First Style  With annotations? 30
  • 31. Future of Annotations  Too Hard to Declare  Far too much work!  Introspection Axes Wrong  Current code uses very unnatural order  Add to TclOO?  Depends on issues being resolved  Find Cool Things to Do, e.g…  Augment ORM?  Ways of creating server-side REST bindings 31