SlideShare une entreprise Scribd logo
1  sur  77
Your business. Your language.
Your code.
Stephan Hochdörfer, bitExpert AG
Your business. Your language. Your code.
About me
 Stephan Hochdörfer
 Head of IT at bitExpert AG, Germany
 enjoying PHP since 1999
 S.Hochdoerfer@bitExpert.de
 @shochdoerfer
Your business. Your language. Your code.
Focus on core business values!
Your business. Your language. Your code.
Get rid of the "framework speak"!
Your business. Your language. Your code.
Trust the framework...
Your business. Your language. Your code.
...but understand the underlying technology!
Your business. Your language. Your code.
Build your own toolset...
Your business. Your language. Your code.
...but focus on communication first!
Your business. Your language. Your code.
Work as a team! (Customer included!)
What the customer really wanted?
Your business. Your language. Your code.
A common language
Your business. Your language. Your code.
A common language
Your business. Your language. Your code.
A domain-specific language (DSL)
is a programming language designed
to be useful for a specific task.
A common language: Key characteristic
Your business. Your language. Your code.
Identifiable domain
A common language: Key characteristic
Your business. Your language. Your code.
„Small language“
A common language
Your business. Your language. Your code.
"[…] I do think that the greatest
potential benefit of DSLs comes when
business people participate [...]"
(Martin Fowler)
Domain-specific language: Examples
Your business. Your language. Your code.
How does a domain-specific
language look like?
SELECT * from slides WHERE presentationId = 4711 ORDER BY
pageNo;
Domain-specific language: SQL
Your business. Your language. Your code.
Feature: Serve coffee
In order to earn money
Customers should be able to
buy coffee at all times
Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1 dollar
When I press the coffee button
Then I should be served a coffee
Domain-specific language: Gherkin
Your business. Your language. Your code.
package { 'screen' :
ensure => present,
}
include apache
apache::vhost { 'myapp.loc' :
docroot => '/srv/myapp.loc/webroot/'
}
host { 'myapp.loc':
ip => '127.0.1.1'
}
Domain-specific language: Puppet
Your business. Your language. Your code.
{
"require": {
"silex/silex": "v1.0.0",
"zendframework/zend-mail": "2.1.5",
"monolog/monolog": "1.5.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.19",
"phing/phing": "2.5.0"
}
}
Domain-specific language: Composer
Your business. Your language. Your code.
Domain-specific language: Doctrine
Your business. Your language. Your code.
/** @Entity **/
class Slides
{
/**
* @OneToOne(targetEntity="Presentation")
* @JoinColumn(name="presentation_id",
* referencedColumnName="id")
**/
private $presentation;
// ...
}
/** @Entity **/
class Presentation
{
// ...
}
<?php
echo "I am a DSL, too!";
Domain-specific language: PHP
Your business. Your language. Your code.
Why using a DSL?
Your business. Your language. Your code.
Why using a DSL?
Your business. Your language. Your code.
Increase your own productivity
Why using a DSL?
Your business. Your language. Your code.
Increase in code quality
Why using a DSL?
Your business. Your language. Your code.
Ignore the implementation details,
focus on the domain aspects
Why using a DSL?
Your business. Your language. Your code.
$file = '/path/to/a/file.csv';
$mimepart1 = new MimePart();
$mimepart1->setContent(file_get_contents($file));
$mimepart1->setFilename(basename($file));
$mimepart2 = new MimePart();
$mimepart2->setText('Sample mail body.');
$multipart = new MimeMultipart();
$multipart->addPart($mimepart1);
$multipart->addPart($mimepart2);
$message = new MimeMessage();
$message->setFrom('foo@bar.org');
$message->addTo('bar@foo.org');
$message->setSubject('Hello');
$message->setContent($multipart);
$transport = new MailTransport();
$transport->send($mail);
Why using a DSL? Non-DSL example
Your business. Your language. Your code.
DSL types: You have to decide
Your business. Your language. Your code.
DSL types: You have to decide
Your business. Your language. Your code.
Internal DSL
vs.
External DSL
DSL types: Internal DSL
Your business. Your language. Your code.
DSL types: Internal DSL
Your business. Your language. Your code.
Fluent API, Expression Builder,
Functions, Closures, Annotations
Internal DSL: The Fluent API
Your business. Your language. Your code.
Internal DSL: The Fluent API
Your business. Your language. Your code.
A fluent interface is an implementation
of an object oriented API that aims to
provide for more readable code.
$file = '/path/to/a/file.csv';
$msg = new MailMessage();
$msg->from('foo@bar.org')
->to('bar@foo.org')
->subject('Hello')
->body('Sample mail body.')
->attachFile($file)
->sendWith(new SmtpTransport());
Internal DSL: The Fluent API
Your business. Your language. Your code.
Internal DSL: The Fluent API
Your business. Your language. Your code.
class MailMessage {
protected $from;
protected $to;
public function from($from) {
$this->from = $from;
return $this;
}
public function to($to) {
$this->to = $to;
return $this;
}
// [...]
}
Internal DSL: The Fluent API
Your business. Your language. Your code.
class MailMessage {
protected $from;
protected $to;
public function from($from) {
$this->from = $from;
return $this;
}
public function to($to) {
$this->to = $to;
return $this;
}
// [...]
}
Internal DSL: Expression Builder
Your business. Your language. Your code.
Internal DSL: Expression Builder
Your business. Your language. Your code.
Provides a fluent interface
on top of an existing API.
class MimeMessage {
public function setFrom($from) {
}
public function addTo($to) {
}
public function setSubject($subject) {
}
public function setContent(MimeMultipart $content) {
}
}
Internal DSL: Expression Builder
Your business. Your language. Your code.
class MailBuilder {
protected $msg;
protected $multipart;
public function __construct() {
$this->msg = new MimeMessage();
$this->multipart = new MimeMultipart();
}
public function from($from) {
$this->msg->setFrom($from);
return $this;
}
public function attachFile($file) {
$part = new MimePart();
$part->setContent(file_get_contents($file));
$part->setFilename(basename($file));
$this->multipart->addPart($part);
return $this;
}
// [...]
}
Internal DSL: Expression Builder
Your business. Your language. Your code.
Internal DSL: Expression Builder
Your business. Your language. Your code.
$file = '/path/to/a/file.csv';
$msg = new MailBuilder();
$msg->from('foo@bar.org')
->to('bar@foo.org')
->subject('Hello')
->body('Sample mail body.')
->attachFile($file)
->sendWith(new SmtpTransport());
Internal DSL: Expression Builder (Improved)
Your business. Your language. Your code.
class MailBuilder {
protected $msg;
protected $parts;
public function __construct() {
$this->msg = new MimeMessage();
$this->parts = array();
}
public function from($from) {
$this->msg->setFrom($from);
return $this;
}
public function attachFile($file) {
$builder = new PartBuilder($this);
$this->parts[] = $builder;
return $builder;
}
// [...]
}
class PartBuilder {
protected $part;
public function __construct() {
$this->part = new MimePart();
}
public function content($content) {
$this->part->setContent($content);
return $this;
}
public function filename($filename) {
$this->part->setFilename($filename);
return $this;
}
// [...]
}
Internal DSL: Expression Builder (Improved)
Your business. Your language. Your code.
Internal DSL: Functions
Your business. Your language. Your code.
Internal DSL: Functions
Your business. Your language. Your code.
Using a combination of function calls
as a sequence of statements.
Internal DSL: Functions
Your business. Your language. Your code.
$file = '/path/to/a/file.csv';
message();
from('foo@bar.org');
to('bar@foo.org');
subject('Hello');
body('Sample mail body.');
attachFile($file);
sendWith(new SmtpTransport());
Internal DSL: Nested Functions
Your business. Your language. Your code.
Internal DSL: Nested Functions
Your business. Your language. Your code.
Using nested function calls to reflect
the hirarchic nature of the language.
$file = '/path/to/a/file.csv';
message(
header(
from('foo@bar.org'),
to('bar@foo.org'),
subject('Hello')
),
body('Sample mail body.'),
attachments(
file($file)
),
sendWith(new SmtpTransport())
);
Internal DSL: Nested Functions
Your business. Your language. Your code.
$file = '/path/to/a/file.csv';
$file2 = '/path/to/a/file2.csv';
message(
header(
[
from('foo@bar.org'),
to('bar@foo.org'),
subject('Hello')
]
),
body('Sample mail body.'),
attachments(
[
file($file),
file($file2)
]
),
sendWith(new SmtpTransport())
);
Internal DSL: Nested Functions (Improved)
Your business. Your language. Your code.
Internal DSL: Closure
Your business. Your language. Your code.
Internal DSL: Closure
Your business. Your language. Your code.
A function or reference to a function
together with a referencing environment.
$fname = '/path/to/a/file.csv';
$fname2 = '/path/to/a/file2.csv';
$msg = new MailMessageBuilder();
$msg->header(function($header){
$header->from('foo@bar.org')
->to('bar@foo.org')
->subject('Hello');
})
->body('Sample mail body.')
->attach(function($file){
$file->setContent(file_get_contents($fname)
->setFilename(basename($fname);
})
->attach(function($file){
$file->setContent(file_get_contents($fname2)
->setFilename(basename($fname2);
})
->sendWith(new SmtpTransport());
Internal DSL: Closure
Your business. Your language. Your code.
Internal DSL: Annotations
Your business. Your language. Your code.
Internal DSL: Annotations
Your business. Your language. Your code.
"An annotation is metadata
attached to your code."
(Rafael Dohms)
Internal DSL: Annotations
Your business. Your language. Your code.
/** @Entity **/
class Slides
{
/**
* @OneToOne(targetEntity="Presentation")
* @JoinColumn(name="presentation_id",
* referencedColumnName="id")
**/
private $presentation;
// ...
}
/** @Entity **/
class Presentation
{
// ...
}
class MyCustomController {
// [...]
public function adminAction() {
$user = $this->authService->getLoggedInUser();
if(!$user->hasRole('ROLE_ADMIN')) {
throw new AccessDeniedException();
}
// proceed with main logic...
}
}
Internal DSL: Annotations
Your business. Your language. Your code.
class MyCustomController {
// [...]
/**
* @Allow(roles="ROLE_ADMIN")
*/
public function adminAction() {
// proceed with main logic...
}
}
Internal DSL: Annotations
Your business. Your language. Your code.
External DSL
Your business. Your language. Your code.
External DSL
Your business. Your language. Your code.
External DSLs provide a
greater syntactic freedom
External DSL: Language development
Your business. Your language. Your code.
Code generation
Your business. Your language. Your code.
Code generation
Your business. Your language. Your code.
From DSL to „code“ ;)
Code generation
Your business. Your language. Your code.
Template Generation
vs.
Transformer Generation
Code generation: Template Generation
Your business. Your language. Your code.
<?php
class [className] {
protected $service;
public function __construct([serviceType] $service) {
$this->service = $service;
}
}
Code generation: Transformer Generation
Your business. Your language. Your code.
<?php
renderPageHeader();
renderMenubar();
renderProducts();
renderFooter();
Output driven approach:
Code generation: Transformer Generation
Your business. Your language. Your code.
<?php
foreach($products as $product) {
renderName($product);
renderImage($product);
renderPrice($product);
}
Input driven approach:
Internal DSL vs. External DSL
Your business. Your language. Your code.
What to choose?
Problems with DSLs
Your business. Your language. Your code.
Problems with DSLs
Your business. Your language. Your code.
Yet-Another-Language-To-Learn
syndrome
Problems with DSLs
Your business. Your language. Your code.
Depending on the DSL complexity
creating a language can be cost intense
Famous final words ;)
Your business. Your language. Your code.
"Any fool can write code that a
computer can understand. Good
programmers write code that
humans can understand."
(Martin Fowler)
Recommended books
Your business. Your language. Your code.
Thank you!
http://joind.in/8640
Credits
http://robonthemoon.wordpress.com/2009/11/24/what-the-customer-really-wanted-–-happ
y-thanksgiving/

Contenu connexe

Tendances

Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13Stephan Hochdörfer
 
How does get template part works in twenty ten theme
How does get template part works in twenty ten themeHow does get template part works in twenty ten theme
How does get template part works in twenty ten thememohd rozani abd ghani
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusIgnacio Martín
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Stephan Hochdörfer
 
Django app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh AgarwalDjango app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh Agarwalratneshsinghparihar
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Michael Wales
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIsJames Pearce
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third PluginJustin Ryan
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with PhingMichiel Rook
 
Into the ZF2 Service Manager
Into the ZF2 Service ManagerInto the ZF2 Service Manager
Into the ZF2 Service ManagerChris Tankersley
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, TembooYandex
 

Tendances (19)

Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13
 
How does get template part works in twenty ten theme
How does get template part works in twenty ten themeHow does get template part works in twenty ten theme
How does get template part works in twenty ten theme
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - Limenius
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010
 
Django app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh AgarwalDjango app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh Agarwal
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIs
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third Plugin
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Writing Pluggable Software
Writing Pluggable SoftwareWriting Pluggable Software
Writing Pluggable Software
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
 
GAEO
GAEOGAEO
GAEO
 
Into the ZF2 Service Manager
Into the ZF2 Service ManagerInto the ZF2 Service Manager
Into the ZF2 Service Manager
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo
 

Similaire à Your Business. Your Language. Your Code - dpc13

Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsZend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsTricode (part of Dept)
 
Pwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and AsteriskPwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and Asteriskjicksta
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Multi Lingual Websites In Umbraco
Multi Lingual Websites In UmbracoMulti Lingual Websites In Umbraco
Multi Lingual Websites In UmbracoPaul Marden
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbaivibrantuser
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 
Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016johnpbloch
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestrationPaolo Tonin
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)Fabien Potencier
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)mfrancis
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysqldurai arasan
 

