• Like
OSDC.TW - Gutscript for PHP haters
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

OSDC.TW - Gutscript for PHP haters

  • 815 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
815
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
7
Comments
0
Likes
8

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Gutscript A new language for PHP haters @c9s
  • 2. PHP
  • 3. 說到 PHP,你有什麼感覺?
  • 4. PHP 哩來!哩來!來來來!來來來來來來 來來來來來來來來來來來來來來 來來來來來來來來來來來來來來 來來來來來來來來來來來來來來 來來來來來來來來來來來來來來 來來來來來來來來來來來來來來 來來來來來來來來來來來來來來
  • 5. 《獨家直擊》來來哥的⼀一天【胖⻁虎黨PHP】
  • 6. 先談 PHP
  • 7. function foo() { 累贅的函數表⽰示法
  • 8. namespace FooBar; 醜到歪七扭⼋八的 namespace
  • 9. if (…) { } else { } foreach($list as $item) { 太多括號
  • 10. array("key" => “value", "foo" => "bar"); [“key" => “value”, "foo" => “bar”]; 煩⼈人的 “=>”
  • 11. array array_map ( callable $callback , array $array1 [, array $... ] ) array array_filter ( array $array = array() [, callable $callback = Function() ] ) 不⼀一致的函數原形 / 不直覺的呼叫⽅方式
  • 12. 難道沒有優點嗎?
  • 13. Dynamic
  • 14. Easy To Deploy
  • 15. Plenty Open Source Library
  • 16. Easy To Learn & Development
  • 17. 就算是升天的 Haskeller 也是可以被抓回來寫 PHP
  • 18. 程式語⾔言設計的嘗試
  • 19. ⼀一直找不到理由
  • 20. CoffeeScript by Jeremy Ashkenas Facebook HipHop / HHVM
  • 21. HHVM 改善了執⾏行效能
  • 22. HHVM Benchmark & Compatibility http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16
  • 23. Requests per second, middle response The higher the better http://blog.liip.ch/archive/2013/10/29/hhvm-and-symfony2.html
  • 24. PHP VM 改善了,但語 ⾔言還是⼀一樣爛
  • 25. A new language beyond PHP
  • 26. For Fun
  • 27. 拋棄 PHP 的向後相容
  • 28. 重新設計
  • 29. The Language • Concise • Easy to learn, Easy to write, Readability • Brings benefits from Ruby and Perl
  • 30. The Generated Code • Can reuse existing PHP libraries • Compatible with PHP 5.4 • Generate PHPDoc format comments automatically.
  • 31. PHP Gutscript HHVM Zend VM HipHop Compiler C++ Compile to PHP and run on HHVM or ZendVM
  • 32. Optimization PHP 5.4 PHP 5.3 Javascript PHP C Extension Gutscript Gutscript (Future)
  • 33. Synopsis
  • 34. class Person # Print the name say :: (name) -> "Hello #{name}, Good morning" ! getPhone :: -> "12345678" ! setName :: (string name) -> @name = name ! if str =~ /[a-z]/ say "matched!"
  • 35. <?php class Person { /** * Print the name * * @param mixed $name */ function say($name) { return "Hello " . $name . ', Good morning'; } ! function getPhone() { return "12345678"; } ! /** * @param string $name */ function setName($name) { $this->name = $name; } } if ( preg_match('[a-z]',$str) ) { echo "matched!"; }
  • 36. Expression
  • 37. a = 3 + 5 b = 3.1415 c = "Hello" ++ "World"
  • 38. a = 3 + 5 b = 3.1415 c = "Hello" ++ "World" <?php $a = 3 + 5; $b = 3.1415; $c = "Hello" . "World"
  • 39. Control Flow
  • 40. say "Hello" if a > 10
  • 41. say "Hello" if a > 10 <?php if ( $a > 10 ) { echo “Hello"; }
  • 42. say i for i in [ 1..10 ]
  • 43. say i for i in [ 1..10 ] <?php for ( $i = 1; $i < 10 ; $i++ ) { echo $i; }
  • 44. Function
  • 45. area :: (x,y) -> x * y
  • 46. area :: (x,y) -> x * y <?php function area($x, $y) { return $x * $y; }
  • 47. Class
  • 48. class Person getName :: () -> "John" getPhone :: () -> "12345678"
  • 49. class Person getName :: () -> "John" getPhone :: () -> "12345678" <?php class Person { function getName() { return "John"; } function getPhone() { return "12345678"; } }
  • 50. Class Inheritance
  • 51. Bring ideas from Perl 6
  • 52. class Person is Object does ArrayIterator getName :: () -> "name"
  • 53. class Person is Object does ArrayIterator getName :: () -> "name" <?php class Person extends Object implements ArrayIterator { function getName() { return "name"; } }
  • 54. Regular Expression
  • 55. say $1 if foo =~ /([a-z])+/ <?php if ( preg_match('/([a-z])+/', $foo, $regs) ) { echo $regs[1]; }
  • 56. Map & Grep
  • 57. phones = map (x) -> { x.phone } contacts <?php $phones = array_map(function($x) { return $x->phone; }, $contacts);
  • 58. sort (a,b) -> { a <=> b } list <?php function __sort1($a, $b) { if ( $a == $b ) { return 0; } return ( $a < $b ) ? -1 : 1; } sort($list, “__sort1”);
  • 59. Auto-generated PHPDoc
  • 60. # method description # @param name contact’s name setName :: (string name) -> @name = name <?php /** * method description * @param string $name contact’s name */ function setName($name) { $this->name = $name; }
  • 61. Optimization
  • 62. for Fun
  • 63. Inline Expansion
  • 64. Function calls are pretty slow in PHP
  • 65. Refactoring produces more functions
  • 66. function foo($a, $b) { return $a + $b; } $ret = foo(1,2) + foo(3,4);
  • 67. $ret = (1+2) + (3+4);
  • 68. Dead Code Elimination
  • 69. function foo($a, $b) { return $a + $b; } function bar() { … } $ret = foo(1,2) + foo(3,4);
  • 70. function foo($a, $b) { return $a + $b; } $ret = foo(1,2) + foo(3,4);
  • 71. Useful when using only small part functions of large libraries.
  • 72. Constant Folding
  • 73. $ret = (1+2) + (3+4);
  • 74. $ret = 10;
  • 75. Code Minifying
  • 76. compress all PHP source files => phar
  • 77. Implementation
  • 78. Implemented in Go
  • 79. pre-compiled and no dependency
  • 80. pre-compiled
  • 81. static linking
  • 82. No dependency
  • 83. Concurrency Support
  • 84. • hand-written lexer in Go • pretty simple go yacc - LALR parser derived from Inferno's utils/iyacc/yacc.c
  • 85. Parsing with concurrency • Using Go channel to send tokens from Tokenizer • Parser reads tokens from Go channel asynchronously.
  • 86. Tokenizer Parser Async token through channel
  • 87. ParserTokenizer ASTFile File File File File Go Channel ParserTokenizer AST Worker (Go Routine) Worker (Go Routine) ....... ....... Result
  • 88. Setup
  • 89. # fork this project…
  • 90. # fork this project… $ git clone git@github.com:you/gutscript.git
  • 91. # fork this project… $ git clone git@github.com:you/gutscript.git $ cd gutscript
  • 92. # fork this project… $ git clone git@github.com:you/gutscript.git $ cd gutscript $ source goenv
  • 93. # fork this project… $ git clone git@github.com:you/gutscript.git $ cd gutscript $ source goenv $ make
  • 94. Join Us! https://github.com/c9s/gutscript