PHPDay 11-05-2018
The way we teach tech Jeroen van der Gulik
About me
❖ Software Architect/ Consultant
❖ Co-Founder Isset
(https://isset.nl)
❖ Señor Developer
❖ Organizer DDDNL
❖ Builder of Artificial Stupidity
❖ @n0x13
shōnen
少年漫画
boy
少年漫画
cartoon or comic
少年漫画
boys' comic
少年漫画
<html>
<head>
<title>My first project</title>
</head>
<body>
<?php echo '<p>Hello World<p>'; ?>
</body>
</html>
Parse error: syntax error, unexpected
'echo' (T_ECHO), expecting ',' or ‘;'
in hello_world.php on line 6
Medior
Senior
Stages of Problem Solving
❖ I just want to solve my problem
❖ I want to understand my problem
❖ I want to be pointed into the right direction and given
options
Context depends on
❖ Knowledge
❖ Experience
❖ Time
❖ Pressure
❖ Interest
No Knowledge
Some
Knowledge
Knowledgable
Just solve my problem √
Understand my problem √
I want options √
final class Example
{
public function doSomething()
{
$this->doAThingThatSometimesFails();
}
}
– John Doe (Jr. Developer)
“I want to log errors”
– Sansa Stark (Sr. Developer)
“Great ! Have you thought about ELK,
Syslog, Splunk or Kafka ?”
final class Example
{
public function doSomething()
{
try {
$this->doAThingThatSometimesFails();
} catch (Throwable $throwable) {
file_put_contents(
realpath('var/log/my.log'),
$throwable->getMessage() . PHP_EOL,
FILE_APPEND
);
}
}
}
final class Example
{
public function doSomething()
{
try {
$this->doAThingThatSometimesFails();
} catch (Throwable $throwable) {
file_put_contents(
realpath('var/log/my.log'),
$throwable->getMessage() . PHP_EOL,
FILE_APPEND
);
}
}
}
final class Example
{
public function doSomething()
{
try {
$this->doAThingThatSometimesFails();
} catch (Throwable $throwable) {
file_put_contents(
realpath('var/log/my.log'),
$throwable->getMessage() . PHP_EOL,
FILE_APPEND
);
}
}
}
final class Example
{
public function doSomething()
{
try {
$this->doAThingThatSometimesFails();
} catch (Throwable $throwable) {
file_put_contents(
realpath('var/log/my.log'),
$throwable->getMessage() . PHP_EOL,
FILE_APPEND
);
}
}
}
– Alice Wonderland (Code Reviewer)
“What if we want to
change the location?”
Code Review
– Alice Wonderland (Code Reviewer)
“Ok much better !
But global variables are
tricky…”
– Alice Wonderland (Code Reviewer)
“What if we want to log to
something else than file?”
interface Logger
{
public function log($message);
}
final class FileLogger implements Logger
{
private $pathToLogFile;
public function __construct(string $pathToLogFile)
{
$this->pathToLogFile = $pathToLogFile;
}
public function log($message)
{
file_put_contents(
realpath($this->pathToLogFile),
$message,
FILE_APPEND
);
}
}
final class Example
{
private $logger;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
public function doSomething()
{
try {
$this->doAThingThatSometimesFails();
} catch (Throwable $throwable) {
$this->logger->log($throwable->getMessage());
}
}
}
– Alice Wonderland (Code Reviewer)
“Did you know there was a
standard for this?”
– Alice Wonderland (Code Reviewer)
“Do you know about
decorators?”
interface DoSomething
{
public function doSomething();
}
final class LoggableExample implements DoSomething
{
private $example;
private $logger;
public function __construct(Example $example, LoggerInterface $logger)
{
$this->example = $example;
$this->logger = $logger;
}
public function doSomething()
{
try {
$this->example->doSomething();
} catch (Throwable $throwable) {
$this->logger->error($throwable->getMessage());
}
}
}
final class Example implements DoSomething
{
public function doSomething()
{
$this->doAThingThatSometimesFails();
}
}
We explained
❖ Why global variable (state) is bad
❖ Why Dependancy Injection is good
❖ Why Interfaces are good
❖ Why Single Responsibility is good
❖ Why Decorator is useful (sometimes)
Learning or Teaching opportunities
dev-books.com
Pair Programming
Meetups
The Pac-Man Rule
EventStorming
Conferences
Small Controlled Experiments
Absolutes
– Robert Martin a.k.a. Uncle Bob
“The number of programmers doubles
every 5 years. That means, at any time,
half the world's programmers have less
than 5 yrs experience”
The way we should teach tech
❖ People learn best 1 step at the time
❖ Find opportunities to learn or teach
❖ Find mentors/mentees
❖ Create your own Seniors
❖ Never stop learning
Feedback
❖ https://joind.in/talk/d51ab

2018 05-11 the way we teach tech - phpday