Sanjiva Weerawarana PhD Founder Chairman amp Chief Architect WSO2 Joint work with Sameera Jayasoma WSO2 Hasitha Aravinda WSO2 Dr Srinath Perera WSO2 and Prof Dr Frank ID: 798133
Download The PPT/PDF document "A modern programming language focused on..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
A modern programming language focused on integration
Sanjiva Weerawarana, Ph.D.Founder, Chairman & Chief Architect; WSO2
Joint work with Sameera
Jayasoma, WSO2; Hasitha Aravinda, WSO2; Dr. Srinath Perera, WSO2; and Prof. Dr. Frank Leymann; Univ. of Stuttgart
June 22, 2018; Univ. of Thessaly, Volos, Greece
James Clark
Independent
Slide2Agenda
MotivationType systemNetwork awareness, security & resiliencyMore than the language
ImplementationFuture work
6/22/182
Slide3Motivation: Why yet another language?
Digital transformation
Everything is a network serviceProduce, not just consume network servicesEvery business has to become a software company
Minimalization of computingHardware VMs Containers ServerlessSOA MicroservicesESB Service meshesMiddleware is dead; middleware is everywhereServers to sidecars to code
6/22/183
Slide4Design inspirations
London 2012 Olympics opening
Sequence diagramsMany existing languages, including Java, Go, C, C++,
Rust, Haskell, Kotlin, Dart, Typescript, Javascript, Flow, Swift, RelaxNG6/22/18
4
Source:
https://stillmed.olympic.org/Global/Images/News/2012-07/27/opening_country.jpg
Slide5Design principles
Code, not config, with both text and graphic syntaxes
Do not try to hide the networkFirst class support for network data types
No room for best practices or “findbugs”Make programs secure by defaultMake programs network resilient by defaultNo dogmatic programming paradigmMainstream concepts & abstractions, not research
6/22/185
Slide6Unusual aspects of Ballerina
First-class nature of application level network abstractions
Structural type system with network friendly types and unionsSequence diagram based parallelism model
Language extensibility with environment binding and compilation extensibility6/22/186
Slide7Hello, World from Ballerina
import ballerina/
io
;function main (string... args) {
worker w1 { io:println
("Hello, World! #m");
}
worker w2 {
io:println
("Hello, World! #n");
}
worker w3 {
io:println
("Hello, World! #k");
}
}
6/22/18
7
Slide8Ballerina graphical notation
Sequence diagrams focused on showing worker and endpoint interactionsEndpoints represent network services
Each worker is sequential codeWe can zoom in graphically but its really just code
Not meant to be used for low-code / no-code or by non-programmersMeant to make it easier to understand complex distributed interactions6/22/18
8
Slide9Ballerina, the language
Program & lexical structure
Values, types & variablesExpressions
StatementsWorkers, Functions, Endpoints & ServicesTables & streamsAnnotationsComments & documentationSecurity
Distributed resilience6/22/18
9
Slide10Programs
Modularity in 4 levelsPackage repository
OrganizationPackageObject, but not mandatory
PackageCollection of files that contribute symbols, like GoFile names not relevantUnit of compilation & executionObjectUsual kind of object6/22/18
10
Slide11Values, types & variables
Structurally typed, defined in terms of values
Type is a label for a set of values, same value can be of many typesKinds of valuesSimple values: (),
boolean, int, float, decimal, string, byteStructured values: tuple, array, map, record, table, xmlBehavioral values: function, future, object, stream, typedescTypesBasic types (one of the above)OthersFinite types, unions, optional, any, json
6/22/18
11
Slide12Mapping types
Mappings are collections of (name, value) pairs
VariationsOpen vs. closed mappingsRequired vs. optional fields
“record” type constructorCollection of mandatory and optional named fields of any typesOpen if desired“map” type constructorAny fields but all values of a single typeAlways openCovariant subtypesStorage type
6/22/18
12
Slide13json
json is just a union
() | int | float | string | map<json> | json
[]json objects are most commonly usedmap<json>, but subtyped to an open record with non-mandatory fields in most casesVery useful for man-in-the-middle network scenariosWith json being within the type system, no data binding concept needed for json
6/22/18
13
Slide14XML
Minimalistic but powerful native xml type
Non-traditional XML architecturexml is sequence of things that appear in XML (elements, comments, text, ..)Elements do not contain references to parent or siblings and same element can appear in multiple xml values
No node identity, no text nodes (just strings)Namespaces married to Ballerina qualified name architectureLiteral XML values, reading/writing6/22/18
14
Slide15Tables
Tabular dataProgrammatically generated & manipulated
Database connectors to load/store tablesIntegrated SQL-like query, ala C# LINQIn-memory database
Table rows are just records (no ORM)6/22/1815
Slide16Streams and streaming query
Stream is a distributor of any type of events within a BVM
Can be attached to network sources as wellStreaming SQL-like queries attach to some number of streamsComplex event processing
Event stream processingMarrying Siddhi CEP engine6/22/1816
Slide17Type matching
Union typed expressions have to be separated out before use:
match expression {
pattern [var] => statement;
pattern [var
] => statement;
..
}
Or within an expression:
expression but { pattern [
var
] => expression }
6/22/18
17
Slide18Errors and error lifting
Errors are its own value space
Can be returned or thrownOften returned as T | errorThrowing is discouraged and meant to be used rarely
Error liftingMany functions return ResultType | errorCheck expression: check expressionIf error return immediately, else error is eliminated from type set6/22/18
18
Slide19Nil & error lifting navigation
Navigating deep hierarchies is common in integration code
Navigating through optional types are nil-lifted by “.” operator: a.b.cNavigation is both nil and error lifted by “!” operator:
a!b!cWhy?Combination of optional types and type matching makes it impossible to have a null reference in BallerinaNil & error lifting make those rules palatable6/22/18
19
Slide20Local & distributed transactions
One service calling another over HTTP is very common in enterprise applications
But lack of distributed resiliency leads to fragile codeBallerina micro transaction protocolAllows any piece of code to initiate a distributed transaction with its own built-in coordinator
Transaction ID is transparently infected to other nodes in the distributed systemThey join and participate in transaction protocolSee: transaction { .. } statement6/22/18
20
Slide21Writing (more) secure programs
ObjectivesProvide integrated authentication and authorization architecture
Prevent potentially dangerous data from getting into the systemPropagate security contexts to downstream bits Make it easier to monitor access patterns for abuse
ArchitectureRuntime context with principal and permissions set by inbound endpointsPluggable authentication and authorization frameworkTaint assertions and checking6/22/18
21
Slide22Functions, methods and resources
Unit of execution: One sequence diagramDefines a set of workers who startin parallel whenunit is invoked
Any worker can causecaller to be releasedOther workers
continue6/22/1822
Slide23Function invocation
Initialization: start endpoints
Start concurrent workersFirst one to return will release callerOthers continue to completion
If no one completes (e.g. due to failures) function call fails with “call failed” exception6/22/1823
Slide24Futures & non-blocking invocation
Any function can be called in a non-blocking way:
future<T> f = start
functionName (args)Wait for completion, cancel, get return values via typed future
6/22/18
24
Slide25Worker to worker communication
Via anonymous channels, non-blocking for send, blocking for receive
Attempt at deadlock preventionComing soon: named channels
6/22/1825
Slide26Network abstraction: endpoint
Endpoints represent network termination points for incoming network interactions or outgoing network interactions
More than a socketService endpoints are network entry points to a BVM via a registered serviceCalls are delivered to a particular resource in a service
Code can reply/message with provided endpoint, no returning valuesClient endpoints represent remote systemsOffer a set of actions for interaction with them6/22/18
26
Slide27Services & resources
Service is a collection of resources where each resource is network invokable
Services must be attached to an endpoint to be invokedResponses must be via endpoint and not by returning values
Responses may not go6/22/1827
Slide28Network calls
Programmer needs to be made aware that this is a network callGraphically line from a worker to an endpoint
Textually:
var result = epName->actionName (
args);If any errors occur they need to be type matched and handled
6/22/18
28
Slide29Outbound resiliency
Failure is normal in network interactions
Endpoints are logicalGroup them for load balancing, failover or other behaviorsCircuit breaking, bulk-heading, timeouts, load management all part of endpoint architecture
6/22/1829
Slide30Comments and documentation
Documentation is a first class aspect of BallerinaWritten in markdown+
Mandatory for public symbolsComments and disabling code
6/22/1830
Slide31Annotations
For everything about the code
Compile-time processable with compiler extensionsE.g.: Docker and K8s annotations
6/22/1831
Slide32Beyond the language
6/22/18
32
Slide33Standard Library
ballerina/auth
ballerina/cacheballerina/config
ballerina/cryptoballerina/fileballerina/grpcballerina/h2ballerina/httpballerina/internalballerina/ioballerina/jdbcballerina/jmsballerina/log
ballerina/math
ballerina/mb
ballerina/mime
ballerina/mysql
ballerina/reflect
ballerina/runtime
ballerina/sql
ballerina/swagger
ballerina/system
ballerina/task
ballerina/test
ballerina/time
ballerina/transactions
ballerina/websub
6/22/18
33
Slide34Programming is more than just code
Editing & debugging
TestingObservabilityDependencies, versions and building
DocumentationSharing6/22/18
34
Slide35Implementation
Compiler produces BVM instructions into library (.balo
) or linked binary (.balx)Portable object and executable format
Extensible architecture for compiler to allow 3rd party annotation processing to become part of compilation process, e.g. Docker/K8sIDEs supported via Language Server ProtocolPlugins for VS Code, IntelliJ and standalone browser-based ComposerCompiler & BVM currently written in Java6/22/18
35
Slide36Future work
Forward recoverabilityCompensationCheckpoint and restart
Docker / Kubernetes compositionsMerging / collapsing sequence diagramsInternationalizing the grammar
Greek, anyone?ImplementationNative compilation via LLVMAlso WebASM, CLR6/22/18
36
Slide37Summary
Ballerina is an attempt to build a modern industrial grade programming language
For future with lots of network endpointsType system is designed to make network data processing easier
First class network services along with functions/objectsFramework to encourage more secure codeFully open source and developed openly6/22/18
37
Slide38Questions?
Contact: sanjiva@wso2.com
Download?v0.970.0 released May 1stv0.975.0 about to be released
v0.980.0 due in mid-Julyv1.0 ETA Nov/Dec 2018http://ballerina.io/CommunityEmail: ballerina-dev@googlegroups.comSlack: ballerina-platform.slack.com#generalTwitter: @ballerinaplat
6/22/18
38