SlideShare a Scribd company logo
SEMANTIC WEAPONS
PHP Conf 2016
HELLO STRANGER
SEMANTIC WEAPONS
$ id -un
– carlos@semantic.mx
– tweet me @cvences
– Founded a 4yo development shop
– semanticweapons.com
#phpconmx
and we’re hiring!
HELLO STRANGER
SEMANTIC WEAPONS
SEMANTIC WEAPONS
PHP for Python Developers
SEMANTIC WEAPONS
PHP for Python Developers
Web Development & General Scripting
SEMANTIC WEAPONS
$ membership operator _
$inArray = in_array(5, range(0, 10)) === TRUE;
SEMANTIC WEAPONS
$ membership operator _
in_array = 5 in range(10) == True
SEMANTIC WEAPONS
$ membership operator _
in_array = 5 in range(10) == True
>>> in_array
False
SEMANTIC WEAPONS
$ default values _
# counting dictionary keys
from collections import defaultdict
log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', 'warn']
stats = defaultdict(int)
for entry in log:
stats[entry] += 1
SEMANTIC WEAPONS
$ default values _
// counting elements
$log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn'];
$stats = [];
foreach ($log as $entry){
$stats[$entry] = $stats[$entry]++ ?: 0;
}
SEMANTIC WEAPONS
$ default values _
// counting elements
$log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn'];
$stats = [];
foreach ($log as $entry){
$stats[$entry]++;
}
SEMANTIC WEAPONS
$ default values _
// counting elements
$log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn'];
$stats = [];
foreach ($log as $entry){
$stats[$entry]++;
}
# counting dictionary keys
from collections import defaultdict
log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn']
stats = defaultdict(int)
for entry in log:
stats[entry] += 1
SEMANTIC WEAPONS
Memory consumption
– C’s pointers
– SQL’s LIMIT statement
– strcmp, strcpy, strcat
– strncmp, strncpy, strncat
– buffer overflow
SEMANTIC WEAPONS
Memory consumption
– C’s pointers
– SQL’s LIMIT statement
– strcmp, strcpy, strcat
– strncmp, strncpy, strncat
– buffer overflow
¿Quién agregó
la clausula LIMIT
a mini SQL 1.x?
SEMANTIC WEAPONS
$ Array
function myRange($max = 10) {
$numeros = [];
$num = 1;
while ($num < $max) {
array_push($numeros, $num);
$num++;
}
return $numeros;
}
function sum($max = 10) {
$sumatoria = 0;
foreach (myRange($max) as $num) {
$sumatoria += $num;
}
echo $sumatoria;
}
sum(1000000);
SEMANTIC WEAPONS
$ Iterator
class NumberIter implements Iterator {
private $position = 0;
private $array = [];
public function __construct($array = []) {
$this->position = 0;
$this->array = $array;
}
public function rewind() {
$this->position = 0;
}
public function current() {
return $this->array[$this->position];
}
public function key() {
return $this->position;
}
public function next() {
++$this->position;
}
public function valid() {
return isset($this->array[$this->position]);
}
}
function sum($max = 10) {
$sumatoria = 0;
$numberIter = new NumberIter($array = range(1, ($max - 1)));
foreach ($numberIter as $num) {
$sumatoria += $num;
}
echo $sumatoria;
}
sum(1000000);
SEMANTIC WEAPONS
$ PHP Arrays vs Iterators
foreach (myRange($max) as $num) {
$sumatoria += $num;
}
foreach ($numberIter as $num) {
$sumatoria += $num;
}
SEMANTIC WEAPONS
Entering
Generators
SEMANTIC WEAPONS
$ Generators
function myRange($max = 10) {
// $numeros = [];
$num = 1;
while ($num < $max) {
yield $num;
$num++;
}
// return $numeros;
}
function sum($max = 10) {
$sumatoria = 0;
foreach (myRange($max) as $num) {
$sumatoria += $num;
}
echo $sumatoria;
}
sum(1000000);
SEMANTIC WEAPONS
Generators
– Implement Iterators
– DRY
– Can traverse with foreach
– foreach does not use IAP (>7.0.0)
– Uses hashtable iterators now
– Does not build an array in-memory
– Also speeds time to generate
Note: – Calling range(0, 1000000) will result in well over 100 MB of memory being used.
SEMANTIC WEAPONS
$ Iterators, Generators and Arrays
class NumberIter implements Iterator {
private $position = 0;
private $array = [];
public function __construct($array = []) {
$this->position = 0;
$this->array = $array;
}
public function rewind() {
$this->position = 0;
}
public function current() {
return $this->array[$this->position];
}
public function key() {
return $this->position;
}
public function next() {
++$this->position;
}
public function valid() {
return isset($this->array[$this->position]);
}
}
function myRange($max = 10) {
$num = 1;
while ($num < $max) {
yield $num;
$num++;
}
}
array range ($start, $end, $step)
SEMANTIC WEAPONS
$ Iterators, Generators and Arrays
class NumberIter implements Iterator {
private $position = 0;
private $array = [];
public function __construct($array = []) {
$this->position = 0;
$this->array = $array;
}
public function rewind() {
$this->position = 0;
}
public function current() {
return $this->array[$this->position];
}
public function key() {
return $this->position;
}
public function next() {
++$this->position;
}
public function valid() {
return isset($this->array[$this->position]);
}
}
function myRange($max = 10) {
$num = 1;
while ($num < $max) {
yield $num;
$num++;
}
}
SEMANTIC WEAPONS
Case of Study
SEMANTIC WEAPONS
$ PHP 7.1.0 RC2_
SEMANTIC WEAPONS
Using Generators
SEMANTIC WEAPONS
$ PHP 7.1.0 RC2_
SEMANTIC WEAPONS
Using Iterators
SEMANTIC WEAPONS
HELLO STRANGER
PHP 7.1.0 RC2
SEMANTIC WEAPONS
$ time
SEMANTIC WEAPONS
To be or not to be
– Using iterators is great
– foreach in 7.0.0 rocks!
– lists are fat, sequences evaluate lazily
– Lazy is good
SEMANTIC WEAPONS
Warning: sort() expects parameter 1 to be array, object given
SEMANTIC WEAPONS
But…
– Python iterators introduced in 2.2 (2001)
– range -> xrange -> range
– PHP yield introduced in 5.5.0+ (2013)
– Iterator name space may clash
– What’s wrong with iterator_to_array?
– PHP ArrayAccess
Blog Post: SPL Iterators against the performance
PHP Manual: /language.generators.overview.php
SEMANTIC WEAPONS
Readability
SEMANTIC WEAPONS
$ unpacking a list _
sum_of_numbers = sum([x**3 for x in range(10000)])
SEMANTIC WEAPONS
$ unpacking an array _
$sumOfNumbers = 0;
foreach (range(1, 10000) as $num) {
$sumOfNumbers += pow($num, 3);
}
SEMANTIC WEAPONS
$ unpacking an array _
// second try
$processArray = function($method, $array) {
return array_map($method, $array);
};
$sumOfNumbers = array_sum(
$processArray(
$method = function($x){return pow($x, 3);},
$array = range(0, 10000)
)
);
SEMANTIC WEAPONS
One liners
– means something in English
– easy to understand at first glance
SEMANTIC WEAPONS
$ unpacking an array _
$sumOfNumbers = 0;
foreach (range(1, 10000) as $value) {
$sumOfNumbers += pow($value, 3);
}
// second try
$processArray = function($method, $array) {
return array_map($method, $array);
};
$sumOfNumbers = array_sum(
$processArray(
$method = function($x){return pow($x, 3);},
$array = range(0, 10000)
)
);
// third try
$sumOfNumbers = array_sum(array_map(function($x){return pow($x, 3);}, range(0, 10000)));
SEMANTIC WEAPONS
$ readability _
sum_of_numbers = sum([x**3 for x in range(10000)])
$y = array_sum(array_map(function($x){return pow($x, 3);}, range(0, 10000)));
SEMANTIC WEAPONS
$ looping over two collections _
speakers = ['Javier', 'Joe', 'Rasmus', 'Carlos']
talks = ['Ansible', 'Loopless', 'Deploy', 'Python']
for speaker, talk in zip(speakers, talks):
print(speaker, talk)
SEMANTIC WEAPONS
$ looping over two collections _
$speakers = ['Javier', 'Joe', 'Rasmus', 'Carlos'];
$talks = ['Ansible', 'Loopless', 'Deploy', 'Python'];
$max = min(count($speakers), count($talks));
foreach(range(0, $max-1) as $i){
echo($speakers[$i] .' '. $talks[$i]);
}
SEMANTIC WEAPONS
$ looping over two collections _
// second approach
$speakers = ['Javier', 'Joe', 'Rasmus', 'Carlos'];
$talks = ['Ansible', 'Loopless', 'Deploy', 'Python'];
$meetupTalks = array_combine($speakers, $talks);
foreach($meetupTalks as $speaker => $talk){
echo "$speaker $talk";
}
SEMANTIC WEAPONS
$ looping over two collections _
for speaker, talk in zip(speakers, talks):
print(speaker, talk)
foreach(array_combine($speakers, $talks) as $speaker => $talk)
echo "$speaker $talk";
SEMANTIC WEAPONS
$ python iterators magic, tweet .@cvences
# dado un array asociativo, elimina todos los nombres que empiecen con la letra “c”