Similaire à Your Business. Your Language. Your Code - dpc13 (20)

Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsZend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
 
Pwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and AsteriskPwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and Asterisk
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Sa
SaSa
Sa
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Dynamic Web Programming
Dynamic Web ProgrammingDynamic Web Programming
Dynamic Web Programming
 
Phpwebdevelping
PhpwebdevelpingPhpwebdevelping
Phpwebdevelping
 
Multi Lingual Websites In Umbraco
Multi Lingual Websites In UmbracoMulti Lingual Websites In Umbraco
Multi Lingual Websites In Umbraco
 
Tml for Objective C
Tml for Objective CTml for Objective C
Tml for Objective C
 
Easy native wrappers with SWIG
Easy native wrappers with SWIGEasy native wrappers with SWIG
Easy native wrappers with SWIG
 
PHP and COM
PHP and COMPHP and COM
PHP and COM
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 

Plus de Stephan Hochdörfer

Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8Stephan Hochdörfer
 
Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Stephan Hochdörfer
 
Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13 Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13 Stephan Hochdörfer
 
Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13Stephan Hochdörfer
 
Offline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmkaOffline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmkaStephan Hochdörfer
 
Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13Stephan Hochdörfer
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13Stephan Hochdörfer
 
Offline-Strategien für HTML5Web Applikationen - WMMRN12
Offline-Strategien für HTML5Web Applikationen - WMMRN12Offline-Strategien für HTML5Web Applikationen - WMMRN12
Offline-Strategien für HTML5Web Applikationen - WMMRN12Stephan Hochdörfer
 
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Stephan Hochdörfer
 
Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12Stephan Hochdörfer
 
