<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jose M Valera Reales</title>
    <description>The latest articles on Forem by Jose M Valera Reales (@chemaclass).</description>
    <link>https://forem.com/chemaclass</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F422281%2F3e463e45-2e3c-4185-a680-131a488fb76b.jpg</url>
      <title>Forem: Jose M Valera Reales</title>
      <link>https://forem.com/chemaclass</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chemaclass"/>
    <language>en</language>
    <item>
      <title>Update your team to be more extreme</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Sun, 27 Feb 2022 08:00:43 +0000</pubDate>
      <link>https://forem.com/chemaclass/update-your-team-to-be-more-extreme-539k</link>
      <guid>https://forem.com/chemaclass/update-your-team-to-be-more-extreme-539k</guid>
      <description>&lt;p&gt;Our profession is constantly evolving; therefore, it demands a non-stop learning process. Embracing the change is not optional in our software industry.&lt;/p&gt;

&lt;p&gt;We need to create spaces to get out of our comfort zone, so our cognitive brain can train and improve how to adapt to our surroundings, which are constantly transforming.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Continue reading at:&lt;br&gt;
&lt;a href="https://chemaclass.es/blog/update-your-team-to-be-more-extreme/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/update-your-team-to-be-more-extreme/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>extreme</category>
      <category>programming</category>
      <category>team</category>
      <category>work</category>
    </item>
    <item>
      <title>Open-Source Software</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Mon, 03 May 2021 08:18:41 +0000</pubDate>
      <link>https://forem.com/chemaclass/open-source-software-13f8</link>
      <guid>https://forem.com/chemaclass/open-source-software-13f8</guid>
      <description>&lt;h1&gt;
  
  
  The power of contributing to OSS 🖥
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is Open-Source Software (OSS)? 🤔
&lt;/h2&gt;

&lt;p&gt;OSS shares similarities with free software but it’s not the same. Free software is a form of OSS, but that doesn’t necessarily mean that it has to be free. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE" rel="noopener noreferrer"&gt;PHPUnit&lt;/a&gt; is an example of OSS which is free.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/spryker/spryker-core/blob/master/LICENSE" rel="noopener noreferrer"&gt;Spryker&lt;/a&gt; is an example of OSS which is not free.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;OSS is basically software that is public, open to the world.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Benefits — for a company 🛕
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Adoption: the easier the access, the easier the adoption.&lt;/li&gt;
&lt;li&gt;Training and tutorials help the system to grow.&lt;/li&gt;
&lt;li&gt;Tech: often on the cutting edge of technology.
Tech moves fast. They will get obsolete if they don’t.&lt;/li&gt;
&lt;li&gt;Community: the people around want to improve as it grows.
Public channels enable easy access and community building.&lt;/li&gt;
&lt;li&gt;Trust: the software is public and accessible.
Everyone can check the quality of the software anytime.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits — for you, as a single contributor 🤓
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Flexibility: decide on what you want to work on.&lt;/li&gt;
&lt;li&gt;Self-confidence: the experience improves your skills.&lt;/li&gt;
&lt;li&gt;Training: without the pressure of a PROD environment.&lt;/li&gt;
&lt;li&gt;Tech: play with the latest features of your tech.
Try upcoming versions of your coding lang, or even try new ones!&lt;/li&gt;
&lt;li&gt;Soft skills: improve your communication skills.
Good communication in the project is important.
Especially when you face disagreements.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;TL;DR: It can be a “constant kata” if you want to.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Github to the rescue 😃
&lt;/h2&gt;

&lt;p&gt;Nowadays, it’s really trivial to start contributing to OSS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can start your own project. A pet project fits here perfectly!&lt;/li&gt;
&lt;li&gt;You can contribute to an existing OSS project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pet projects 🐘
&lt;/h2&gt;

&lt;p&gt;A pet project is a playground to create software and train your professional skills. Creating pet projects in your public Github profile has all the benefits of contributing to OSS, plus you’re your own boss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You dictate the roadmap.&lt;/li&gt;
&lt;li&gt;You decide what to do and how.&lt;/li&gt;
&lt;li&gt;You’re your own boss.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The project is there for you.&lt;br&gt;
You are responsible to play, explore and pass your limits.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Some Chema’s Pet Projects 🦣
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Active
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/Chemaclass/php-best-practices" rel="noopener noreferrer"&gt;php-best-practices&lt;/a&gt;: what I consider best practices for web-dev.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Chemaclass/php-scaffolding" rel="noopener noreferrer"&gt;php-scaffolding&lt;/a&gt;: a basic PHP scaffolding with Docker.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Chemaclass/typed-arrays" rel="noopener noreferrer"&gt;typed-arrays&lt;/a&gt;: generics replacement for PHP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Inactive
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;stock-ticker: get a notification with the news from your favorites Tickers.&lt;/li&gt;
&lt;li&gt;jira-status-notifier: Notify when the JIRA tickets don’t move along.&lt;/li&gt;
&lt;li&gt;edifact-parser: a parser for a UN/EDIFACT file format in PHP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Abandoned
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;knob-mvc: a framework to create WordPress templates (2015/2017).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Some of Chema’s OSS org contributions 🌚
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Active
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/phel-lang/phel-lang" rel="noopener noreferrer"&gt;phel-lang&lt;/a&gt;: Phel is a functional programming language that compiles to PHP. It is a dialect of Lisp inspired by Clojure and Janet.
I already wrote a post about phel-lang: &lt;a href="https://chemaclass.medium.com/phel-the-lisp-that-compiles-to-php-544980605ebe" rel="noopener noreferrer"&gt;Phel: A Lisp that compiles to PHP&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/gacela-project/gacela" rel="noopener noreferrer"&gt;gacela-project&lt;/a&gt;: Gacela is a PHP framework that helps you to improve the design of your application by splitting the logic into different modules.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Abandoned
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;nm_template: The base template for NuevaMetal (2013–2016).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Knowledge sharing ✍🏼
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://chemaclass.medium.com/pull-requests-vs-pair-programming-77be022c10c3" rel="noopener noreferrer"&gt;Pull Requests vs Pair Programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://chemaclass.medium.com/the-process-itself-is-the-goal-a7dd17b80bae" rel="noopener noreferrer"&gt;The process itself is the goal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/swlh/the-art-of-refactoring-cb079353d8df" rel="noopener noreferrer"&gt;The art of refactoring; When, How, and Why&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/swlh/the-art-of-testing-39c6af8c9076" rel="noopener noreferrer"&gt;The art of testing: Where design meets quality&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;... and many more on &lt;a href="https://medium.com/@Chemaclass" rel="noopener noreferrer"&gt;https://medium.com/@Chemaclass&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The beauty of this 🧑‍🎓
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Seeing the corrections that you constantly keep doing&lt;/li&gt;
&lt;li&gt;Seeing how your own code gets old with time&lt;/li&gt;
&lt;li&gt;Seeing the many mistakes that you have done&lt;/li&gt;
&lt;li&gt;Seeing how you are getting better at coding over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Developing a sixth sense to smell patterns which you have already done and their positive &amp;amp; negative experiences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Showing your skills and helping the community around you.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Open-Source Software offers you one of the best opportunities to start building your career path towards continuous improvement.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhujicoui8y426z7qxmyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhujicoui8y426z7qxmyu.png" alt="Alt Text" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jesusvalerareales.medium.com/getting-started-with-open-source-software-e6c177b68b39" rel="noopener noreferrer"&gt;Getting started with Open Source Software&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Originally written in &lt;a href="https://chemaclass.es/blog/the-process-itself-is-the-goal/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/the-process-itself-is-the-goal/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>github</category>
      <category>programming</category>
      <category>development</category>
    </item>
    <item>
      <title>Pull Requests vs Pair Programming</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Mon, 05 Apr 2021 14:50:25 +0000</pubDate>
      <link>https://forem.com/chemaclass/pull-requests-vs-pair-programming-32b9</link>
      <guid>https://forem.com/chemaclass/pull-requests-vs-pair-programming-32b9</guid>
      <description>&lt;p&gt;Why choosing when you can have both?&lt;/p&gt;