meetup_info = {

'Javier': 'Ansible',

'Joe': 'Loopsless',

'Rasmus': 'Deploy',

'Carlos': 'Python',

}



meetup_info = {key: meetup_info[key] for key in meetup_info if not key.lower().startswith('c')}
# dado un modelo con relationships, filtra los blogs cuyos autores tengan o no
# un nombre asignado. El título no incluye la palabra python y ordénalos por fecha
# de creación descendente.


Blog.objects
.filter(entry__authors__isnull=False, entry__authors__name__isnull=True)
.exclude(entry__title__icontains=‘python’)
.order_by(‘-created’)
SEMANTIC WEAPONS
$ python iterators magic
def fib(n):

return (4 << n * (3 + n)) // ((4 << 2 * n) - (2 << n) - 1) & ((2 << n) - 1)
def get_fibonacci_by_position(pos):

"""

Returns the fibonacci number at pos



"""

a, b = 1, 1



for _ in range(pos):

a, b = a + b, a



return b
carlos@semantic.mx
HELLO STRANGER
SEMANTIC WEAPONS

More Related Content

What's hot

Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
Jorn Oomen
 
Codeware
CodewareCodeware
Codeware
Uri Nativ
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
garux
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
Bill Chang
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
Mark Baker
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
Guilherme Blanco
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
Hugo Hamon
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
Yuya Takeyama
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
abrummett
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
Nikita Popov
 
