<?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: Gabriel Peixoto</title>
    <description>The latest articles on Forem by Gabriel Peixoto (@peixotons).</description>
    <link>https://forem.com/peixotons</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%2F1183313%2F8e3bfd17-c672-4714-800f-63df5a96071c.jpeg</url>
      <title>Forem: Gabriel Peixoto</title>
      <link>https://forem.com/peixotons</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/peixotons"/>
    <language>en</language>
    <item>
      <title>How I Passed the AWS Exam in 10 Days(no bs)</title>
      <dc:creator>Gabriel Peixoto</dc:creator>
      <pubDate>Thu, 15 May 2025 01:59:46 +0000</pubDate>
      <link>https://forem.com/peixotons/how-i-passed-the-aws-exam-in-10-daysno-bs-171m</link>
      <guid>https://forem.com/peixotons/how-i-passed-the-aws-exam-in-10-daysno-bs-171m</guid>
      <description>&lt;h3&gt;
  
  
  How I passed the 𝐀𝐖𝐒 𝐂𝐋𝐎𝐔𝐃 𝐏𝐑𝐀𝐂𝐓𝐈𝐓𝐈𝐎𝐍𝐄𝐑 exam in 10 days 🥇
&lt;/h3&gt;

&lt;p&gt;IN SHORT, I STUDIED A LOT..&lt;/p&gt;

&lt;p&gt;Jokes aside, I created a challenge in my mind to pass in just 10 days, I made the payment for the test on April 21st at 11:22 pm and scheduled the test for April 26th, a Saturday.&lt;/p&gt;

&lt;p&gt;So I joined Udemy and started studying &lt;strong&gt;Stéphane Maarek's&lt;/strong&gt; course, it covers everything you need to pass the AWS exam in a cohesive and concise way. I work 8 hours a day but whenever I had some free time, even at lunch, I would watch classes and 𝐈 𝐖𝐑𝐎𝐓𝐄 𝐈𝐓 𝐃𝐎𝐖𝐍 𝐈𝐍 𝐀 𝐍𝐎𝐓𝐄𝐁𝐎𝐎𝐊 𝐀𝐍𝐃 𝐒𝐏𝐎𝐊𝐄 𝐈𝐓 𝐎𝐔𝐓 𝐋𝐎𝐔𝐃 (In my head, writing down and talking about the topic was the difference).&lt;/p&gt;

&lt;p&gt;Even though I studied whenever I had time, I wasn't confident enough to take the test on April 26th, so &lt;strong&gt;I rescheduled the test for May 1st&lt;/strong&gt;, a Thursday.&lt;/p&gt;

&lt;p&gt;After finishing &lt;strong&gt;Stéphane Maarek's&lt;/strong&gt; course and doing 8 mock exams with 65 questions each, I felt confident. In the last 2 mock exams, I scored 860-890, so I felt I was ready.&lt;/p&gt;