Testing untestable code - Herbstcampus12
Testing untestable code - Herbstcampus12Testing untestable code - Herbstcampus12
Testing untestable code - Herbstcampus12Stephan Hochdörfer
 
Testing untestable code - oscon 2012
Testing untestable code - oscon 2012Testing untestable code - oscon 2012
Testing untestable code - oscon 2012Stephan Hochdörfer
 
Introducing a Software Generator Framework - JAZOON12
Introducing a Software Generator Framework - JAZOON12Introducing a Software Generator Framework - JAZOON12
Introducing a Software Generator Framework - JAZOON12Stephan Hochdörfer
 
Real World Dependency Injection SE - phpugrhh
Real World Dependency Injection SE - phpugrhhReal World Dependency Injection SE - phpugrhh
Real World Dependency Injection SE - phpugrhhStephan Hochdörfer
 

Plus de Stephan Hochdörfer (20)

Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
 
Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8
 
Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13
 
Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13 Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13
 
Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13
 
Offline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmkaOffline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmka
 
Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13
 
Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13
 
Offline-Strategien für HTML5Web Applikationen - WMMRN12
Offline-Strategien für HTML5Web Applikationen - WMMRN12Offline-Strategien für HTML5Web Applikationen - WMMRN12
Offline-Strategien für HTML5Web Applikationen - WMMRN12
 