Oops in php
Oops in phpOops in php
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
Rafael Dohms
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
David Stockton
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
osfameron
 
Presentation1
Presentation1Presentation1
Presentation1
Rahadyan Gusti
 

What's hot (20)

Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
 
Codeware
CodewareCodeware
Codeware
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
Oops in php
Oops in phpOops in php
Oops in php
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
Presentation1
Presentation1Presentation1
Presentation1
 

Viewers also liked

Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-Datenbanken
Tobias Trelle
 
How to lose a job?
How to lose a job?How to lose a job?
Video games
Video gamesVideo games
Minnesota Business Owners' Perceptions of State and Local Regulations
Minnesota Business Owners' Perceptions of State and Local RegulationsMinnesota Business Owners' Perceptions of State and Local Regulations
Minnesota Business Owners' Perceptions of State and Local Regulations
Center for Rural Policy & Development
 
Woefstok got talent - PP 2 - de eerste wedstrijd
Woefstok got talent - PP 2  - de eerste wedstrijdWoefstok got talent - PP 2  - de eerste wedstrijd
Woefstok got talent - PP 2 - de eerste wedstrijd
Yvette van Veldhuijsen
 
Blogger !!
Blogger !!Blogger !!
Blogger !!
laa_xunxa_lamejor
 
Bluetooth technology aditya
Bluetooth technology adityaBluetooth technology aditya
Bluetooth technology aditya
akshay8811
 