&lt;p&gt;🤝 The biggest lessons I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;𝐇𝐚𝐯𝐞 𝐚 𝐠𝐨𝐨𝐝 𝐦𝐞𝐧𝐭𝐨𝐫 𝐭𝐨 𝐭𝐞𝐚𝐜𝐡 𝐲𝐨𝐮, 𝐈 𝐫𝐞𝐜𝐨𝐦𝐦𝐞𝐧𝐝 𝐒𝐭é𝐩𝐡𝐚𝐧𝐞&lt;/li&gt;
&lt;li&gt;𝐁𝐮𝐲 𝐚 𝐧𝐨𝐭𝐞𝐛𝐨𝐨𝐤 𝐚𝐧𝐝 𝐭𝐚𝐤𝐞 𝐧𝐨𝐭𝐞𝐬, 𝐰𝐫𝐢𝐭𝐢𝐧𝐠 𝐝𝐨𝐰𝐧 𝐦𝐚𝐤𝐞𝐬 𝐚 𝐝𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞&lt;/li&gt;
&lt;li&gt;𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬 𝐨𝐮𝐭 𝐥𝐨𝐮𝐝 𝐚𝐬 𝐢𝐟 𝐲𝐨𝐮 𝐰𝐞𝐫𝐞 𝐭𝐚𝐥𝐤𝐢𝐧𝐠 𝐭𝐨 𝐬𝐨𝐦𝐞𝐨𝐧𝐞&lt;/li&gt;
&lt;li&gt;𝐂𝐫𝐞𝐚𝐭𝐞 𝐚 𝐜𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞, 𝐚 𝐠𝐨𝐚𝐥, 𝐚𝐧 𝐨𝐛𝐣𝐞𝐜𝐭𝐢𝐯𝐞 𝐚𝐧𝐝 𝐩𝐮𝐫𝐬𝐮𝐞 𝐢𝐭&lt;/li&gt;
&lt;li&gt;𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞 𝐀𝐖𝐒 𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬, 𝐞𝐚𝐜𝐡 𝐨𝐟 𝐭𝐡𝐞𝐦 𝐬𝐨𝐥𝐯𝐞𝐬 𝐬𝐨𝐦𝐞𝐨𝐧𝐞’𝐬 𝐩𝐫𝐨𝐛𝐥𝐞𝐦&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The challenge&lt;/strong&gt; was what made me anxious but at the same time wanting to study and get there, as well as when I received the information that I passed on, happiness came and I thought at the time that the days studying were rewarded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On my LinkedIn I posted the proof where I show the date I paid for the exam and the appointments.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>programming</category>
      <category>learning</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Clean, Fast, and Efficient: 4 PHP Tips to Supercharge Your Code</title>
      <dc:creator>Gabriel Peixoto</dc:creator>
      <pubDate>Thu, 20 Mar 2025 01:33:57 +0000</pubDate>
      <link>https://forem.com/peixotons/clean-fast-and-efficient-4-php-tips-to-supercharge-your-code-1c00</link>
      <guid>https://forem.com/peixotons/clean-fast-and-efficient-4-php-tips-to-supercharge-your-code-1c00</guid>
      <description>&lt;p&gt;Hey, PHP folks! Want cleaner, faster code without breaking a sweat? Here are four practical tips to sharpen your skills. I’ll keep it short but juicy, with examples and a peek at why they work—spoiler: some are turbo-charged by C optimizations. Let’s roll!&lt;/p&gt;

&lt;h3&gt;
  
  
  Tip 1: Use &lt;code&gt;empty()&lt;/code&gt; for Smarter Variable Checks
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;empty()&lt;/code&gt; function is your go-to for checking if a variable exists and has a meaningful value (not &lt;code&gt;''&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;). It’s not just handy—it’s a language construct baked into PHP’s core, optimized in C for speed.&lt;/p&gt;

&lt;p&gt;Before:&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$var&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$var&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$var&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"It’s got something!"&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;After:&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$var&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"It’s got something!"&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;&lt;strong&gt;Why it’s better:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;empty()&lt;/code&gt; combines multiple checks into one sleek call. Since it’s written in C, it’s faster than stacking &lt;code&gt;isset()&lt;/code&gt; and comparisons. Plus, it’s easier to read—less clutter, more clarity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tip 2: Lean on Built-in Functions
&lt;/h3&gt;

&lt;p&gt;PHP’s built-in functions, like &lt;code&gt;str_replace()&lt;/code&gt; or &lt;code&gt;array_sum()&lt;/code&gt;, aren’t just convenient—they’re coded in C, making them lightning-fast compared to DIY solutions.&lt;/p&gt;

&lt;p&gt;Before:&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;$str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$search&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$replace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"PHP"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$str&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nv"&gt;$i&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$search&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nv"&gt;$search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$replace&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$str&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$i&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;After:&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;$str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;str_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PHP"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$str&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it’s better:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Built-ins like &lt;code&gt;str_replace()&lt;/code&gt; are optimized at the C level, so they outpace manual loops by a mile. They’re also battle-tested, reducing bugs and boosting readability. Why reinvent the wheel when PHP’s got a turbo version?&lt;/p&gt;

&lt;h3&gt;
  
  
  Tip 3: Swap Loops for Array Functions