&lt;h1&gt;
  
  
  Pull Requests
&lt;/h1&gt;

&lt;p&gt;A Pull Request (PR) is basically a way of showing your suggested code changes such that they are easily comparable with the existing source code. This is part of a workflow that helps developers to share knowledge about the changes that are being done within the system.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Pull Request is the moment where you ask your peers to review and check out your code changes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Usually, it’s also used:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For discussions about code style.&lt;/li&gt;
&lt;li&gt;To spot potential bugs.&lt;/li&gt;
&lt;li&gt;For architectural or design discussions once the solution is done.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Pull Requests aren’t the best tool for everything
&lt;/h2&gt;

&lt;p&gt;The main problem with these topics above is that PR’s are usually ready when the feature/bug is already being worked on and in the last stage of its development process. It’s an “already change proposal to be merged into the current system”, don’t forget that.&lt;/p&gt;

&lt;p&gt;The concept of “Draft PR” exists to make explicit that a PR is not ready to be merged, so it’s still a “work in progress thing”, but that’s another topic.&lt;/p&gt;

&lt;p&gt;Pull Requests are, indeed, one of the best tools that we have in our industry to share knowledge about the changes that we are doing in the system, but sometimes they might be misused, as for example:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Discussions about code style&lt;/strong&gt;. Code style shouldn’t be discussed in a PR. There should be already a CI running a code style checker, that’s all. If you want to talk about code style, request a change in your code style checker, but not in a random PR.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spot bugs&lt;/strong&gt;. Bugs and desired behavior should be covered by automated tests. The developer is the first responsible person for this topic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Architectural or design discussions&lt;/strong&gt;. Once a particular solution is developed and ready for review, it is usually really hard to “rollback” that idea and rewrite it again. Because “why would you do that? For some subjective opinion? It’s done already. And it seems to work just fine.”&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Having an extra person looking at the changes that we have done for “designing decisions” might be beneficial, but we could have addressed “potential disagreements” in a sooner stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should the purpose of a Pull Request be?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Sharing knowledge about the proposed changes with the team.&lt;/li&gt;
&lt;li&gt;Ensuring the team aligns and agrees across the multiples changes that are getting submitted every day in order to keep a healthy direction for the project. Yes, this might include double-checking the outcome design, but… What if that is now too late? How could we solve all those issues?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkt9o0g47lekmklqtvd2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkt9o0g47lekmklqtvd2.png" alt="Alt Text" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Pair Programming
&lt;/h1&gt;

&lt;p&gt;The concept of “Pair Programming” can be understood from different points of view. Pair thinking and pair programming, driver-navigator roles concepts, or pure live coding from one side. Actually, this is way easier than it looks like at first instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Either you watch and help the other person to write code,&lt;/li&gt;
&lt;li&gt;Or you type while getting another pair of eyes watching and helping you.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Pair Programming helps the team to work together.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Pair programming is the joy of working with an extra brain and another pair of eyes, where the key is to &lt;strong&gt;build a context&lt;/strong&gt; where you two &lt;strong&gt;share the same goal&lt;/strong&gt; in order to find the &lt;strong&gt;best possible solution&lt;/strong&gt;. All of this while learning from each other every single second.&lt;br&gt;
Pair Programming is not about developing the best solution at the very beginning. It’s about making it work, sharing ideas, and finding a better solution together. After that, you can refactor and clean the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pair Programming is a continuous code review
&lt;/h2&gt;

&lt;p&gt;Pull Requests are an asynchronous way to share code changes, while Pair Programming is totally &lt;strong&gt;synchronous&lt;/strong&gt; because it happens at the same time.&lt;/p&gt;

&lt;p&gt;That said, Pull Requests and Pair Programming aren’t mutually exclusive, they can coexist. They are tools, and we should wisely choose them in order to achieve our objectives.&lt;/p&gt;

&lt;p&gt;The most common fear that I saw while encouraging to do Pair Programming is that some people are shy and they don’t like to have other eyes around them while they are coding because of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fear that they don’t know what to code or where to start.&lt;/li&gt;
&lt;li&gt;Fear that others will laugh at their solutions.&lt;/li&gt;
&lt;li&gt;Fear to don’t succeed in public.&lt;/li&gt;
&lt;li&gt;Fear to not be able to develop the expected solution for multiple reasons: misunderstanding the task or lack of knowledge.&lt;/li&gt;
&lt;li&gt;Fear to change your mind in front of others.&lt;/li&gt;
&lt;li&gt;Fear to discuss and make decisions loud.&lt;/li&gt;
&lt;li&gt;Fear of disagreeing with others.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn90d2i7f9wyz3s1b653r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn90d2i7f9wyz3s1b653r.png" alt="Alt Text" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  After several years of experience on this topic
&lt;/h2&gt;

&lt;p&gt;The pattern which rejects Pair Programing is basically “fear”, and being out of your comfort zone. And this is due to the misunderstanding of the roots of the actual Pair Programming concept.&lt;/p&gt;

&lt;p&gt;Pair Programming is not “to show off in front of your colleagues” or “to be screwed by your peers”, but to be transparent (showing your skills as they really are) and improve as a team lifting up each other.&lt;/p&gt;