trabajo 2 Datos
trabajo 2 Datostrabajo 2 Datos
trabajo 2 Datos
cesar82703
 
Fungi
FungiFungi
Fungi
jdrinks
 
Global warming.jasper
Global warming.jasperGlobal warming.jasper
Global warming.jasper
jasperhu
 
Rural Minnesota Journal: Why Everyone Should Care
Rural Minnesota Journal: Why Everyone Should CareRural Minnesota Journal: Why Everyone Should Care
Rural Minnesota Journal: Why Everyone Should Care
Center for Rural Policy & Development
 
Budget 2013
Budget 2013Budget 2013
Budget 2013
Alok Jain
 
Goals of vocabulary learning
Goals of vocabulary learning Goals of vocabulary learning
Goals of vocabulary learning
Karitho Loaiza Osorio
 
Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...
Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...
Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...
Center for Rural Policy & Development
 
vmware optimization
vmware optimizationvmware optimization
vmware optimization
Adithya Venkatesh
 
Markma hyperanimation - del rosario
Markma   hyperanimation - del rosarioMarkma   hyperanimation - del rosario
Markma hyperanimation - del rosario
miyuuh
 
Ntl overview presentation_long
Ntl overview presentation_longNtl overview presentation_long
Ntl overview presentation_long
Rosalyn Alleman
 
Imc presentation
Imc presentationImc presentation
Vocabulary yr
Vocabulary yrVocabulary yr
Vocabulary yr
jdrinks
 
Vocabulary yr
Vocabulary yrVocabulary yr
Vocabulary yr
jdrinks
 

Viewers also liked (20)

Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-Datenbanken
 
How to lose a job?
How to lose a job?How to lose a job?
How to lose a job?
 
Video games
Video gamesVideo games
Video games
 
Minnesota Business Owners' Perceptions of State and Local Regulations
Minnesota Business Owners' Perceptions of State and Local RegulationsMinnesota Business Owners' Perceptions of State and Local Regulations
Minnesota Business Owners' Perceptions of State and Local Regulations
 
Woefstok got talent - PP 2 - de eerste wedstrijd
Woefstok got talent - PP 2  - de eerste wedstrijdWoefstok got talent - PP 2  - de eerste wedstrijd
Woefstok got talent - PP 2 - de eerste wedstrijd
 
Blogger !!
Blogger !!Blogger !!
Blogger !!
 
Bluetooth technology aditya
Bluetooth technology adityaBluetooth technology aditya
Bluetooth technology aditya
 
trabajo 2 Datos
trabajo 2 Datostrabajo 2 Datos
trabajo 2 Datos
 
Fungi
FungiFungi
Fungi
 
Global warming.jasper
Global warming.jasperGlobal warming.jasper
Global warming.jasper
 
Rural Minnesota Journal: Why Everyone Should Care
Rural Minnesota Journal: Why Everyone Should CareRural Minnesota Journal: Why Everyone Should Care
Rural Minnesota Journal: Why Everyone Should Care
 
Budget 2013
Budget 2013Budget 2013
Budget 2013
 
Goals of vocabulary learning
Goals of vocabulary learning Goals of vocabulary learning
Goals of vocabulary learning
 
Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...
Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...
Rural Minnesota Journal: Where will Minnesota's Baby Boomers live in their la...
 