&lt;/h3&gt;

&lt;p&gt;Need to process arrays? Skip the &lt;code&gt;foreach&lt;/code&gt; grind and use &lt;code&gt;array_map()&lt;/code&gt; or &lt;code&gt;array_filter()&lt;/code&gt;. These functions are designed for arrays and come with internal optimizations that traditional loops can’t match.&lt;/p&gt;

&lt;p&gt;Before:&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;$numbers&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="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="nv"&gt;$squares&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;$numbers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$squares&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;$num&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;After:&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;$numbers&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="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="nv"&gt;$squares&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="nv"&gt;$num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;$num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$numbers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it’s better:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;array_map()&lt;/code&gt; is slicker and faster, thanks to PHP’s array-handling optimizations. It cuts out loop overhead and keeps your code concise—perfect for big datasets or just showing off your modern PHP chops.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tip 4: Cache Smarter with Static Variables
&lt;/h3&gt;

&lt;p&gt;Got a function doing heavy lifting, like a database call? Use static variables to cache results inside the function. It’s a simple trick that leverages PHP’s memory management to skip redundant work.&lt;/p&gt;

&lt;p&gt;Before:&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;getUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Imagine a slow DB query here&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'User '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;$user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getUserData&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="nv"&gt;$user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getUserData&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="c1"&gt;// Repeats the work&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&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;getUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nv"&gt;$cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'User '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;$user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getUserData&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="nv"&gt;$user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getUserData&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="c1"&gt;// Pulls from cache&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it’s better:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Static vars stick around between calls, storing results in memory. This avoids re-running expensive operations, making your app snappier—especially in loops or high-traffic scenarios.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrap-Up
&lt;/h2&gt;

&lt;p&gt;There you go—four PHP tips to make your code faster, cleaner, and smarter: &lt;code&gt;empty()&lt;/code&gt; for checks, built-ins for speed, array functions for style, and static caching for efficiency. Many of these tap into C-level optimizations baked into PHP, so you’re getting performance boosts for free. Try them out, tweak them, and let me know your own tricks in the comments. Happy coding!&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Simplify Your PHP Code with KISS, YAGNI, and DRY</title>
      <dc:creator>Gabriel Peixoto</dc:creator>
      <pubDate>Wed, 12 Mar 2025 00:19:48 +0000</pubDate>
      <link>https://forem.com/peixotons/simplify-your-php-code-with-kiss-yagni-and-dry-p5g</link>
      <guid>https://forem.com/peixotons/simplify-your-php-code-with-kiss-yagni-and-dry-p5g</guid>
      <description>&lt;h2&gt;
  
  
  Simplify Your PHP Code with KISS, YAGNI, and DRY
&lt;/h2&gt;

&lt;p&gt;Good code doesn’t need to be complicated. Principles like KISS, YAGNI, and DRY help you write cleaner, more maintainable PHP code without changing what it does. In this article, we’ll take a super simple example and improve it using these ideas, showing how they make your code better—step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Are These Principles?
&lt;/h3&gt;

&lt;p&gt;KISS (Keep It Simple, Stupid): Avoid unnecessary complexity. Simple code is easier to read and less prone to bugs.&lt;/p&gt;

&lt;p&gt;YAGNI (You Ain’t Gonna Need It): Don’t add features you don’t need right now. Keep your code focused.&lt;/p&gt;

&lt;p&gt;DRY (Don’t Repeat Yourself): Avoid duplicating code. Centralize logic to make updates easier.&lt;/p&gt;

&lt;p&gt;Let’s see them in action with a example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing User Discounts and Final Price
&lt;/h3&gt;

&lt;p&gt;Calculating a user’s final price after applying a discount based on their membership status. Both versions will produce the same output, but the "after" version will be cleaner and more maintainable.&lt;/p&gt;

&lt;h4&gt;
  
  
  Before: Overly Complicated and Redundant
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
// Before version: overly complicated