Testing untestable code - IPC12
Testing untestable code - IPC12Testing untestable code - IPC12
Testing untestable code - IPC12
 
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
 
Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012
 
Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12
 
Testing untestable code - Herbstcampus12
Testing untestable code - Herbstcampus12Testing untestable code - Herbstcampus12
Testing untestable code - Herbstcampus12
 
Testing untestable code - oscon 2012
Testing untestable code - oscon 2012Testing untestable code - oscon 2012
Testing untestable code - oscon 2012
 
Introducing a Software Generator Framework - JAZOON12
Introducing a Software Generator Framework - JAZOON12Introducing a Software Generator Framework - JAZOON12
Introducing a Software Generator Framework - JAZOON12
 
The state of DI - DPC12
The state of DI - DPC12The state of DI - DPC12
The state of DI - DPC12
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
Real World Dependency Injection SE - phpugrhh
Real World Dependency Injection SE - phpugrhhReal World Dependency Injection SE - phpugrhh
Real World Dependency Injection SE - phpugrhh
 

Dernier

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 

Dernier (20)

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 

Your Business. Your Language. Your Code - dpc13

  • 1. Your business. Your language. Your code. Stephan Hochdörfer, bitExpert AG
  • 2. Your business. Your language. Your code. About me  Stephan Hochdörfer  Head of IT at bitExpert AG, Germany  enjoying PHP since 1999  S.Hochdoerfer@bitExpert.de  @shochdoerfer
  • 3. Your business. Your language. Your code. Focus on core business values!
  • 4. Your business. Your language. Your code. Get rid of the "framework speak"!
  • 5. Your business. Your language. Your code. Trust the framework...
  • 6. Your business. Your language. Your code. ...but understand the underlying technology!
  • 7. Your business. Your language. Your code. Build your own toolset...
  • 8. Your business. Your language. Your code. ...but focus on communication first!
  • 9. Your business. Your language. Your code. Work as a team! (Customer included!)
  • 10. What the customer really wanted? Your business. Your language. Your code.
  • 11. A common language Your business. Your language. Your code.
  • 12. A common language Your business. Your language. Your code. A domain-specific language (DSL) is a programming language designed to be useful for a specific task.
  • 13. A common language: Key characteristic Your business. Your language. Your code. Identifiable domain
  • 14. A common language: Key characteristic Your business. Your language. Your code. „Small language“
  • 15. A common language Your business. Your language. Your code. "[…] I do think that the greatest potential benefit of DSLs comes when business people participate [...]" (Martin Fowler)
  • 16. Domain-specific language: Examples Your business. Your language. Your code. How does a domain-specific language look like?
  • 17. SELECT * from slides WHERE presentationId = 4711 ORDER BY pageNo; Domain-specific language: SQL Your business. Your language. Your code.
  • 18. Feature: Serve coffee In order to earn money Customers should be able to buy coffee at all times Scenario: Buy last coffee Given there are 1 coffees left in the machine And I have deposited 1 dollar When I press the coffee button Then I should be served a coffee Domain-specific language: Gherkin Your business. Your language. Your code.
  • 19. package { 'screen' : ensure => present, } include apache apache::vhost { 'myapp.loc' : docroot => '/srv/myapp.loc/webroot/' } host { 'myapp.loc': ip => '127.0.1.1' } Domain-specific language: Puppet Your business. Your language. Your code.
  • 20. { "require": { "silex/silex": "v1.0.0", "zendframework/zend-mail": "2.1.5", "monolog/monolog": "1.5.0" }, "require-dev": { "phpunit/phpunit": "3.7.19", "phing/phing": "2.5.0" } } Domain-specific language: Composer Your business. Your language. Your code.
  • 21. Domain-specific language: Doctrine Your business. Your language. Your code. /** @Entity **/ class Slides { /** * @OneToOne(targetEntity="Presentation") * @JoinColumn(name="presentation_id", * referencedColumnName="id") **/ private $presentation; // ... } /** @Entity **/ class Presentation { // ... }
  • 23. Why using a DSL? Your business. Your language. Your code.
  • 24. Why using a DSL? Your business. Your language. Your code. Increase your own productivity
  • 25. Why using a DSL? Your business. Your language. Your code. Increase in code quality
  • 26. Why using a DSL? Your business. Your language. Your code. Ignore the implementation details, focus on the domain aspects
  • 27. Why using a DSL? Your business. Your language. Your code.
  • 28. $file = '/path/to/a/file.csv'; $mimepart1 = new MimePart(); $mimepart1->setContent(file_get_contents($file)); $mimepart1->setFilename(basename($file)); $mimepart2 = new MimePart(); $mimepart2->setText('Sample mail body.'); $multipart = new MimeMultipart(); $multipart->addPart($mimepart1); $multipart->addPart($mimepart2); $message = new MimeMessage(); $message->setFrom('foo@bar.org'); $message->addTo('bar@foo.org'); $message->setSubject('Hello'); $message->setContent($multipart); $transport = new MailTransport(); $transport->send($mail); Why using a DSL? Non-DSL example Your business. Your language. Your code.
  • 29. DSL types: You have to decide Your business. Your language. Your code.
  • 30. DSL types: You have to decide Your business. Your language. Your code. Internal DSL vs. External DSL
  • 31. DSL types: Internal DSL Your business. Your language. Your code.
  • 32. DSL types: Internal DSL Your business. Your language. Your code. Fluent API, Expression Builder, Functions, Closures, Annotations
  • 33. Internal DSL: The Fluent API Your business. Your language. Your code.
  • 34. Internal DSL: The Fluent API Your business. Your language. Your code. A fluent interface is an implementation of an object oriented API that aims to provide for more readable code.
  • 35. $file = '/path/to/a/file.csv'; $msg = new MailMessage(); $msg->from('foo@bar.org') ->to('bar@foo.org') ->subject('Hello') ->body('Sample mail body.') ->attachFile($file) ->sendWith(new SmtpTransport()); Internal DSL: The Fluent API Your business. Your language. Your code.
  • 36. Internal DSL: The Fluent API Your business. Your language. Your code. class MailMessage { protected $from; protected $to; public function from($from) { $this->from = $from; return $this; } public function to($to) { $this->to = $to; return $this; } // [...] }
  • 37. Internal DSL: The Fluent API Your business. Your language. Your code. class MailMessage { protected $from; protected $to; public function from($from) { $this->from = $from; return $this; } public function to($to) { $this->to = $to; return $this; } // [...] }
  • 38. Internal DSL: Expression Builder Your business. Your language. Your code.
  • 39. Internal DSL: Expression Builder Your business. Your language. Your code. Provides a fluent interface on top of an existing API.
  • 40. class MimeMessage { public function setFrom($from) { } public function addTo($to) { } public function setSubject($subject) { } public function setContent(MimeMultipart $content) { } } Internal DSL: Expression Builder Your business. Your language. Your code.
  • 41. class MailBuilder { protected $msg; protected $multipart; public function __construct() { $this->msg = new MimeMessage(); $this->multipart = new MimeMultipart(); } public function from($from) { $this->msg->setFrom($from); return $this; } public function attachFile($file) { $part = new MimePart(); $part->setContent(file_get_contents($file)); $part->setFilename(basename($file)); $this->multipart->addPart($part); return $this; } // [...] } Internal DSL: Expression Builder Your business. Your language. Your code.
  • 42. Internal DSL: Expression Builder Your business. Your language. Your code. $file = '/path/to/a/file.csv'; $msg = new MailBuilder(); $msg->from('foo@bar.org') ->to('bar@foo.org') ->subject('Hello') ->body('Sample mail body.') ->attachFile($file) ->sendWith(new SmtpTransport());
  • 43. Internal DSL: Expression Builder (Improved) Your business. Your language. Your code. class MailBuilder { protected $msg; protected $parts; public function __construct() { $this->msg = new MimeMessage(); $this->parts = array(); } public function from($from) { $this->msg->setFrom($from); return $this; } public function attachFile($file) { $builder = new PartBuilder($this); $this->parts[] = $builder; return $builder; } // [...] }
  • 44. class PartBuilder { protected $part; public function __construct() { $this->part = new MimePart(); } public function content($content) { $this->part->setContent($content); return $this; } public function filename($filename) { $this->part->setFilename($filename); return $this; } // [...] } Internal DSL: Expression Builder (Improved) Your business. Your language. Your code.
  • 45. Internal DSL: Functions Your business. Your language. Your code.
  • 46. Internal DSL: Functions Your business. Your language. Your code. Using a combination of function calls as a sequence of statements.
  • 47. Internal DSL: Functions Your business. Your language. Your code. $file = '/path/to/a/file.csv'; message(); from('foo@bar.org'); to('bar@foo.org'); subject('Hello'); body('Sample mail body.'); attachFile($file); sendWith(new SmtpTransport());
  • 48. Internal DSL: Nested Functions Your business. Your language. Your code.
  • 49. Internal DSL: Nested Functions Your business. Your language. Your code. Using nested function calls to reflect the hirarchic nature of the language.
  • 50. $file = '/path/to/a/file.csv'; message( header( from('foo@bar.org'), to('bar@foo.org'), subject('Hello') ), body('Sample mail body.'), attachments( file($file) ), sendWith(new SmtpTransport()) ); Internal DSL: Nested Functions Your business. Your language. Your code.
  • 51. $file = '/path/to/a/file.csv'; $file2 = '/path/to/a/file2.csv'; message( header( [ from('foo@bar.org'), to('bar@foo.org'), subject('Hello') ] ), body('Sample mail body.'), attachments( [ file($file), file($file2) ] ), sendWith(new SmtpTransport()) ); Internal DSL: Nested Functions (Improved) Your business. Your language. Your code.
  • 52. Internal DSL: Closure Your business. Your language. Your code.
  • 53. Internal DSL: Closure Your business. Your language. Your code. A function or reference to a function together with a referencing environment.
  • 54. $fname = '/path/to/a/file.csv'; $fname2 = '/path/to/a/file2.csv'; $msg = new MailMessageBuilder(); $msg->header(function($header){ $header->from('foo@bar.org') ->to('bar@foo.org') ->subject('Hello'); }) ->body('Sample mail body.') ->attach(function($file){ $file->setContent(file_get_contents($fname) ->setFilename(basename($fname); }) ->attach(function($file){ $file->setContent(file_get_contents($fname2) ->setFilename(basename($fname2); }) ->sendWith(new SmtpTransport()); Internal DSL: Closure Your business. Your language. Your code.
  • 55. Internal DSL: Annotations Your business. Your language. Your code.
  • 56. Internal DSL: Annotations Your business. Your language. Your code. "An annotation is metadata attached to your code." (Rafael Dohms)
  • 57. Internal DSL: Annotations Your business. Your language. Your code. /** @Entity **/ class Slides { /** * @OneToOne(targetEntity="Presentation") * @JoinColumn(name="presentation_id", * referencedColumnName="id") **/ private $presentation; // ... } /** @Entity **/ class Presentation { // ... }
  • 58. class MyCustomController { // [...] public function adminAction() { $user = $this->authService->getLoggedInUser(); if(!$user->hasRole('ROLE_ADMIN')) { throw new AccessDeniedException(); } // proceed with main logic... } } Internal DSL: Annotations Your business. Your language. Your code.
  • 59. class MyCustomController { // [...] /** * @Allow(roles="ROLE_ADMIN") */ public function adminAction() { // proceed with main logic... } } Internal DSL: Annotations Your business. Your language. Your code.
  • 60. External DSL Your business. Your language. Your code.
  • 61. External DSL Your business. Your language. Your code. External DSLs provide a greater syntactic freedom
  • 62. External DSL: Language development Your business. Your language. Your code.
  • 63. Code generation Your business. Your language. Your code.
  • 64. Code generation Your business. Your language. Your code. From DSL to „code“ ;)
  • 65. Code generation Your business. Your language. Your code. Template Generation vs. Transformer Generation
  • 66. Code generation: Template Generation Your business. Your language. Your code. <?php class [className] { protected $service; public function __construct([serviceType] $service) { $this->service = $service; } }
  • 67. Code generation: Transformer Generation Your business. Your language. Your code. <?php renderPageHeader(); renderMenubar(); renderProducts(); renderFooter(); Output driven approach:
  • 68. Code generation: Transformer Generation Your business. Your language. Your code. <?php foreach($products as $product) { renderName($product); renderImage($product); renderPrice($product); } Input driven approach:
  • 69. Internal DSL vs. External DSL Your business. Your language. Your code. What to choose?
  • 70. Problems with DSLs Your business. Your language. Your code.
  • 71. Problems with DSLs Your business. Your language. Your code. Yet-Another-Language-To-Learn syndrome
  • 72. Problems with DSLs Your business. Your language. Your code. Depending on the DSL complexity creating a language can be cost intense
  • 73. Famous final words ;) Your business. Your language. Your code. "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." (Martin Fowler)
  • 74. Recommended books Your business. Your language. Your code.