vmware optimization
vmware optimizationvmware optimization
vmware optimization
 
Markma hyperanimation - del rosario
Markma   hyperanimation - del rosarioMarkma   hyperanimation - del rosario
Markma hyperanimation - del rosario
 
Ntl overview presentation_long
Ntl overview presentation_longNtl overview presentation_long
Ntl overview presentation_long
 
Imc presentation
Imc presentationImc presentation
Imc presentation
 
Vocabulary yr
Vocabulary yrVocabulary yr
Vocabulary yr
 
Vocabulary yr
Vocabulary yrVocabulary yr
Vocabulary yr
 

Similar to PHP for Python Developers

Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
Alena Holligan
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
Bradley Holt
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
Leonardo Proietti
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
lichtkind
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
Abbas Ali
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
Jeroen van Dijk
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Durian: a PHP 5.5 microframework with generator-style middleware
Durian: a PHP 5.5 microframework with generator-style middlewareDurian: a PHP 5.5 microframework with generator-style middleware
Durian: a PHP 5.5 microframework with generator-style middleware
Kuan Yen Heng
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
James Titcumb
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
Norhisyam Dasuki
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
Raju Mazumder
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
 
Forget about loops
Forget about loopsForget about loops
Forget about loops
Dušan Kasan
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
Taras Kalapun
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
Lucas Witold Adamus
 

Similar to PHP for Python Developers (20)

Php functions
Php functionsPhp functions
Php functions
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Durian: a PHP 5.5 microframework with generator-style middleware
Durian: a PHP 5.5 microframework with generator-style middlewareDurian: a PHP 5.5 microframework with generator-style middleware
Durian: a PHP 5.5 microframework with generator-style middleware
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Forget about loops
Forget about loopsForget about loops
Forget about loops
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 

Recently uploaded

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 

Recently uploaded (20)

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 

