Slide 1

Slide 1 text

Refactor your code Refactor yourself

Slide 2

Slide 2 text

Please say „Hi“ PICS OR IT DIDN‘T HAPPEN

Slide 3

Slide 3 text

Your entertainer while you digest  Peter Dietrich ([email protected], @xosofox)  Freelancer  PHP since Version 3, Symfony since 1.0  Skipped 2.0 release while being in nodejs land  For 12 years VBA by day, Web by night  Since 2016 Full time/stack Freelancer  Since 2022 in training to become a therapist (Gestalttherapie)  Why am I here?

Slide 4

Slide 4 text

Get yourself into a positive mindset  There is no bad code  Nobody writes bad code on purpose!  Don‘t blame, don‘t excuse

Slide 5

Slide 5 text

Lack of  Knowledge/experience  Time  Support  Long-term perspective of project  Motivation / Interest $ git config --global alias.ack blame

Slide 6

Slide 6 text

If you think "This is bad code"...  Celebrate  if it was yours – even more so!  Acknowledge  Become aware of better solution  Discuss (guidelines?)  Improve Refactoring should be a daily practice

Slide 7

Slide 7 text

Main Take-Away  Nobody writes bad code on purpose  Celebrate that you learned a better way to do it WTF?

Slide 8

Slide 8 text

Apply this to the world  Nobody does bad things on purpose  People do things because it is the only way the know  … being hurt, scared, insecure, attacked, disregarded  If you knew a better way to behave, you would do it  Changing your „inner programming“ is hard work as it is deeply written into your firmware

Slide 9

Slide 9 text

checkState(); $need = $state->getNeed(); $feedback = $self->express($need); $experience = $self->validate($need, $feedback); $self->addExperience($experience); }

Slide 10

Slide 10 text

„Bad“ experiences lead to adaptation • Negative feedback leads to „bad feelings“ • We dont‘ want to feel bad • → If you experience a „bad feeling“, your body/mind tries to protect you in the future $state = $self->checkState(); $need = $state->getNeed(); $feedback = $self->express($need); $experience = $self->validate($need, $feedback); • Stop checking state • Stop feeling your needs • Stop expressing your needs • Stop validation

Slide 11

Slide 11 text

Coping mechanisms • Stop checking state → Do not listen to your body, stop feeling (anger, ..) • Stop feeling your needs → Go on, drain your battery, exhaust yourself • Stop expressing your needs → „I‘m not worth it“ / „I am too much“ • Stop objective validation → „It‘s my fault“ / „I must not do this“ These mechanisms are being incorporated into your code base

Slide 12

Slide 12 text

How does this change my code base?  Coping mechanisms intercept your main code  Unconcious  High-Priority EventListeners that kick in before/during the „main“ process (concious decissions)  High performance, impressive response time (react before you think)  Hard to debug

Slide 13

Slide 13 text

class DoItForMumRequestSubscriber implements EventSubscriberInterface { public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); $requestor = $request->getRequestor(); if ($requestor->isFemale()) { // skip validation, mum would not like it and be sad, see logs1978.tar.gz to logs1983.tar.gz $response = new YesSureIllDoItResponse('Sure'); $event->setResponse($response); } } public static function getSubscribedEvents(): array {…} }

Slide 14

Slide 14 text

class DontHurtThemSubscriber implements EventSubscriberInterface { public function onKernelException(ExceptionEvent $event): void { $exception = $event->getThrowable(); if ($exception instanceof NoIDontWantThisException) { $request = $event->getRequest(); $requestor = $request->getRequestor(); if ($requestor->mightNotLike($exception)) { // stop handling exception, do not hurt their feelings, they will stop loving you continue_execution_after_validation(); // magic method I invented myself } } } public static function getSubscribedEvents(): array {…} }

Slide 15

Slide 15 text

class WhyBotherSubscriber implements EventSubscriberInterface { public function __construct(private EventDispatcher $dispatcher) {} public function onExpressNeedEvent(ExpressNeedEvent $event): void { $need = $event->getNeed(); if ($need->isThirsty()) { // dont bother asking for a glass of water, you're not worth anyone's trouble $this->dispatcher->dispatch(new GetUpEvent()); // get it yourself $this->dispatcher->dispatch(new GetWaterEvent()); } }

Slide 16

Slide 16 text

How can we change this?  Xdebug  Set a breakpoint – become aware when your EventListeners kick in  Acknowledge, don‘t blame (yourself, parents, partner, colleagues, …)  Become aware of better solution  Discuss – get in contact and show yourself  Improve says:

Slide 17

Slide 17 text

Awareness can heal

Slide 18

Slide 18 text

„Bad“ EventListener Construction Kit Triggers „Exceptions“ (Warning signs) Requests Needs Conditions Who is your contact (spouse, parents, manager, people in need) Validation Is this really good for me? Am I worth it? Is this a valid need? Response / Action Say „yes“ even if you should not

Slide 19

Slide 19 text

„Bad“ EventListener Construction Kit Triggers „Exceptions“ (Warning signs) Requests Needs … Conditions Who is your contact (spouse, parents, manager, people in need) … Validation Is this really good for me? Am I worth it? Is this a valid need? … Response / Action Say „yes“ even if you should not … • Find a class name for the listener • Define event / event class • Draft code Where does it come from? Purpose? Fix?

Slide 20

Slide 20 text

Sounds silly?  It works  I makes „talking about it“ easier  Biggest learning: We are all in the same boat #catcontent #wtfpowerpoint

Slide 21

Slide 21 text

„If you don‘t understand it, it might be unnecessary nonsense“ „Wenn Du‘s nicht verstehst, isses vielleicht einfach Quatsch“

Slide 22

Slide 22 text

Find out your old codes purpose Figure out what that code did – and what ist intentions were (what it protected you from) Become aware that you, as a grown up, might not need that protection anymore

Slide 23

Slide 23 text

Why bother at all? UNCONCIOUS REACTIONS STRESS MUSCULAR TENSION YOU CANNOT BE YOUR „AUTHENTIC SELF“

Slide 24

Slide 24 text

Only you can change it  It has been written by you to adjust to your environment  It is your code base – and you are the lead dev  You CAN change it

Slide 25

Slide 25 text

Might not work on your own Awareness can heal Show yourself Check Mental Health offers at your job You might not need „therapy“ – a therapist can help though

Slide 26

Slide 26 text

…to leave you with a Positive Mindset Everyone is running the best code they have Once you spend time on learning new things and refactor your code, performance and maintainability will get better

Slide 27

Slide 27 text

Feedback please, please, pretty please  [email protected]  @xosofox  Talk to me I did quite a lot of work on myself, I can take your feedback :-D