&lt;p&gt;Programming is an iterative process that needs a continuous refactoring of our way of thinking in order to achieve better solutions, day by day. Therefore, programming with another person next to you (with a different way of thinking) will help the team to get the best from each other while discarding the waste or bad habits if necessary.&lt;/p&gt;

&lt;p&gt;Pair Programming doesn’t need to be always set for everything. As a tool, it’s flexible, and we can choose how, when and for what reason.&lt;/p&gt;

&lt;p&gt;A personal rule of thumb, before starting tasks that might involve touching multiple modules or complex business rules, think about a quick Pair Thinking/Programming with another more experienced colleague in that field.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Everything depends on a particular context and people: the developers, the pairs, the tasks, the mood.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Still uncomfortable with Pair Programming?
&lt;/h2&gt;

&lt;p&gt;If you still feel uncomfortable having another person next to you while you write code, it might be because you aren’t particularly happy with your own code, or the process that you follow in order to achieve some result. My favorite way to work on this is by exercising on your own and working on improving your skills as a software developer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create and play around with your own pet projects.&lt;/li&gt;
&lt;li&gt;Work on code katas on your own and with others.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Practice makes the master.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Don’t get me wrong, Pull Requests are great. Keep doing them.&lt;/li&gt;
&lt;li&gt;Team collaboration is essential. Pair Programming aims for this.&lt;/li&gt;
&lt;li&gt;Pair Programming encourages the team to proactively work together.&lt;/li&gt;
&lt;li&gt;Don’t be afraid of coding while having eyes around you. Ask questions when something is unclear. Ask for help when you don’t know how to solve something.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;It’s totally ok not knowing everything. The most important thing is to know how to work together.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7343xq0htcu4tcy4z1e.png" alt="Alt Text" width="800" height="439"&gt;
&lt;/h2&gt;

&lt;p&gt;Originally written in &lt;a href="https://chemaclass.es/blog/pull-request-vs-pair-prog/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/pull-request-vs-pair-prog/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>pullrequest</category>
      <category>pairprogramming</category>
      <category>teamwork</category>
      <category>programming</category>
    </item>
    <item>
      <title>Embrace the change</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Mon, 01 Mar 2021 08:15:43 +0000</pubDate>
      <link>https://forem.com/chemaclass/embrace-the-change-27f9</link>
      <guid>https://forem.com/chemaclass/embrace-the-change-27f9</guid>
      <description>&lt;h2&gt;
  
  
  Who moved my cheese?🧀
&lt;/h2&gt;

&lt;p&gt;Published in 1998 and I just read it at the beginning of 2021. Better late than never. Actually, thanks to my brother Jesús, who recommended it to me.&lt;/p&gt;

&lt;p&gt;The book &lt;em&gt;Who moved my cheese?&lt;/em&gt; presents a tale inside the main story that consists of four characters: two mice, &lt;strong&gt;Sniff&lt;/strong&gt; and &lt;strong&gt;Scurry&lt;/strong&gt;, and two little persons, &lt;strong&gt;Hem&lt;/strong&gt; and &lt;strong&gt;Haw&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They live in a Maze (that represents one’s environment) and in order to survive they need to go out of their comfort zone and look for cheese (which represents happiness and success).&lt;/p&gt;

&lt;p&gt;The tale starts when both groups end up at “Cheese Station C”, full of cheese. The humans established routines while the mouses kept their instincts active.&lt;/p&gt;

&lt;p&gt;One day the mouses arrive at the “Cheese Station C” and find no cheese left. So they go out to find more cheese somewhere else. On the contrary, when Hem and Haw see that there is no cheese left, they start complaining. Hem, angry and annoyed, demands “Who moved my cheese?!”. Both humans counted on the cheese supply would be endless constant, so they weren’t prepared for that unexpected. The main difference here is how Haw and Hem react to this situation.&lt;/p&gt;

&lt;p&gt;Hem denies moving away from the “Cheese Station C”, so he keeps going there every day expecting to find cheese without success, being weaker, and with continuous fear of doing something different. Haw, on the other hand, decides to laugh at the situation, turns down his fear, and goes out looking for more cheese.&lt;/p&gt;

&lt;p&gt;... I will leave the rest of the tale to you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzcaupdcr2alspok4aan9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzcaupdcr2alspok4aan9.png" alt="Alt Text" width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tale is a beautiful metaphor of the different attitudes that people adopt as part of their identity in life when they have to confront any change.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Noticing small changes early helps you adapt to the bigger changes that are to come.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This book is full of lessons that apply to everyone no matter who they are or when they read it. I fully recommend it.&lt;/p&gt;

&lt;h3&gt;
  
  
  My favorite lessons of the book
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Change happens. 
They keep moving the cheese.&lt;/li&gt;
&lt;li&gt;Anticipate change. 
Get ready for the cheese to move.&lt;/li&gt;
&lt;li&gt;Monitor change. 
Smell the cheese often so you know when it's getting old.&lt;/li&gt;
&lt;li&gt;Adapt to change quickly. 
The quicker you let go of old cheese, the sooner you can enjoy new cheese.&lt;/li&gt;
&lt;li&gt;Change. 
Move with the cheese.&lt;/li&gt;
&lt;li&gt;Enjoy change. 
Enjoy the taste of new cheese&lt;/li&gt;
&lt;li&gt;Be ready to change quickly and enjoy it again. 
They keep moving the cheese.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;"Everyone knows that not all change is good or even necessary. But in a world that is constantly changing, it is to our advantage to learn how to adapt and enjoy something better. It is not what is in the story of "Who moved my cheese?" but how you interpret it and apply it to your own situation that gives it the value." - Ken Blanchard.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/OvYCLxqkfvY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Find the book in &lt;a href="https://www.amazon.de/-/en/Dr-Spencer-Johnson/dp/0091816971/" rel="noopener noreferrer"&gt;Amazon.de&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Life moves on and so should we” — Spencer Johnson&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqda2zd8g2wowi3sdewyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqda2zd8g2wowi3sdewyz.png" alt="Alt Text" width="800" height="1128"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Originally written in &lt;a href="https://chemaclass.es/blog/embrace-the-change/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/embrace-the-change/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>books</category>
      <category>change</category>
      <category>management</category>
      <category>leadership</category>
    </item>
    <item>
      <title>Phel: the Lisp that compiles to PHP 🐘</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Mon, 01 Feb 2021 09:51:56 +0000</pubDate>
      <link>https://forem.com/chemaclass/phel-the-lisp-that-compiles-to-php-963</link>
      <guid>https://forem.com/chemaclass/phel-the-lisp-that-compiles-to-php-963</guid>
      <description>&lt;h5&gt;
  
  
  The new functional language. Fully interoperable with PHP 🚀
&lt;/h5&gt;

