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 si...
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 languageYour business. Your language. Your code.
A common languageYour business. Your language. Your code.A domain-specific language (DSL)is a programming language designe...
A common language: Key characteristicYour business. Your language. Your code.Identifiable domain
A common language: Key characteristicYour business. Your language. Your code.„Small language“
A common languageYour business. Your language. Your code."[…] I do think that the greatestpotential benefit of DSLs comes ...
Domain-specific language: ExamplesYour business. Your language. Your code.How does a domain-specificlanguage look like?
SELECT * from slides WHERE presentationId = 4711 ORDER BYpageNo;Domain-specific language: SQLYour business. Your language....
Feature: Serve coffeeIn order to earn moneyCustomers should be able tobuy coffee at all timesScenario: Buy last coffeeGive...
package { screen :ensure => present,}include apacheapache::vhost { myapp.loc :docroot => /srv/myapp.loc/webroot/}host { my...
{"require": {"silex/silex": "v1.0.0","zendframework/zend-mail": "2.1.5","monolog/monolog": "1.5.0"},"require-dev": {"phpun...
Domain-specific language: DoctrineYour business. Your language. Your code./** @Entity **/class Slides{/*** @OneToOne(targe...
<?phpecho "I am a DSL, too!";Domain-specific language: PHPYour 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->setFi...
DSL types: You have to decideYour business. Your language. Your code.
DSL types: You have to decideYour business. Your language. Your code.Internal DSLvs.External DSL
DSL types: Internal DSLYour business. Your language. Your code.
DSL types: Internal DSLYour business. Your language. Your code.Fluent API, Expression Builder,Functions, Closures, Annotat...
Internal DSL: The Fluent APIYour business. Your language. Your code.
Internal DSL: The Fluent APIYour business. Your language. Your code.A fluent interface is an implementationof an object or...
$file = /path/to/a/file.csv;$msg = new MailMessage();$msg->from(foo@bar.org)->to(bar@foo.org)->subject(Hello)->body(Sample...
Internal DSL: The Fluent APIYour business. Your language. Your code.class MailMessage {protected $from;protected $to;publi...
Internal DSL: The Fluent APIYour business. Your language. Your code.class MailMessage {protected $from;protected $to;publi...
Internal DSL: Expression BuilderYour business. Your language. Your code.
Internal DSL: Expression BuilderYour business. Your language. Your code.Provides a fluent interfaceon top of an existing A...
class MimeMessage {public function setFrom($from) {}public function addTo($to) {}public function setSubject($subject) {}pu...
class MailBuilder {protected $msg;protected $multipart;public function __construct() {$this->msg = new MimeMessage();$this...
Internal DSL: Expression BuilderYour business. Your language. Your code.$file = /path/to/a/file.csv;$msg = new MailBuilder...
Internal DSL: Expression Builder (Improved)Your business. Your language. Your code.class MailBuilder {protected $msg;prote...
class PartBuilder {protected $part;public function __construct() {$this->part = new MimePart();}public function content($c...
Internal DSL: FunctionsYour business. Your language. Your code.
Internal DSL: FunctionsYour business. Your language. Your code.Using a combination of function callsas a sequence of state...
Internal DSL: FunctionsYour business. Your language. Your code.$file = /path/to/a/file.csv;message();from(foo@bar.org);to(...
Internal DSL: Nested FunctionsYour business. Your language. Your code.
Internal DSL: Nested FunctionsYour business. Your language. Your code.Using nested function calls to reflectthe hirarchic ...
$file = /path/to/a/file.csv;message(header(from(foo@bar.org),to(bar@foo.org),subject(Hello)),body(Sample mail body.),attac...
$file = /path/to/a/file.csv;$file2 = /path/to/a/file2.csv;message(header([from(foo@bar.org),to(bar@foo.org),subject(Hello)...
Internal DSL: ClosureYour business. Your language. Your code.
Internal DSL: ClosureYour business. Your language. Your code.A function or reference to a functiontogether with a referenc...
$fname = /path/to/a/file.csv;$fname2 = /path/to/a/file2.csv;$msg = new MailMessageBuilder();$msg->header(function($header)...
Internal DSL: AnnotationsYour business. Your language. Your code.
Internal DSL: AnnotationsYour business. Your language. Your code."An annotation is metadataattached to your code."(Rafael ...
Internal DSL: AnnotationsYour business. Your language. Your code./** @Entity **/class Slides{/*** @OneToOne(targetEntity="...
class MyCustomController {// [...]public function adminAction() {$user = $this->authService->getLoggedInUser();if(!$user->...
class MyCustomController {// [...]/*** @Allow(roles="ROLE_ADMIN")*/public function adminAction() {// proceed with main log...
External DSLYour business. Your language. Your code.
External DSLYour business. Your language. Your code.External DSLs provide agreater syntactic freedom
External DSL: Language developmentYour business. Your language. Your code.
Code generationYour business. Your language. Your code.
Code generationYour business. Your language. Your code.From DSL to „code“ ;)
Code generationYour business. Your language. Your code.Template Generationvs.Transformer Generation
Code generation: Template GenerationYour business. Your language. Your code.<?phpclass [className] {protected $service;pub...
Code generation: Transformer GenerationYour business. Your language. Your code.<?phprenderPageHeader();renderMenubar();ren...
Code generation: Transformer GenerationYour business. Your language. Your code.<?phpforeach($products as $product) {render...
Internal DSL vs. External DSLYour business. Your language. Your code.What to choose?
Problems with DSLsYour business. Your language. Your code.
Problems with DSLsYour business. Your language. Your code.Yet-Another-Language-To-Learnsyndrome
Problems with DSLsYour business. Your language. Your code.Depending on the DSL complexitycreating a language can be cost i...
Famous final words ;)Your business. Your language. Your code."Any fool can write code that acomputer can understand. Goodp...
Recommended booksYour business. Your language. Your code.
Thank you!
http://joind.in/8640
Creditshttp://robonthemoon.wordpress.com/2009/11/24/what-the-customer-really-wanted-–-happy-thanksgiving/
Upcoming SlideShare
Loading in...5
×

Your Business. Your Language. Your Code - dpc13

464

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
464
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Your Business. Your Language. Your Code - dpc13

  1. 1. Your business. Your language.Your code.Stephan Hochdörfer, bitExpert AG
  2. 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. 3. Your business. Your language. Your code.Focus on core business values!
  4. 4. Your business. Your language. Your code.Get rid of the "framework speak"!
  5. 5. Your business. Your language. Your code.Trust the framework...
  6. 6. Your business. Your language. Your code....but understand the underlying technology!
  7. 7. Your business. Your language. Your code.Build your own toolset...
  8. 8. Your business. Your language. Your code....but focus on communication first!
  9. 9. Your business. Your language. Your code.Work as a team! (Customer included!)
  10. 10. What the customer really wanted?Your business. Your language. Your code.
  11. 11. A common languageYour business. Your language. Your code.
  12. 12. A common languageYour business. Your language. Your code.A domain-specific language (DSL)is a programming language designedto be useful for a specific task.
  13. 13. A common language: Key characteristicYour business. Your language. Your code.Identifiable domain
  14. 14. A common language: Key characteristicYour business. Your language. Your code.„Small language“
  15. 15. A common languageYour business. Your language. Your code."[…] I do think that the greatestpotential benefit of DSLs comes whenbusiness people participate [...]"(Martin Fowler)
  16. 16. Domain-specific language: ExamplesYour business. Your language. Your code.How does a domain-specificlanguage look like?
  17. 17. SELECT * from slides WHERE presentationId = 4711 ORDER BYpageNo;Domain-specific language: SQLYour business. Your language. Your code.
  18. 18. Feature: Serve coffeeIn order to earn moneyCustomers should be able tobuy coffee at all timesScenario: Buy last coffeeGiven there are 1 coffees left in the machineAnd I have deposited 1 dollarWhen I press the coffee buttonThen I should be served a coffeeDomain-specific language: GherkinYour business. Your language. Your code.
  19. 19. package { screen :ensure => present,}include apacheapache::vhost { myapp.loc :docroot => /srv/myapp.loc/webroot/}host { myapp.loc:ip => 127.0.1.1}Domain-specific language: PuppetYour business. Your language. Your code.
  20. 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: ComposerYour business. Your language. Your code.
  21. 21. Domain-specific language: DoctrineYour business. Your language. Your code./** @Entity **/class Slides{/*** @OneToOne(targetEntity="Presentation")* @JoinColumn(name="presentation_id",* referencedColumnName="id")**/private $presentation;// ...}/** @Entity **/class Presentation{// ...}
  22. 22. <?phpecho "I am a DSL, too!";Domain-specific language: PHPYour business. Your language. Your code.
  23. 23. Why using a DSL?Your business. Your language. Your code.
  24. 24. Why using a DSL?Your business. Your language. Your code.Increase your own productivity
  25. 25. Why using a DSL?Your business. Your language. Your code.Increase in code quality
  26. 26. Why using a DSL?Your business. Your language. Your code.Ignore the implementation details,focus on the domain aspects
  27. 27. Why using a DSL?Your business. Your language. Your code.
  28. 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 exampleYour business. Your language. Your code.
  29. 29. DSL types: You have to decideYour business. Your language. Your code.
  30. 30. DSL types: You have to decideYour business. Your language. Your code.Internal DSLvs.External DSL
  31. 31. DSL types: Internal DSLYour business. Your language. Your code.
  32. 32. DSL types: Internal DSLYour business. Your language. Your code.Fluent API, Expression Builder,Functions, Closures, Annotations
  33. 33. Internal DSL: The Fluent APIYour business. Your language. Your code.
  34. 34. Internal DSL: The Fluent APIYour business. Your language. Your code.A fluent interface is an implementationof an object oriented API that aims toprovide for more readable code.
  35. 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 APIYour business. Your language. Your code.
  36. 36. Internal DSL: The Fluent APIYour 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. 37. Internal DSL: The Fluent APIYour 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. 38. Internal DSL: Expression BuilderYour business. Your language. Your code.
  39. 39. Internal DSL: Expression BuilderYour business. Your language. Your code.Provides a fluent interfaceon top of an existing API.
  40. 40. class MimeMessage {public function setFrom($from) {}public function addTo($to) {}public function setSubject($subject) {}public function setContent(MimeMultipart $content) {}}Internal DSL: Expression BuilderYour business. Your language. Your code.
  41. 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 BuilderYour business. Your language. Your code.
  42. 42. Internal DSL: Expression BuilderYour 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. 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. 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. 45. Internal DSL: FunctionsYour business. Your language. Your code.
  46. 46. Internal DSL: FunctionsYour business. Your language. Your code.Using a combination of function callsas a sequence of statements.
  47. 47. Internal DSL: FunctionsYour 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. 48. Internal DSL: Nested FunctionsYour business. Your language. Your code.
  49. 49. Internal DSL: Nested FunctionsYour business. Your language. Your code.Using nested function calls to reflectthe hirarchic nature of the language.
  50. 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 FunctionsYour business. Your language. Your code.
  51. 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. 52. Internal DSL: ClosureYour business. Your language. Your code.
  53. 53. Internal DSL: ClosureYour business. Your language. Your code.A function or reference to a functiontogether with a referencing environment.
  54. 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: ClosureYour business. Your language. Your code.
  55. 55. Internal DSL: AnnotationsYour business. Your language. Your code.
  56. 56. Internal DSL: AnnotationsYour business. Your language. Your code."An annotation is metadataattached to your code."(Rafael Dohms)
  57. 57. Internal DSL: AnnotationsYour business. Your language. Your code./** @Entity **/class Slides{/*** @OneToOne(targetEntity="Presentation")* @JoinColumn(name="presentation_id",* referencedColumnName="id")**/private $presentation;// ...}/** @Entity **/class Presentation{// ...}
  58. 58. class MyCustomController {// [...]public function adminAction() {$user = $this->authService->getLoggedInUser();if(!$user->hasRole(ROLE_ADMIN)) {throw new AccessDeniedException();}// proceed with main logic...}}Internal DSL: AnnotationsYour business. Your language. Your code.
  59. 59. class MyCustomController {// [...]/*** @Allow(roles="ROLE_ADMIN")*/public function adminAction() {// proceed with main logic...}}Internal DSL: AnnotationsYour business. Your language. Your code.
  60. 60. External DSLYour business. Your language. Your code.
  61. 61. External DSLYour business. Your language. Your code.External DSLs provide agreater syntactic freedom
  62. 62. External DSL: Language developmentYour business. Your language. Your code.
  63. 63. Code generationYour business. Your language. Your code.
  64. 64. Code generationYour business. Your language. Your code.From DSL to „code“ ;)
  65. 65. Code generationYour business. Your language. Your code.Template Generationvs.Transformer Generation
  66. 66. Code generation: Template GenerationYour business. Your language. Your code.<?phpclass [className] {protected $service;public function __construct([serviceType] $service) {$this->service = $service;}}
  67. 67. Code generation: Transformer GenerationYour business. Your language. Your code.<?phprenderPageHeader();renderMenubar();renderProducts();renderFooter();Output driven approach:
  68. 68. Code generation: Transformer GenerationYour business. Your language. Your code.<?phpforeach($products as $product) {renderName($product);renderImage($product);renderPrice($product);}Input driven approach:
  69. 69. Internal DSL vs. External DSLYour business. Your language. Your code.What to choose?
  70. 70. Problems with DSLsYour business. Your language. Your code.
  71. 71. Problems with DSLsYour business. Your language. Your code.Yet-Another-Language-To-Learnsyndrome
  72. 72. Problems with DSLsYour business. Your language. Your code.Depending on the DSL complexitycreating a language can be cost intense
  73. 73. Famous final words ;)Your business. Your language. Your code."Any fool can write code that acomputer can understand. Goodprogrammers write code thathumans can understand."(Martin Fowler)
  74. 74. Recommended booksYour business. Your language. Your code.
  75. 75. Thank you!
  76. 76. http://joind.in/8640
  77. 77. Creditshttp://robonthemoon.wordpress.com/2009/11/24/what-the-customer-really-wanted-–-happy-thanksgiving/

×