$userType = "premium"; // Can be "premium", "standard", or "guest"
$originalPrice = 200;
$discountRatePremium = 0.20; // 20% discount for premium
$discountRateStandard = 0.10; // 10% discount for standard
$minimumPriceThreshold = 50; 

// Complex discount logic with redundant checks
$discountAmount = 0;
if ($userType === "premium") {
    if ($originalPrice &amp;gt; $minimumPriceThreshold) {
        $discountAmount = $originalPrice * $discountRatePremium;
        if ($discountAmount &amp;gt; 0) {
            $finalPrice = $originalPrice - $discountAmount;
        } else {
            $finalPrice = $originalPrice;
        }
    } else {
        $finalPrice = $originalPrice;
    }
} elseif ($userType === "standard") {
    if ($originalPrice &amp;gt; $minimumPriceThreshold) {
        $discountAmount = $originalPrice * $discountRateStandard;
        if ($discountAmount &amp;gt; 0) {
            $finalPrice = $originalPrice - $discountAmount;
        } else {
            $finalPrice = $originalPrice;
        }
    } else {
        $finalPrice = $originalPrice;
    }
} else {
    $finalPrice = $originalPrice; // No discount for guests
}

// Unnecessary logging feature we don’t use yet
$logMessage = "User type: $userType, Original: $originalPrice, Final: $finalPrice";

// Specific condition tied to a hardcoded value
if ($finalPrice === 160) {
    $status = "Discount applied successfully for premium user.";
} else {
    $status = "No special discount condition met.";
}

echo "Original Price: $originalPrice\n";
echo "Discount Amount: $discountAmount\n";
echo "Final Price: $finalPrice\n";
echo "$status\n";
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The output
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Original Price: 200
Discount Amount: 40
Final Price: 160
Discount applied successfully for premium user.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What’s Messy Here?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;KISS Violation: Nested if statements make the discount logic overly complex. The $discountAmount &amp;gt; 0 check is redundant since the discount rate and price are positive.&lt;/li&gt;
&lt;li&gt;YAGNI Violation: The $minimumPriceThreshold check and $logMessage variable suggest future functionality (logging or price validation), but they’re not needed now.&lt;/li&gt;
&lt;li&gt;DRY Violation: The discount calculation logic is repeated for "premium" and "standard" users, duplicating code unnecessarily.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  After: Simple and Maintainable
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
// Refactored version: simple and maintainable

$userType = "premium"; // Can be "premium", "standard", or "guest"
$originalPrice = 200;

// Define discount rates in a simple array
$discountRates = [
    "premium" =&amp;gt; 0.20, // 20% discount
    "standard" =&amp;gt; 0.10, // 10% discount
    "guest" =&amp;gt; 0.0 // No discount
];

// Calculate discount and final price directly
$discountRate = $discountRates[$userType] ?? 0.0; // Default to 0 if user type is invalid
$discountAmount = $originalPrice * $discountRate;
$finalPrice = $originalPrice - $discountAmount;

// Flexible status message using a ternary operator
$status = ($discountAmount &amp;gt; 0) ? "Discount applied successfully." : "No discount applied.";

echo "Original Price: {$originalPrice}\n";
echo "Discount Amount: {$discountAmount}\n";
echo "Final Price: {$finalPrice}\n";
echo "{$status}\n";
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The output
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Original Price: 200
Discount Amount: 40
Final Price: 160
Discount applied successfully.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Why It’s Better:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;KISS: The discount logic is simplified by using an array to store rates and a single calculation ($originalPrice * $discountRate). No nested if statements.&lt;/li&gt;
&lt;li&gt;YAGNI: Removed the $minimumPriceThreshold and $logMessage since they’re not required for the current functionality.&lt;/li&gt;
&lt;li&gt;DRY: The discount logic is centralized with the $discountRates array, eliminating repetition across user types.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Congratulations&lt;/strong&gt;—you’ve made it to the end! By sticking with us, you’ve unlocked the power of KISS, YAGNI, and DRY—principles that can transform the way you write code. Try applying them to your next project and see the difference for yourself. Have you used these ideas before? Share your thoughts or success stories in the comments below!&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why You Need SOLID as a Developer</title>
      <dc:creator>Gabriel Peixoto</dc:creator>
      <pubDate>Sun, 09 Mar 2025 02:29:00 +0000</pubDate>
      <link>https://forem.com/peixotons/why-you-need-solid-as-a-developer-1fp5</link>
      <guid>https://forem.com/peixotons/why-you-need-solid-as-a-developer-1fp5</guid>
      <description>&lt;h2&gt;
  
  
  Do You Need SOLID to Be a Better Developer?