&lt;h1&gt;
  
  
  The Phel Language
&lt;/h1&gt;

&lt;p&gt;Phel is a Functional Programming (&lt;a href="https://en.wikipedia.org/wiki/Functional_programming" rel="noopener noreferrer"&gt;FP&lt;/a&gt;) language that compiles to PHP. It is a dialect of &lt;a href="https://en.wikipedia.org/wiki/Lisp_(programming_language)" rel="noopener noreferrer"&gt;Lisp&lt;/a&gt; inspired by Clojure and Janet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Built on PHP’s ecosystem&lt;/li&gt;
&lt;li&gt;Good error reporting&lt;/li&gt;
&lt;li&gt;Different Datastructures (Arrays, Tables, and Tuples)&lt;/li&gt;
&lt;li&gt;Macros&lt;/li&gt;
&lt;li&gt;Recursive functions&lt;/li&gt;
&lt;li&gt;Powerful but simple Syntax&lt;/li&gt;
&lt;li&gt;REPL&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Phel?
&lt;/h2&gt;

&lt;p&gt;Phel is a creation of Jens Haase, and as he mentions on the website, “it is the result of many &lt;a href="https://phel-lang.org/blog/functional-programming-in-php" rel="noopener noreferrer"&gt;failed attempts to do functional programming in PHP&lt;/a&gt;”. He was looking for something with these characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A LISP-inspired&lt;/li&gt;
&lt;li&gt;Functional Programming language&lt;/li&gt;
&lt;li&gt;That runs on cheap hosting providers&lt;/li&gt;
&lt;li&gt;And is easy to write and debug&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From my point, it was ending May 2020 when I finished the book “&lt;a href="https://www.amazon.de/-/en/Bruce-Tate/dp/193435659X/" rel="noopener noreferrer"&gt;Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages&lt;/a&gt;”, in which I learned a bit of Prolog, Erlang, Clojure, Haskell… I even created a &lt;a href="https://github.com/Chemaclass/7LangIn7Weeks" rel="noopener noreferrer"&gt;repository in Github&lt;/a&gt; to store my progress over the weeks with these learnings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7z7nz3etqe95q18s9hpa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7z7nz3etqe95q18s9hpa.png" alt="Alt Text" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suddenly, one day beginning of June 2020, I saw a post in Reddit's PHP official channel, with a message of someone mentioning this “&lt;strong&gt;Phel&lt;/strong&gt;” project, claiming to be a “&lt;strong&gt;functional programming language written in PHP&lt;/strong&gt;”! (or something like that).&lt;/p&gt;

&lt;p&gt;I work with PHP for around 8 years so far, and I always try to combine OOP with FP as much as possible (because I believe both paradigms are better combined; they are not necessarily exclusive), and a new dialect of Lisp fully written in native &lt;strong&gt;PHP 7.4&lt;/strong&gt; sounded really exciting. I decided to take a look at it. I wanted to see the code.&lt;/p&gt;

&lt;p&gt;The fresh readings from &lt;a href="https://twitter.com/matthiasnoback" rel="noopener noreferrer"&gt;Mathias NoBack&lt;/a&gt; books such as &lt;a href="https://www.manning.com/books/object-design-style-guide" rel="noopener noreferrer"&gt;Object Design Style Guide&lt;/a&gt;, &lt;a href="https://www.apress.com/us/book/9781484241189" rel="noopener noreferrer"&gt;Principles of Package Design&lt;/a&gt;, and &lt;a href="https://leanpub.com/web-application-architecture/" rel="noopener noreferrer"&gt;Advanced Web Application Architecture&lt;/a&gt;, gave me the courage to try out what I learned and put it for real in a project. This was (and still is) a beautiful challenge, which helps me to test myself and grow professionally at the same time.&lt;/p&gt;

&lt;p&gt;My first commit was done on 6 June 2020, and since then I work on this project a bit (almost) every day in my free time. It helps me to learn more about FP, languages internal design, and best practices on testing and software design architecture in general.&lt;/p&gt;

&lt;p&gt;I started applying minor changes until I ended refactoring the whole compiler structure (among other things) in order to make the modules easier to read and understand. Psalm, strict types, good test coverage, unifying code style… These were some of my favorite topics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft716l54e2zi9tue7dk1h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft716l54e2zi9tue7dk1h.png" alt="Alt Text" width="800" height="631"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of Phel code
&lt;/h2&gt;

&lt;p&gt;The following example gives a short impression of how Phel looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nv"&gt;Define&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;namespace&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;my\example&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nv"&gt;Define&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;variable&lt;/span&gt; &lt;span class="nv"&gt;with&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="s"&gt;"my-name"&lt;/span&gt; &lt;span class="nb"&gt;and&lt;/span&gt; &lt;span class="nv"&gt;value&lt;/span&gt; &lt;span class="s"&gt;"world"&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;my-name&lt;/span&gt; &lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nv"&gt;Define&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;func&lt;/span&gt; &lt;span class="nv"&gt;with&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="s"&gt;"print-name"&lt;/span&gt; &lt;span class="nb"&gt;and&lt;/span&gt; &lt;span class="nv"&gt;one&lt;/span&gt; &lt;span class="nv"&gt;argument&lt;/span&gt; &lt;span class="s"&gt;"your-name"&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;print-name&lt;/span&gt; &lt;span class="nv"&gt;[your-name]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s"&gt;"hello"&lt;/span&gt; &lt;span class="nv"&gt;your-name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nv"&gt;Call&lt;/span&gt; &lt;span class="k"&gt;the&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;print-name&lt;/span&gt; &lt;span class="nv"&gt;my-name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Current status of Phel
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We have an open &lt;a href="https://gitter.im/phel-lang/community" rel="noopener noreferrer"&gt;Gitter Community&lt;/a&gt; where we help each other&lt;/li&gt;
&lt;li&gt;We prepared an easy &lt;a href="https://phel-lang.org/documentation/getting-started/" rel="noopener noreferrer"&gt;Getting Started Guide&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;We prepared an easy Github Repository with a &lt;a href="https://github.com/phel-lang/phel-scaffolding" rel="noopener noreferrer"&gt;Phel Scaffolding Template&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;We just released the first official version: &lt;a href="https://github.com/phel-lang/phel-lang/tags" rel="noopener noreferrer"&gt;0.1.0&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check out the official website with all documentation of the Phel Language:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://phel-lang.org/" rel="noopener noreferrer"&gt;https://phel-lang.org/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fov6fkxgw6jvssjmkoezs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fov6fkxgw6jvssjmkoezs.png" alt="Alt Text" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Also recommended
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jesusvalerareales.medium.com/functional-programming-with-phel-5f32145eddb7" rel="noopener noreferrer"&gt;Functional Programming with Phel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally written in &lt;a href="https://chemaclass.es/blog/phel-first-release/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/phel-first-release/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>functional</category>
      <category>programming</category>
      <category>lisp</category>
      <category>php</category>
    </item>
    <item>
      <title>To mock or not to mock</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Mon, 11 Jan 2021 09:13:41 +0000</pubDate>
      <link>https://forem.com/chemaclass/to-mock-or-not-to-mock-438h</link>
      <guid>https://forem.com/chemaclass/to-mock-or-not-to-mock-438h</guid>
      <description>&lt;h4&gt;
  
  
  How to escape the mocking hell