PHP for Python Developers

  • 1. SEMANTIC WEAPONS PHP Conf 2016 HELLO STRANGER
  • 2. SEMANTIC WEAPONS $ id -un – carlos@semantic.mx – tweet me @cvences – Founded a 4yo development shop – semanticweapons.com #phpconmx
  • 3. and we’re hiring! HELLO STRANGER SEMANTIC WEAPONS
  • 4. SEMANTIC WEAPONS PHP for Python Developers
  • 5. SEMANTIC WEAPONS PHP for Python Developers Web Development & General Scripting
  • 6. SEMANTIC WEAPONS $ membership operator _ $inArray = in_array(5, range(0, 10)) === TRUE;
  • 7. SEMANTIC WEAPONS $ membership operator _ in_array = 5 in range(10) == True
  • 8. SEMANTIC WEAPONS $ membership operator _ in_array = 5 in range(10) == True >>> in_array False
  • 9. SEMANTIC WEAPONS $ default values _ # counting dictionary keys from collections import defaultdict log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', 'warn'] stats = defaultdict(int) for entry in log: stats[entry] += 1
  • 10. SEMANTIC WEAPONS $ default values _ // counting elements $log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn']; $stats = []; foreach ($log as $entry){ $stats[$entry] = $stats[$entry]++ ?: 0; }
  • 11. SEMANTIC WEAPONS $ default values _ // counting elements $log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn']; $stats = []; foreach ($log as $entry){ $stats[$entry]++; }
  • 12. SEMANTIC WEAPONS $ default values _ // counting elements $log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn']; $stats = []; foreach ($log as $entry){ $stats[$entry]++; } # counting dictionary keys from collections import defaultdict log = ['warn', 'error', 'debug', 'info', 'warn', 'debug', ‘warn'] stats = defaultdict(int) for entry in log: stats[entry] += 1
  • 13. SEMANTIC WEAPONS Memory consumption – C’s pointers – SQL’s LIMIT statement – strcmp, strcpy, strcat – strncmp, strncpy, strncat – buffer overflow
  • 14. SEMANTIC WEAPONS Memory consumption – C’s pointers – SQL’s LIMIT statement – strcmp, strcpy, strcat – strncmp, strncpy, strncat – buffer overflow ¿Quién agregó la clausula LIMIT a mini SQL 1.x?
  • 15. SEMANTIC WEAPONS $ Array function myRange($max = 10) { $numeros = []; $num = 1; while ($num < $max) { array_push($numeros, $num); $num++; } return $numeros; } function sum($max = 10) { $sumatoria = 0; foreach (myRange($max) as $num) { $sumatoria += $num; } echo $sumatoria; } sum(1000000);
  • 16. SEMANTIC WEAPONS $ Iterator class NumberIter implements Iterator { private $position = 0; private $array = []; public function __construct($array = []) { $this->position = 0; $this->array = $array; } public function rewind() { $this->position = 0; } public function current() { return $this->array[$this->position]; } public function key() { return $this->position; } public function next() { ++$this->position; } public function valid() { return isset($this->array[$this->position]); } } function sum($max = 10) { $sumatoria = 0; $numberIter = new NumberIter($array = range(1, ($max - 1))); foreach ($numberIter as $num) { $sumatoria += $num; } echo $sumatoria; } sum(1000000);
  • 17. SEMANTIC WEAPONS $ PHP Arrays vs Iterators foreach (myRange($max) as $num) { $sumatoria += $num; } foreach ($numberIter as $num) { $sumatoria += $num; }
  • 19. SEMANTIC WEAPONS $ Generators function myRange($max = 10) { // $numeros = []; $num = 1; while ($num < $max) { yield $num; $num++; } // return $numeros; } function sum($max = 10) { $sumatoria = 0; foreach (myRange($max) as $num) { $sumatoria += $num; } echo $sumatoria; } sum(1000000);
  • 20. SEMANTIC WEAPONS Generators – Implement Iterators – DRY – Can traverse with foreach – foreach does not use IAP (>7.0.0) – Uses hashtable iterators now – Does not build an array in-memory – Also speeds time to generate Note: – Calling range(0, 1000000) will result in well over 100 MB of memory being used.
  • 21. SEMANTIC WEAPONS $ Iterators, Generators and Arrays class NumberIter implements Iterator { private $position = 0; private $array = []; public function __construct($array = []) { $this->position = 0; $this->array = $array; } public function rewind() { $this->position = 0; } public function current() { return $this->array[$this->position]; } public function key() { return $this->position; } public function next() { ++$this->position; } public function valid() { return isset($this->array[$this->position]); } } function myRange($max = 10) { $num = 1; while ($num < $max) { yield $num; $num++; } } array range ($start, $end, $step)
  • 22. SEMANTIC WEAPONS $ Iterators, Generators and Arrays class NumberIter implements Iterator { private $position = 0; private $array = []; public function __construct($array = []) { $this->position = 0; $this->array = $array; } public function rewind() { $this->position = 0; } public function current() { return $this->array[$this->position]; } public function key() { return $this->position; } public function next() { ++$this->position; } public function valid() { return isset($this->array[$this->position]); } } function myRange($max = 10) { $num = 1; while ($num < $max) { yield $num; $num++; } }
  • 30. SEMANTIC WEAPONS To be or not to be – Using iterators is great – foreach in 7.0.0 rocks! – lists are fat, sequences evaluate lazily – Lazy is good
  • 31. SEMANTIC WEAPONS Warning: sort() expects parameter 1 to be array, object given
  • 32. SEMANTIC WEAPONS But… – Python iterators introduced in 2.2 (2001) – range -> xrange -> range – PHP yield introduced in 5.5.0+ (2013) – Iterator name space may clash – What’s wrong with iterator_to_array? – PHP ArrayAccess Blog Post: SPL Iterators against the performance PHP Manual: /language.generators.overview.php
  • 34. SEMANTIC WEAPONS $ unpacking a list _ sum_of_numbers = sum([x**3 for x in range(10000)])
  • 35. SEMANTIC WEAPONS $ unpacking an array _ $sumOfNumbers = 0; foreach (range(1, 10000) as $num) { $sumOfNumbers += pow($num, 3); }
  • 36. SEMANTIC WEAPONS $ unpacking an array _ // second try $processArray = function($method, $array) { return array_map($method, $array); }; $sumOfNumbers = array_sum( $processArray( $method = function($x){return pow($x, 3);}, $array = range(0, 10000) ) );
  • 37. SEMANTIC WEAPONS One liners – means something in English – easy to understand at first glance
  • 38. SEMANTIC WEAPONS $ unpacking an array _ $sumOfNumbers = 0; foreach (range(1, 10000) as $value) { $sumOfNumbers += pow($value, 3); } // second try $processArray = function($method, $array) { return array_map($method, $array); }; $sumOfNumbers = array_sum( $processArray( $method = function($x){return pow($x, 3);}, $array = range(0, 10000) ) ); // third try $sumOfNumbers = array_sum(array_map(function($x){return pow($x, 3);}, range(0, 10000)));
  • 39. SEMANTIC WEAPONS $ readability _ sum_of_numbers = sum([x**3 for x in range(10000)]) $y = array_sum(array_map(function($x){return pow($x, 3);}, range(0, 10000)));
  • 40. SEMANTIC WEAPONS $ looping over two collections _ speakers = ['Javier', 'Joe', 'Rasmus', 'Carlos'] talks = ['Ansible', 'Loopless', 'Deploy', 'Python'] for speaker, talk in zip(speakers, talks): print(speaker, talk)
  • 41. SEMANTIC WEAPONS $ looping over two collections _ $speakers = ['Javier', 'Joe', 'Rasmus', 'Carlos']; $talks = ['Ansible', 'Loopless', 'Deploy', 'Python']; $max = min(count($speakers), count($talks)); foreach(range(0, $max-1) as $i){ echo($speakers[$i] .' '. $talks[$i]); }
  • 42. SEMANTIC WEAPONS $ looping over two collections _ // second approach $speakers = ['Javier', 'Joe', 'Rasmus', 'Carlos']; $talks = ['Ansible', 'Loopless', 'Deploy', 'Python']; $meetupTalks = array_combine($speakers, $talks); foreach($meetupTalks as $speaker => $talk){ echo "$speaker $talk"; }
  • 43. SEMANTIC WEAPONS $ looping over two collections _ for speaker, talk in zip(speakers, talks): print(speaker, talk) foreach(array_combine($speakers, $talks) as $speaker => $talk) echo "$speaker $talk";
  • 44. SEMANTIC WEAPONS $ python iterators magic, tweet .@cvences # dado un array asociativo, elimina todos los nombres que empiecen con la letra “c”
 meetup_info = {
 'Javier': 'Ansible',
 'Joe': 'Loopsless',
 'Rasmus': 'Deploy',
 'Carlos': 'Python',
 }
 
 meetup_info = {key: meetup_info[key] for key in meetup_info if not key.lower().startswith('c')} # dado un modelo con relationships, filtra los blogs cuyos autores tengan o no # un nombre asignado. El título no incluye la palabra python y ordénalos por fecha # de creación descendente. 
 Blog.objects .filter(entry__authors__isnull=False, entry__authors__name__isnull=True) .exclude(entry__title__icontains=‘python’) .order_by(‘-created’)
  • 45. SEMANTIC WEAPONS $ python iterators magic def fib(n):
 return (4 << n * (3 + n)) // ((4 << 2 * n) - (2 << n) - 1) & ((2 << n) - 1) def get_fibonacci_by_position(pos):
 """
 Returns the fibonacci number at pos
 
 """
 a, b = 1, 1
 
 for _ in range(pos):
 a, b = a + b, a
 
 return b
  • 46.