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

More Related Content

What's hot

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
Hideaki Ohno
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 

What's hot (20)

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
ekb.py - Python VS ...
ekb.py - Python VS ...ekb.py - Python VS ...
ekb.py - Python VS ...
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 

Viewers also liked (6)

Goqt
GoqtGoqt
Goqt
 
Golang Taipei Gathering #15 - 進擊的 Gobot!
Golang Taipei Gathering #15 - 進擊的 Gobot!Golang Taipei Gathering #15 - 進擊的 Gobot!
Golang Taipei Gathering #15 - 進擊的 Gobot!
 
Gtg12
Gtg12Gtg12
Gtg12
 
Full-stack go with GopherJS
Full-stack go with GopherJSFull-stack go with GopherJS
Full-stack go with GopherJS
 
Project52
Project52Project52
Project52
 
Use go channel to write a disk queue
Use go channel to write a disk queueUse go channel to write a disk queue
Use go channel to write a disk queue
 

Similar to OSDC.TW - Gutscript for PHP haters

Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
thinkphp
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
Hung-yu Lin
 

Similar to OSDC.TW - Gutscript for PHP haters (20)

Hiphop php
Hiphop phpHiphop php
Hiphop php
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
What's New in PHP 5.5
What's New in PHP 5.5What's New in PHP 5.5
What's New in PHP 5.5
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Workshop unittesting
Workshop unittestingWorkshop unittesting
Workshop unittesting
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 

More from Lin Yo-An (11)

Getting merged
Getting mergedGetting merged
Getting merged
 
OSDC.TW 2014 building popular open source projects
OSDC.TW 2014   building popular open source projectsOSDC.TW 2014   building popular open source projects
OSDC.TW 2014 building popular open source projects
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1
 
Secret sauce of building php applications
Secret sauce of building php applicationsSecret sauce of building php applications
Secret sauce of building php applications
 
LazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHP
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script Programming
 
CPAN 模組二三事
CPAN 模組二三事CPAN 模組二三事
CPAN 模組二三事
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

OSDC.TW - Gutscript for PHP haters