&lt;/h4&gt;

&lt;p&gt;What is actually happening when we create a mock? Which types of mocks are there? Is mocking good or bad? Well, as always, everything depends on the context. And here we will consider some of the main situations about when to mock and when not to mock, but especially why.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens when you mock something?
&lt;/h2&gt;

&lt;p&gt;First of all, we should define what a mock is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In a unit test, mock objects can simulate the behavior of complex, real objects and are therefore useful when it is impractical or impossible to incorporate a real object into a unit test.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Mocking makes sense in a &lt;em&gt;unit testing&lt;/em&gt; context. An integration test should go through the real implementation checking the integration between multiple units, which are even allowed to talk to the DB or File IO: infrastructure code. Therefore we should agree that &lt;em&gt;a unit test is a fast and deterministic test that doesn’t rely on external dependencies and doesn’t require any special context to run&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Mock objects meet the &lt;em&gt;interface&lt;/em&gt; requirements. In consequence, they allow us to write and unit-test functionality without calling complex underlying or collaborating classes.&lt;/p&gt;

&lt;p&gt;A mock is a test double that stands in for real implementation code during the unit testing process. It is also capable of producing assertions about how it was manipulated by the test subject during the test run.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I strongly recommend you to read this post if you want to get into the details of why &lt;a href="https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a" rel="noopener noreferrer"&gt;Mocking is a code smell&lt;/a&gt; (Topics like these: What is a mock? What is a unit test? What is test coverage? What is tight coupling? What causes tight coupling? What does composition have to do with mocking? How do we remove coupling? and more!)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The problem with mocking
&lt;/h2&gt;

&lt;p&gt;When you mock you are overriding the logic of the mocked class. The real logic is getting hidden behind the scenes and there is actually where bugs love to live. Consider that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The mock may have attributes, methods, or arguments that the real object doesn’t.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The mock’s &lt;em&gt;return values may differ from the real objects’ return values&lt;/em&gt;. For example, it may return a different type of object that has different attributes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The mock’s &lt;em&gt;side effects and behavior may differ from the real objects’ ones&lt;/em&gt;. For example, maybe the mock fails to raise an exception when the real object would raise it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4uf7fz3oibrsjpc5d7an.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4uf7fz3oibrsjpc5d7an.png" alt="Alt Text" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives to mocking
&lt;/h2&gt;

&lt;p&gt;“Are you saying that mocking is bad and we shouldn’t mock?!” No.&lt;/p&gt;

&lt;p&gt;It depends on what you are “overriding”.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is your business domain logic what you are mocking? Then it’s wrong.&lt;/li&gt;
&lt;li&gt;Is the connection to the DB what you are mocking? Then it’s right.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;It depends on the context of the logic and where that logic belongs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Is it part of your business domain logic? Then you shouldn’t mock it but instantiate it.&lt;/p&gt;

&lt;p&gt;Is it part of any infrastructure dependency like DB connection, IO file system, Network, or any external service that has nothing to do directly with your business domain? Then &lt;em&gt;mock it using abstractions/interfaces&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The interface should be the &lt;em&gt;contract between your business domain logic and its external infrastructure dependencies&lt;/em&gt;. Imagine how easy it would be to unit test your domain logic by instantiating it and calling their methods with different arguments expecting different inputs under your entire control. &lt;a href="https://medium.com/swlh/unit-testing-effectively-4d1cabc77722" rel="noopener noreferrer"&gt;Here is an example of how to unit test written code&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some tricks
&lt;/h2&gt;

&lt;p&gt;When you are writing a unit test:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Try to instantiate your classes first.&lt;/li&gt;
&lt;li&gt;Avoid mocking concrete classes. I wrote an article exclusively about this exclusively: encouraging &lt;a href="https://medium.com/swlh/final-classes-in-php-9174e3e2747e" rel="noopener noreferrer"&gt;final classes&lt;/a&gt; and interfaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Mock interfaces. Instantiate concrete classes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://youtu.be/RbSqXFUfRMU" rel="noopener noreferrer"&gt;https://youtu.be/RbSqXFUfRMU&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;“Excessive use of mocks leads to legacy code.” — Philippe Boargau&lt;/p&gt;

&lt;h3&gt;
  
  
  How can we avoid excessive mocking?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Favor immutable state over a mutable state.&lt;/li&gt;
&lt;li&gt;Make dependencies explicit.&lt;/li&gt;
&lt;li&gt;Program to an interface, not to an implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7fxehfe1iocdjfdoc773.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7fxehfe1iocdjfdoc773.png" alt="Alt Text" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published in &lt;a href="https://chemaclass.es/blog/to-mock-or-not-to-mock/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/to-mock-or-not-to-mock/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>mocking</category>
      <category>testing</category>
      <category>design</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Sharing your git patches</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Wed, 02 Dec 2020 07:45:27 +0000</pubDate>
      <link>https://forem.com/chemaclass/sharing-your-git-patches-2582</link>
      <guid>https://forem.com/chemaclass/sharing-your-git-patches-2582</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Another way of sharing quick suggestions with your team&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Imagine this situation
&lt;/h3&gt;

&lt;p&gt;You are reviewing a Pull Request (PR) and you see some minor improvements or suggestions that you would like to share with the author. You might write some comments, and usually, that would be sufficient.&lt;/p&gt;

&lt;p&gt;But imagine that in order to transmit your “whole idea” you would need to change some files because just communicating the full picture will end up in a huge comment which might be not as clear as it could be.&lt;/p&gt;

&lt;h2&gt;
  
  
  What possibilities are there apart from just comments in a PR?
&lt;/h2&gt;

&lt;p&gt;Well, there are multiple options. The key is to be aware of them and use them wisely depending on the priority of the task and the changes themselves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As already mentioned, writing a comment as feedback is a good idea by default, but not the only one.&lt;/li&gt;
&lt;li&gt;We can always do some pair-thinking, talk at any time. Communication is always good in order to clarify the possible uncertainty.&lt;/li&gt;
&lt;li&gt;Sharing your git patches is another good option.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Git diff to the rescue!
&lt;/h1&gt;