&lt;/h2&gt;

&lt;p&gt;You don’t need SOLID to write working code—many developers manage without it. But to become a better developer (and potentially earn more by writing high-quality, maintainable software), learning SOLID basics is a smart move. SOLID’s five principles make code more understandable, flexible, and maintainable.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Single Responsibility Principle
&lt;/h2&gt;

&lt;p&gt;"Do one thing and do it well"—that’s Uncle Bob’s advice from his book. SRP means a class should have just one responsibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  SRP Failing
&lt;/h3&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%2Fbarp8ws8hv0mkqlua87z.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%2Fbarp8ws8hv0mkqlua87z.png" alt="SRP Failing" width="542" height="905"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Book&lt;/code&gt; class has two responsibilities:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managing book details (title, author, description)—its core purpose.
&lt;/li&gt;
&lt;li&gt;Interacting with a database (&lt;code&gt;saveToDatabase&lt;/code&gt;)—unrelated to the book’s properties. That’s a mistake.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SRP Essence
&lt;/h3&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%2Fnzp5jrf2qhdrzqqk792o.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%2Fnzp5jrf2qhdrzqqk792o.png" alt="SRP essence" width="545" height="960"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To fix this, separate the responsibilities:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Book&lt;/code&gt; focuses solely on book-related tasks.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DatabaseManager&lt;/code&gt; handles database operations.
Each class now has one reason to change:
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Book&lt;/code&gt; if book properties change.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DatabaseManager&lt;/code&gt; if database logic changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Open/Closed Principle
&lt;/h2&gt;

&lt;p&gt;The Open/Closed Principle (OCP) means software entities (classes, modules) should be open for extension but closed for modification—add new functionality without altering existing code.&lt;/p&gt;

&lt;h3&gt;
  
  
  OCP Failing
&lt;/h3&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%2Ft85ro3si31atzl4624yc.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%2Ft85ro3si31atzl4624yc.png" alt="OCP Failing" width="753" height="889"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
The &lt;code&gt;ShippingCalculator&lt;/code&gt; calculates shipping costs based on book type.&lt;br&gt;
The mistake?&lt;br&gt;
Adding a new type requires modifying it with another &lt;code&gt;elseif&lt;/code&gt;, breaking OCP. This opens the class to changes, risking bugs.&lt;/p&gt;

&lt;h3&gt;
  
  
  OCP Essence
&lt;/h3&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%2Fsbawwknbf5w1x1kphg5a.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%2Fsbawwknbf5w1x1kphg5a.png" alt="OCP Essence" width="582" height="965"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
The &lt;code&gt;ShippingCalculator&lt;/code&gt; stays closed for modification by using a &lt;code&gt;ShippingType&lt;/code&gt; interface. New types (&lt;code&gt;PaperbackShipping&lt;/code&gt;, &lt;code&gt;HardcoverShipping&lt;/code&gt;) extend it, delegating logic to specific classes. This keeps the system flexible and bug-free.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Liskov Substitution Principle
&lt;/h2&gt;

&lt;p&gt;The Liskov Substitution Principle (LSP) states that subclass objects should replace parent class objects without breaking the program—substitution should work seamlessly.&lt;/p&gt;

&lt;h3&gt;
  
  
  LSP Failing