&lt;p&gt;What if you (as a reviewer) could share your idea without any single commit or comment in the PR, but sharing your changes directly with the author?&lt;/p&gt;

&lt;p&gt;Well, that’s actually possible and really easy. As you already know, the git diff command gives you the differences between any two branches.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git diff origin develop &amp;gt; ../my-origin-develop.patch&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What we are doing here is redirecting the output of the diff command into a file (aka: patch), so we can share that output with any other peer-team.&lt;/p&gt;

&lt;h2&gt;
  
  
  What now?
&lt;/h2&gt;

&lt;p&gt;Well, having that patch file, it’s pretty easy to apply those changes in your local machine without doing any commit:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git apply ../my-origin-develop.patch&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Applying this patch will simply change your local system in the same way the patch was created.&lt;/p&gt;

&lt;h2&gt;
  
  
  “How to” by steps
&lt;/h2&gt;

&lt;p&gt;Let’s divide the responsibilities into two: the creator of the patch and its user:&lt;/p&gt;

&lt;h3&gt;
  
  
  The patch creator: the person who will create the patch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Checkout that branch
$ ~/myProject git:(the-branch) ➜ git pull origin the-branch
# Do your suggestions and changes in the targeted branch
# Generate the patch file using the diff command
$ ~/myProject git:(the-branch) ➜ git diff &amp;gt; ../your-diff.patch
# Share the patch file with the author of the PR
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The patch user: the person who will see the patch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Ensure you are in that branch
$ ~/myProject git:(the-branch) ➜ git pull origin the-branch
# Apply the patch file
$ ~/myProject git:(the-branch) ➜ git apply ../your-diff.patch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyhca9sh9ymbrgpmou9qn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyhca9sh9ymbrgpmou9qn.png" alt="Alt Text" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git-apply" rel="noopener noreferrer"&gt;https://git-scm.com/docs/git-apply&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://chemaclass.es/blog/sharing-git-patches/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/sharing-git-patches/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>patch</category>
      <category>team</category>
    </item>
    <item>
      <title>Never use array_merge in a loop</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Tue, 10 Nov 2020 09:12:51 +0000</pubDate>
      <link>https://forem.com/chemaclass/never-use-arraymerge-in-a-loop-3mj0</link>
      <guid>https://forem.com/chemaclass/never-use-arraymerge-in-a-loop-3mj0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;The spread operator to the rescue.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Flattening a one-level array
&lt;/h1&gt;

&lt;p&gt;I have seen people using the array_merge function in a loop like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;$merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$merged&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$list&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// $merged === [1, 2, 3, 4, 5, 6];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a very bad practice because it’s a (memory) performance killer!&lt;br&gt;
Instead, you should use the spread operator (in PHP since 5.6!):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;$merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// === [1, 2, 3, 4, 5, 6];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Unpacking an assoc-array
&lt;/h2&gt;

&lt;p&gt;What if you had an assoc-array instead like this one?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="s1"&gt;'key-1'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="s1"&gt;'key-2'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="s1"&gt;'key-3'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In that case, you will need to unpack its values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nb"&gt;array_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// === [1, 2, 3, 4, 5, 6];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Functional Programming, this is known as flatting a list.&lt;br&gt;
No loops &amp;amp; no more performance problem.&lt;/p&gt;
&lt;h1&gt;
  
  
  Flatting a multilevel array
&lt;/h1&gt;

&lt;p&gt;What if you wanted to flat a multilevel array like this one?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[[[]]],&lt;/span&gt; &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]]],&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or like this one, even with key-values?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'key-1'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s1"&gt;'key-2'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'key-3'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'key-4'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In these cases, you might want to use the internal standard library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;iterator_to_array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RecursiveIteratorIterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RecursiveArrayIterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nv"&gt;$use_keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// $merged === [1, 2, 3, 4, 5, 6, 7, 8];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Usually, being aware of how to flat a “2 level” array might be sufficient:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$flattenList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nb"&gt;array_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$lists&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Otherwise, the internal standard library will help you deal with it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmbcozp9t6xqjafywrgn2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmbcozp9t6xqjafywrgn2.png" alt="Alt Text" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://chemaclass.es/blog/array-merge-in-loop/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/array-merge-in-loop/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>php</category>
      <category>array</category>
      <category>performance</category>
      <category>spread</category>
    </item>
    <item>
      <title>Typed arrays in PHP</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Tue, 13 Oct 2020 08:42:01 +0000</pubDate>
      <link>https://forem.com/chemaclass/typed-arrays-in-php-hoo</link>
      <guid>https://forem.com/chemaclass/typed-arrays-in-php-hoo</guid>
      <description>&lt;p&gt;An alternative to the missing feature in PHP: Generics&lt;/p&gt;

&lt;h3&gt;
  
  
  The perfect combination
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Argument unpacking: Instead of passing the argument itself to the function, the elements it contains will be passed (as individual arguments).&lt;/li&gt;
&lt;li&gt;Function variable argument list: The arguments will be passed into the given variable as an array.&lt;/li&gt;
&lt;li&gt;Variadics function: Types can be checked with a type-hint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will use this snipped for our examples&lt;br&gt;
Having a class, &lt;code&gt;Customer&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/** 
 * @psalm-immutable 
 */&lt;/span&gt;
&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Using PHP 8 constructor property promotion&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// We create a list of 6 customers&lt;/span&gt;
&lt;span class="nv"&gt;$customers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;Customer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"name-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever we want to manipulate a list of Customers, we can pass as an argument: &lt;code&gt;…$customers&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we use to do it
&lt;/h2&gt;

&lt;p&gt;We define the array type using the PHPDoc param comment block above. But we cannot define the real type of the item. The code will still run without any problem passing any type on that argument &lt;code&gt;array $customers&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/** 
 * @param Customer[] 
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$customers&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ... some irrelevant logic for this example&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code below would work at "compile-time". But it might fail at "runtime".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'any name'&lt;/span&gt;&lt;span class="p"&gt;)]);&lt;/span&gt;
&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AnyOtherType&lt;/span&gt;&lt;span class="p"&gt;()]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An alternative (recommended!) might be to extract that logic and ask for the particular type in order to "check it" at runtime in that particular moment, failing if one of the items wasn't really a Customer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/** 
 * @param Customer[] 
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$customers&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;createInvoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;createInvoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Customer&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ... some irrelevant logic for this example&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything here below would work at "compile-time". It will for sure break during "runtime" if the &lt;code&gt;createInvoice(Customer $customer)&lt;/code&gt; receives something different than a Customer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'any name'&lt;/span&gt;&lt;span class="p"&gt;)]);&lt;/span&gt;
&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AnyOtherType&lt;/span&gt;&lt;span class="p"&gt;()]);&lt;/span&gt; &lt;span class="c1"&gt;// won't work&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing that &lt;code&gt;createInvoice(Customer $customer)&lt;/code&gt; we are ensuring the type of the argument, which is good! But, what about going one step further. Could we check the types of the elements when calling the function &lt;code&gt;createInvoiceForCustomers(array $customers)&lt;/code&gt;, even making the IDE complain when the types are not right?&lt;/p&gt;

&lt;p&gt;Well, that's actually what Generics are for, but sadly, they are not yet in PHP. Not even in the upcoming PHP 8. Hopefully in a near future, but we cannot predict that for now.&lt;br&gt;
Luckily, we have currently an alternative nowadays, but it's not that popular. It has its own "pros" and "cons", so let's take a look at an example first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Customer&lt;/span&gt; &lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;createInvoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything here below would work at "compile-time". It will for sure break during "runtime" if the &lt;code&gt;createInvoice()&lt;/code&gt; receives something different than a Customer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$customers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// OK&lt;/span&gt;
&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'any name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'any name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// OK&lt;/span&gt;
&lt;span class="c1"&gt;// This is not even possible to write. The IDE will yeld at you. &lt;/span&gt;
&lt;span class="c1"&gt;// It's expecting a `Customer`, but `AnyOtherType` is given:&lt;/span&gt;
&lt;span class="nf"&gt;createInvoiceForCustomers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AnyOtherType&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  PROS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We can easily type a list of any concrete type.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  CONS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We better define our functions with one or two arguments max. Otherwise, it would be too complicated to read.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Important remarks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It needs to be the last taken argument of a function.&lt;/li&gt;
&lt;li&gt;It helps to minimize the number of arguments that we use in a function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Argument unpacking is a great feature that, in combination with variadic functions, can help us to simulate typed arrays. With great power comes great responsibility, and this is no exception.&lt;br&gt;
We need to learn about our toolbox in order to use it wisely.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl21s9isaeeklnii4d3iw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl21s9isaeeklnii4d3iw.png" alt="Alt Text" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;References&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://wiki.php.net/rfc/argument_unpacking" rel="noopener noreferrer"&gt;Argument unpacking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list" rel="noopener noreferrer"&gt;Function variable argument list&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.php.net/rfc/variadics" rel="noopener noreferrer"&gt;Variadics function&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://chemaclass.es/blog/typed-arrays-php/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/typed-arrays-php/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>php</category>
      <category>typed</category>
      <category>array</category>
      <category>generics</category>
    </item>
    <item>
      <title>Strict Types in PHP</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Mon, 10 Aug 2020 12:02:25 +0000</pubDate>
      <link>https://forem.com/chemaclass/strict-types-in-php-21mk</link>
      <guid>https://forem.com/chemaclass/strict-types-in-php-21mk</guid>
      <description>&lt;p&gt;In December 2015, PHP 7 introduced scalar type declarations and with it the strict types flag.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To enable the strict mode, a single declare directive must be placed at the top of the file. This means that the strictness of typing for scalars is configured on a per-file basis. This directive not only affects the type declarations of parameters, but also a function’s return type.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The good thing about declaring a PHP file as strict is that it actually applies to &lt;strong&gt;ONLY the current file&lt;/strong&gt;. It ensures that this file has strict types, but it doesn’t apply to any other file in the whole project. It allows you to do, step by step, this migration from non-strict code to strict code, especially for new files or projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Strict types affect coercion types
&lt;/h2&gt;

&lt;p&gt;Using hint type without strict_types may lead to subtle bugs.&lt;/p&gt;

&lt;p&gt;Without this, &lt;code&gt;int $x&lt;/code&gt; meant &lt;code&gt;$x must have a value coercible to an int&lt;/code&gt;. Any value that could be coerced to an int would pass the hint type, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a proper &lt;code&gt;int&lt;/code&gt; (example: 42 -&amp;gt; 42)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;float&lt;/code&gt; (example: 13.1459 -&amp;gt; 13)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;bool&lt;/code&gt; (example: true -&amp;gt; 1)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;null&lt;/code&gt; (example: null -&amp;gt; 0)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;string&lt;/code&gt; with leading digits (example: “15 Trees” -&amp;gt; 15)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By setting &lt;code&gt;strict_types=1&lt;/code&gt;, you tell the engine that int $x means $x must only be an int proper, no type coercion allowed. You have the great assurance you're getting exactly and only what was given, without any conversion or potential loss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who should care about this “strict type” line?
&lt;/h2&gt;

&lt;p&gt;Actually, declare(strict_types=1); is more for the reader than for the writer. Why? Because it will explicitly tell the reader:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The types in this current scope (file/class) are treated strictly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  'strict_types=1' is more for the reader than for the writer
&lt;/h2&gt;

&lt;p&gt;The writer just needs to maintain such strictness while writing the expected behavior. That said, as a writer, you should care about your readers, which also includes your future self. Because you are going to be one of them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjz3v2bx2ffq174z7d0nu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjz3v2bx2ffq174z7d0nu.png" alt="Alt Text" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://php.chemaclass.com/technical-skills/strict-types.html" rel="noopener noreferrer"&gt;PHP Best Practices&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.scalar-type-declarations" rel="noopener noreferrer"&gt;Scalar type declarations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/48723637/what-do-strict-types-do-in-php/48723830#48723830" rel="noopener noreferrer"&gt;What do strict types do in PHP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://chemaclass.es/blog/strict-types/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/strict-types/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>software</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>The Art of Refactoring</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Thu, 02 Jul 2020 13:43:08 +0000</pubDate>
      <link>https://forem.com/chemaclass/the-art-of-refactoring-2539</link>
      <guid>https://forem.com/chemaclass/the-art-of-refactoring-2539</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;TL;DR: If you see something, in the scope of your current task, that can be easily improved, improve it. And if you have any questions about it, ask.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is refactoring?
&lt;/h2&gt;

&lt;p&gt;Refactoring means improving your code. It can go from making a variable name more readable, extract some lines of code into a private method, or separate the responsibilities of a class into subclasses, for example.&lt;/p&gt;

&lt;p&gt;Refactoring is the action of showing that you care about what you do as a professional. It can be a controversial topic; it is indeed one of the major controversial topics since a long time ago. But we shouldn’t stop trying our best in order to improve the quality of the system just because of that controversiality.&lt;/p&gt;

&lt;h2&gt;
  
  
  When and how should we refactor?
&lt;/h2&gt;

&lt;p&gt;Always in the scope of your current task unless it is an already planned task, something like “architecture refactoring” or similar, where the scope of the task is actually to do refactoring.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Refactoring should be part of our daily job, not a separate task by default.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We do not need to ask permission to refactor. Or do we ask our managers for permission to do our best job?&lt;/p&gt;

&lt;p&gt;In order to do proper refactoring, the intention of such refactoring needs to be clear. What is intended to achieve and how? Pair programming (or even pair thinking!) certainly helps in this topic because it syncs two brains on the same topic and that encourages team building and a better understanding of them.&lt;/p&gt;

&lt;p&gt;Applying refactor in a collaborative way, in a “bidirectional channel”, is fundamental when working within a team. Refactoring shouldn’t be a tabu topic, on the contrary: it will be helpful in order to unify the goals and the direction of the team code quality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8a79tfse08g8gcq5xjli.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8a79tfse08g8gcq5xjli.png" alt="Alt Text" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Some personal advice about the “how”
&lt;/h3&gt;

&lt;p&gt;Continuous improvement is what we’re looking for within this topic, but…&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you realize your changes are generating more noise than help, stop immediately and think again if your changes are worth in the current system status.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Maybe it’s not the right moment for that refactoring.&lt;/p&gt;

&lt;p&gt;Maybe you are polluting your current diff with out-scoped changes.&lt;/p&gt;

&lt;p&gt;Or, maybe, your refactoring idea is too big to be applied in your current task. In such a case, a follow-up task (in order to apply the refactoring) would be a better idea.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you see that refactoring is perhaps needed even before starting your current task, do the refactoring first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We usually refactor in order to increase our productivity, making the code more readable and therefore easier to understand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing
&lt;/h3&gt;

&lt;p&gt;Be aware that you should have a pretty well suite of tests covering the logic that you might have changed. Without tests, refactoring can be really risky. Usually, the easier something is to be tested, the easier it is to be replaced or removed.&lt;/p&gt;

&lt;p&gt;You can read more about how testing is related to quality here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why should we do it?
&lt;/h2&gt;

&lt;p&gt;Wouldn’t you want to have a better system as time goes by?&lt;/p&gt;

&lt;h4&gt;
  
  
  Software isn’t like wine: it doesn’t get better as time passes by. Therefore, if you want to have a better system you must work for it.
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F06rnpbwc1q65m9rfkato.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F06rnpbwc1q65m9rfkato.png" alt="Alt Text" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://chemaclass.es/blog/art-refactoring/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/art-refactoring/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>refactoring</category>
      <category>testing</category>
      <category>software</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>Final classes in PHP|Java|Any</title>
      <dc:creator>Jose M Valera Reales</dc:creator>
      <pubDate>Thu, 02 Jul 2020 13:34:18 +0000</pubDate>
      <link>https://forem.com/chemaclass/final-classes-in-php-java-any-aoo</link>
      <guid>https://forem.com/chemaclass/final-classes-in-php-java-any-aoo</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;TL;DR: Benefits of final classes: clear contracts, isolated side effects, testability, low complexity and cognitive load, code fluidity, and confidence in yourself.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Reduce the scope visibility to the minimum
&lt;/h3&gt;

&lt;p&gt;When you see a class prefix with final you will prevent a particular class to be extended by any other, which not only makes it more readable but also makes you be sure that the scope of the logic where you are is limited to that particular class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encourage “composition over inheritance” mentality
&lt;/h3&gt;

&lt;p&gt;The Open-Close Principle states: open for extension but close for modification.&lt;/p&gt;

&lt;p&gt;If for any reason, a good one you should be completely aware of, you decide to create an inheritance there, well, then just drop the final keyword and you are good to go.&lt;/p&gt;

&lt;p&gt;When you “by default” can’t extends from a class (because it’s final), you will help yourself by thinking about using composition instead of inheritance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why isn’t this class final?
&lt;/h2&gt;

&lt;p&gt;If we aim for composition over inheritance, then we should try to avoid inheritance as much as possible, and use it only when it’s really necessary. Inheritance is often misused in OOP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Misconception
&lt;/h3&gt;

&lt;p&gt;When we first taught OOP, we usually introduced the classic inheritance example.&lt;/p&gt;

&lt;p&gt;Nonetheless, when Alan Kay created Smalltalk, the inheritance was never the main concept of it. The main concept was messaging, which is that you can send messages to objects and they encapsulate the data and logic in it, and you can change their behavior by using different objects, which is actually composition. But the concept of inheritance is too popular that eventually overshadows composition.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzybt44rq65rfp7gcg4zu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzybt44rq65rfp7gcg4zu.png" alt="Alt Text" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Clear contracts. Using interfaces will force you to think in terms of communication between objects.&lt;/li&gt;
&lt;li&gt;Isolated, side effect free code units. Injecting interfaces only as dependencies will remove every nasty side effect around the code you are working on.&lt;/li&gt;
&lt;li&gt;Testability. Mocking dependencies is extremely easy when they are interfaces.&lt;/li&gt;
&lt;li&gt;Low, manageable complexity. Since everything is isolated, you won’t need to worry about rippling changes. This dramatically decreases the complexity of your code.&lt;/li&gt;
&lt;li&gt;Low cognitive load. With decreased complexity, your brain will be free to focus on what matters.&lt;/li&gt;
&lt;li&gt;Code fluidity. By removing any unnecessary coupling, you will be able to move things around way more easily than before.&lt;/li&gt;
&lt;li&gt;Confidence in yourself. Being able to test your code in isolation so well will give you a wonderful sense of confidence in changing it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Composition over inheritance
&lt;/h2&gt;

&lt;p&gt;If you feel the need to reconfigure an object, to change parts of an algorithm, or to rewrite part of the implementation, consider creating a new class instead of overriding an existing class.&lt;br&gt;
If you need to represent a hierarchy of classes, where subclasses are proper substitutes for their parent classes. This would be the classic situation where you may still consider inheritance. However, the result may even be better if you don’t inherit from concrete parent classes but from abstract interfaces.&lt;/p&gt;

&lt;h3&gt;
  
  
  What you should start doing instead
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use interfaces to define the contracts between your classes.&lt;/li&gt;
&lt;li&gt;Use final classes to implement behavior for those interfaces.&lt;/li&gt;
&lt;li&gt;Use composition (through constructor dependency injection) to put things together and prevent complexity.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Interfaces -&amp;gt; Final classes -&amp;gt; Composition&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzybt44rq65rfp7gcg4zu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzybt44rq65rfp7gcg4zu.png" alt="Alt Text" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://chemaclass.es/blog/final-classes/" rel="noopener noreferrer"&gt;https://chemaclass.es/blog/final-classes/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>php</category>
      <category>java</category>
      <category>final</category>
      <category>classes</category>
    </item>
  </channel>
</rss>