&lt;/h3&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%2Fj859vphgsn8tbc3jb5lz.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%2Fj859vphgsn8tbc3jb5lz.png" alt="Liskov Failing" width="460" height="719"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
A &lt;code&gt;Bird&lt;/code&gt; class assumes all birds can &lt;code&gt;fly()&lt;/code&gt;, but a &lt;code&gt;Penguin&lt;/code&gt; subclass can’t. This breaks LSP because &lt;code&gt;Penguin&lt;/code&gt; isn’t substitutable for &lt;code&gt;Bird&lt;/code&gt; without altering behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  LSP Essence
&lt;/h3&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%2Ff580b0sv4pn17e1jjk5m.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%2Ff580b0sv4pn17e1jjk5m.png" alt="LSP Essence" width="461" height="829"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
An &lt;code&gt;Animal&lt;/code&gt; interface with a &lt;code&gt;move()&lt;/code&gt; method lets &lt;code&gt;Sparrow&lt;/code&gt; and &lt;code&gt;Penguin&lt;/code&gt; implement it their way. The &lt;code&gt;makeAnimalMove()&lt;/code&gt; function works with any &lt;code&gt;Animal&lt;/code&gt; subclass without breaking, satisfying LSP.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Interface Segregation Principle
&lt;/h2&gt;

&lt;p&gt;ISP states that classes shouldn’t be forced to implement interfaces they don’t use—keep interfaces small and specific.&lt;/p&gt;

&lt;h3&gt;
  
  
  ISP Failing
&lt;/h3&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%2Fcl5ufn0gdy01l40jbsjt.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%2Fcl5ufn0gdy01l40jbsjt.png" alt="ISP Failing" width="629" height="959"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
A &lt;code&gt;Worker&lt;/code&gt; interface includes &lt;code&gt;work()&lt;/code&gt; and &lt;code&gt;manage()&lt;/code&gt;. &lt;code&gt;Developer&lt;/code&gt; only needs &lt;code&gt;work()&lt;/code&gt; but must implement &lt;code&gt;manage()&lt;/code&gt; too, breaking ISP by forcing unused methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  ISP Essence
&lt;/h3&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%2Fv9ejmg9swzcyy8bbnece.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%2Fv9ejmg9swzcyy8bbnece.png" alt="ISP Essence" width="468" height="966"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;Workable&lt;/code&gt; and &lt;code&gt;Manageable&lt;/code&gt; are separate interfaces. &lt;code&gt;Developer&lt;/code&gt; implements only &lt;code&gt;Workable&lt;/code&gt;; &lt;code&gt;Manager&lt;/code&gt; implements both. No unused methods are forced, satisfying ISP.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Dependency Inversion Principle
&lt;/h2&gt;

&lt;p&gt;DIP states that high-level modules shouldn’t depend on low-level ones—both should rely on abstractions (interfaces) for flexibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  DIP Failing
&lt;/h3&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%2Flu7afoxq1bpvj9zyn1da.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%2Flu7afoxq1bpvj9zyn1da.png" alt="DIP Failing" width="578" height="736"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;Notification&lt;/code&gt; (high-level) directly depends on &lt;code&gt;FileLogger&lt;/code&gt; (low-level). Switching to &lt;code&gt;DatabaseLogger&lt;/code&gt; requires changing &lt;code&gt;Notification&lt;/code&gt;, breaking DIP due to tight coupling.&lt;/p&gt;

&lt;h3&gt;
  
  
  DIP Essence
&lt;/h3&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%2F6nsjtot5e4dpoay77lcm.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%2F6nsjtot5e4dpoay77lcm.png" alt="DIP Essence" width="611" height="831"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
A &lt;code&gt;Logger&lt;/code&gt; interface defines the contract. &lt;code&gt;Notification&lt;/code&gt; depends on &lt;code&gt;Logger&lt;/code&gt;, not &lt;code&gt;FileLogger&lt;/code&gt;. Swapping &lt;code&gt;FileLogger&lt;/code&gt; for &lt;code&gt;DatabaseLogger&lt;/code&gt; needs no changes to &lt;code&gt;Notification&lt;/code&gt;, following DIP by relying on abstractions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;SOLID principles improve code quality and flexibility. Apply them to level up your skills and projects. Thanks for reading!&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>solidprinciples</category>
      <category>programming</category>
      <category>php</category>
    </item>
  </channel>
</rss>
