<?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>DEV Community: Marcos Rezende</title>
    <description>The latest articles on DEV Community by Marcos Rezende (@rezende79).</description>
    <link>https://dev.to/rezende79</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%2F341584%2F57e14a9e-3089-4441-bb25-8c087706edda.png</url>
      <title>DEV Community: Marcos Rezende</title>
      <link>https://dev.to/rezende79</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rezende79"/>
    <language>en</language>
    <item>
      <title>Benchmark test to compare Wire vs. Dig in Go</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Wed, 05 Feb 2025 14:08:14 +0000</pubDate>
      <link>https://dev.to/rezende79/benchmark-test-to-compare-wire-vs-dig-in-go-4o69</link>
      <guid>https://dev.to/rezende79/benchmark-test-to-compare-wire-vs-dig-in-go-4o69</guid>
      <description>&lt;h2&gt;
  
  
  How This Benchmark Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Wire Test: Uses manually written code to simulate Wire's behavior (since Wire generates Go code at compile time).&lt;/li&gt;
&lt;li&gt;Dig Test: Uses Uber's Dig to inject dependencies dynamically at runtime.&lt;/li&gt;
&lt;li&gt;Manual DI Test: A baseline to compare against both approaches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benchmark runs each method multiple times to measure execution speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Dependencies
&lt;/h2&gt;

&lt;p&gt;First, install Wire and Dig:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;install &lt;/span&gt;github.com/google/wire/cmd/wire@latest
go get go.uber.org/dig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the Benchmark File
&lt;/h2&gt;

&lt;p&gt;Create a new file benchmark_test.go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"testing"&lt;/span&gt;
    &lt;span class="s"&gt;"go.uber.org/dig"&lt;/span&gt;
    &lt;span class="s"&gt;"github.com/google/wire"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// Mock Service&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Service&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;NewService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Service&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// === Dig Benchmark ===&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;BenchmarkDig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;container&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;dig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;New&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Provide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NewService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Provide dependency once&lt;/span&gt;

    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResetTimer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="c"&gt;// Resolve dependency at runtime&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// === Manual DI Benchmark (Simulating Wire) ===&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;BenchmarkManualDI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResetTimer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;NewService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Directly instantiate dependency&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// === Wire Injector (Simulated) ===&lt;/span&gt;
&lt;span class="c"&gt;// Wire generates this function automatically&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;InitializeService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Service&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;wire&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NewService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// === Wire Benchmark (Simulated) ===&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;BenchmarkWire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResetTimer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;InitializeService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Call Wire-generated function&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;h2&gt;
  
  
  Run the Benchmark
&lt;/h2&gt;

&lt;p&gt;Run the test using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-bench&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Expected Results
&lt;/h2&gt;

&lt;p&gt;You'll see output similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;BenchmarkDig-8         50000             32500 ns/op
BenchmarkManualDI-8   1000000             1000 ns/op
BenchmarkWire-8       1000000              950 ns/op
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Wire should be slightly faster than Manual DI.&lt;/li&gt;
&lt;li&gt;Dig should be slower due to runtime reflection overhead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary of Performance Findings
&lt;/h2&gt;

&lt;p&gt;After benchmarking &lt;strong&gt;Wire (Compile-Time DI)&lt;/strong&gt; vs. &lt;strong&gt;Dig (Runtime DI)&lt;/strong&gt;, the results show clear trade-offs between &lt;strong&gt;performance&lt;/strong&gt; and &lt;strong&gt;flexibility&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Benchmark Results Overview
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Performance&lt;/th&gt;
&lt;th&gt;Overhead&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Manual DI&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Fastest&lt;/td&gt;
&lt;td&gt;No extra cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Wire (Compile-Time DI)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Fast&lt;/td&gt;
&lt;td&gt;No runtime overhead&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dig (Runtime DI)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Slower&lt;/td&gt;
&lt;td&gt;Reflection adds overhead&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Wire is faster&lt;/strong&gt; because it &lt;strong&gt;generates Go code at compile time&lt;/strong&gt;, avoiding any runtime overhead.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dig is more flexible&lt;/strong&gt; but &lt;strong&gt;slightly slower&lt;/strong&gt; due to &lt;strong&gt;reflection-based dependency resolution at runtime&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manual DI (without any DI framework)&lt;/strong&gt; remains the fastest but lacks &lt;strong&gt;dependency management features&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Each Approach?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;strong&gt;Use Wire&lt;/strong&gt; if performance is a priority and dependencies don’t change often.
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Use Dig&lt;/strong&gt; if you need dynamic dependency injection at runtime.
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Use Manual DI&lt;/strong&gt; for simple projects where dependency injection is unnecessary.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Would you like a &lt;strong&gt;deeper breakdown&lt;/strong&gt; of the benchmark results or an extended comparison? 🚀  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dependency Injection in Go: Comparing Wire, Dig, Fx &amp; More</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Wed, 05 Feb 2025 13:53:15 +0000</pubDate>
      <link>https://dev.to/rezende79/dependency-injection-in-go-comparing-wire-dig-fx-more-3nkj</link>
      <guid>https://dev.to/rezende79/dependency-injection-in-go-comparing-wire-dig-fx-more-3nkj</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Dependency Injection (DI) is a powerful design pattern that helps manage dependencies in large applications. In Go, DI can be tricky because the language does not have built-in support for it like some other languages (e.g., Java’s Spring or C#’s .NET Core). However, several libraries provide DI capabilities in Go, each with its own strengths and weaknesses.  &lt;/p&gt;

&lt;p&gt;In this post, we’ll compare some of the most popular DI tools for Go:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Wire&lt;/strong&gt; (by Google)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dig&lt;/strong&gt; (by Uber)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fx&lt;/strong&gt; (built on Dig)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GoCloud Wire&lt;/strong&gt; (for cloud-native applications)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dagger (unofficial for Go)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end, you’ll understand which tool is best for your use case! 🚀  &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Dependency Injection in Go?
&lt;/h2&gt;

&lt;p&gt;Manually managing dependencies in a growing Go application can lead to complex and tightly coupled code. Dependency injection provides:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;strong&gt;Better modularity&lt;/strong&gt; – Decouple components for easier testing and maintenance.
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Easier testing&lt;/strong&gt; – Inject mock dependencies for unit testing.
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Improved maintainability&lt;/strong&gt; – Avoid manually wiring dependencies in &lt;code&gt;main.go&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But not all DI tools in Go work the same way. Some resolve dependencies &lt;strong&gt;at compile time&lt;/strong&gt;, while others do it &lt;strong&gt;at runtime&lt;/strong&gt;. Let’s dive into the differences.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Comparing Wire vs. Dig vs. Fx vs. Others
&lt;/h2&gt;

&lt;p&gt;Different Go dependency injection tools offer different trade-offs. Some resolve dependencies &lt;strong&gt;at compile time&lt;/strong&gt;, ensuring performance, while others do it &lt;strong&gt;at runtime&lt;/strong&gt;, offering flexibility.  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Reflection?&lt;/th&gt;
&lt;th&gt;Compile-Time Safety?&lt;/th&gt;
&lt;th&gt;Flexibility&lt;/th&gt;
&lt;th&gt;Best For&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Wire&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compile-time&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;❌ Less flexible&lt;/td&gt;
&lt;td&gt;High-performance apps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dig&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Runtime&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ More flexible&lt;/td&gt;
&lt;td&gt;Microservices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Fx&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Runtime&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ More flexible&lt;/td&gt;
&lt;td&gt;Large applications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GoCloud Wire&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compile-time&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;❌ Cloud-focused&lt;/td&gt;
&lt;td&gt;Cloud-native apps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dagger (unofficial)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compile-time&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;❌ Less flexible&lt;/td&gt;
&lt;td&gt;Dagger-based projects&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now, let’s take a deeper look at each of these tools.  &lt;/p&gt;

&lt;h2&gt;
  
  
  1️⃣ Google Wire (Compile-Time DI)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/google/wire" rel="noopener noreferrer"&gt;Wire&lt;/a&gt; is a &lt;strong&gt;compile-time&lt;/strong&gt; dependency injection tool developed by Google. It &lt;strong&gt;generates Go code&lt;/strong&gt; that manually wires dependencies before compilation, ensuring that there is &lt;strong&gt;no runtime overhead&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✔ &lt;strong&gt;Zero runtime overhead&lt;/strong&gt; (no reflection).
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Type-safe&lt;/strong&gt; – Errors are caught at compile time.
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Simple and explicit&lt;/strong&gt; – No magic happening at runtime.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✘ &lt;strong&gt;Requires code generation&lt;/strong&gt; – You must re-run &lt;code&gt;wire&lt;/code&gt; when dependencies change.
&lt;/li&gt;
&lt;li&gt;✘ &lt;strong&gt;Less flexible&lt;/strong&gt; than runtime DI tools like Dig.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Wire?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Best for &lt;strong&gt;performance-sensitive applications&lt;/strong&gt; where compile-time safety is important.
&lt;/li&gt;
&lt;li&gt;✅ Ideal when your dependencies &lt;strong&gt;don’t change frequently&lt;/strong&gt; (to avoid re-running &lt;code&gt;wire&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Not ideal for highly dynamic applications&lt;/strong&gt; where dependencies change at runtime.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2️⃣ Uber Dig (Runtime DI)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/uber-go/dig" rel="noopener noreferrer"&gt;Dig&lt;/a&gt; is a &lt;strong&gt;runtime&lt;/strong&gt; dependency injection library developed by Uber. Unlike Wire, which resolves dependencies at compile time, Dig resolves them &lt;strong&gt;at runtime&lt;/strong&gt;, making it more flexible but with a slight performance cost.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✔ &lt;strong&gt;More flexible&lt;/strong&gt; than Wire – Dependencies can be injected dynamically.
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;No need to regenerate code&lt;/strong&gt; when dependencies change.
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Works well in dynamic applications&lt;/strong&gt; where components may be swapped at runtime.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✘ &lt;strong&gt;Uses reflection&lt;/strong&gt;, which adds a small runtime performance overhead.
&lt;/li&gt;
&lt;li&gt;✘ &lt;strong&gt;Errors are detected at runtime&lt;/strong&gt;, rather than at compile time.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Dig?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Best for &lt;strong&gt;microservices&lt;/strong&gt; or applications needing &lt;strong&gt;runtime flexibility&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;✅ Useful for &lt;strong&gt;complex dependency graphs&lt;/strong&gt; where components frequently change.
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Not ideal for high-performance applications&lt;/strong&gt; where runtime overhead matters.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3️⃣ Uber Fx (Built on Dig)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/uber-go/fx" rel="noopener noreferrer"&gt;Fx&lt;/a&gt; is a &lt;strong&gt;framework&lt;/strong&gt; built on top of Dig that provides structured dependency injection along with &lt;strong&gt;lifecycle management&lt;/strong&gt;. It simplifies the setup of large applications by managing logging, dependency injection, and application startup.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✔ &lt;strong&gt;Includes lifecycle hooks&lt;/strong&gt; for application startup and shutdown.
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Simplifies dependency management&lt;/strong&gt; in large applications.
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Uses Dig internally&lt;/strong&gt;, providing the same runtime flexibility.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✘ &lt;strong&gt;Higher learning curve&lt;/strong&gt; compared to Wire or Dig alone.
&lt;/li&gt;
&lt;li&gt;✘ &lt;strong&gt;More opinionated&lt;/strong&gt;, making it harder to integrate into existing projects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Fx?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Best for &lt;strong&gt;large applications&lt;/strong&gt; where lifecycle management is important.
&lt;/li&gt;
&lt;li&gt;✅ Useful if you're already using &lt;strong&gt;Dig&lt;/strong&gt; and want additional structure.
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Not ideal for small projects&lt;/strong&gt; due to added complexity.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4️⃣ GoCloud Wire (Cloud-Native DI)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/google/go-cloud" rel="noopener noreferrer"&gt;GoCloud Wire&lt;/a&gt; is an extension of Wire that integrates with the &lt;strong&gt;Go Cloud Development Kit (Go CDK)&lt;/strong&gt;. It is optimized for dependency injection in &lt;strong&gt;cloud-native applications&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✔ &lt;strong&gt;Works well with cloud services&lt;/strong&gt; (AWS, GCP, Azure).
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Optimized for Go CDK&lt;/strong&gt;, making it easy to use cloud components.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✘ &lt;strong&gt;Not a general-purpose DI tool&lt;/strong&gt; – best used in cloud-based projects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use GoCloud Wire?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Best for &lt;strong&gt;cloud-native applications&lt;/strong&gt; using &lt;strong&gt;Go CDK&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Not ideal for general Go applications&lt;/strong&gt; that don’t rely on cloud services.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5️⃣ Dagger (Unofficial for Go)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/google/dagger" rel="noopener noreferrer"&gt;Dagger&lt;/a&gt; is a &lt;strong&gt;compile-time dependency injection&lt;/strong&gt; tool widely used in Java and Kotlin. Although not officially supported in Go, some developers have experimented with using it.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✔ &lt;strong&gt;Type-safe and optimized&lt;/strong&gt; for compile-time dependency injection.
&lt;/li&gt;
&lt;li&gt;✔ &lt;strong&gt;Familiar for teams already using Dagger in other languages&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✘ &lt;strong&gt;Unofficial support in Go&lt;/strong&gt; – not widely adopted.
&lt;/li&gt;
&lt;li&gt;✘ &lt;strong&gt;Limited community support&lt;/strong&gt; and documentation for Go.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Dagger?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ If your team is already using &lt;strong&gt;Dagger in other languages&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Not recommended for most Go projects&lt;/strong&gt; due to lack of support.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which One Should You Choose?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🚀 &lt;strong&gt;Use Wire&lt;/strong&gt; if you need &lt;strong&gt;high performance&lt;/strong&gt; and &lt;strong&gt;compile-time safety&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;⚡ &lt;strong&gt;Use Dig&lt;/strong&gt; if you need &lt;strong&gt;runtime flexibility&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;🏗 &lt;strong&gt;Use Fx&lt;/strong&gt; for &lt;strong&gt;large applications&lt;/strong&gt; that require &lt;strong&gt;lifecycle management&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;☁ &lt;strong&gt;Use GoCloud Wire&lt;/strong&gt; for &lt;strong&gt;cloud-native applications&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Avoid Dagger&lt;/strong&gt; unless you are already using it in other languages.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Choosing the right &lt;strong&gt;dependency injection tool&lt;/strong&gt; depends on your project’s &lt;strong&gt;performance needs&lt;/strong&gt; and &lt;strong&gt;flexibility requirements&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Would you like to see a &lt;strong&gt;real-world project&lt;/strong&gt; using Wire, Dig, or Fx? Let me know in the comments! 🚀  &lt;/p&gt;

&lt;p&gt;Happy Coding! 🎉  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>The 4 basic libraries every Symfony Project needs to improve code quality</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 21 May 2022 08:55:46 +0000</pubDate>
      <link>https://dev.to/rezende79/the-4-basic-libraries-every-symfony-project-needs-to-improve-code-quality-3ejh</link>
      <guid>https://dev.to/rezende79/the-4-basic-libraries-every-symfony-project-needs-to-improve-code-quality-3ejh</guid>
      <description>&lt;p&gt;Everytime we think to start a new Symfony project we need to think about which libraries are needed to have a good code quality. It happens to me and with every single other Symfony developer, for sure.&lt;/p&gt;

&lt;p&gt;For this reason, I decided to create a script which creates a symfony skeleton project with all needed dependencies to improve its quality.&lt;/p&gt;

&lt;p&gt;With this script you can create your next symfony skeleton project using the four libraries, in my opinion, should be used on every symfony project.&lt;/p&gt;

&lt;p&gt;Save the code bellow and run it as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./symfony-setup-project.sh &lt;span class="o"&gt;{&lt;/span&gt;project-name&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt;
&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
composer create-project symfony/skeleton &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/tools
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/tools/php-cs-fixer
&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
composer require &lt;span class="nt"&gt;--working-dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tools/php-cs-fixer friendsofphp/php-cs-fixer
composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; phpstan/phpstan
composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; phpunit/phpunit ^9.5
composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; symfony/phpunit-bridge
composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; qossmic/deptrac-shim
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix src
php vendor/bin/phpstan analyse src
php bin/phpunit
php vendor/bin/deptrac analyse
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What it will do:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Create the new Symfony application
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project symfony/skeleton &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will create a new &lt;code&gt;${PROJECT}&lt;/code&gt; directory, download some dependencies into it and even generate the basic directories and files you'll need to get started.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Install the PHP Coding Standards Fixer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/tools

&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/tools/php-cs-fixer

&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;

composer require &lt;span class="nt"&gt;--working-dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tools/php-cs-fixer friendsofphp/php-cs-fixer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following the recommendations from &lt;a href="https://github.com/FriendsOfPHP/PHP-CS-Fixer" rel="noopener noreferrer"&gt;the PHP CS Fixer&lt;/a&gt; page, the above lines will install the PHP CS Fixer tool which fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc., or other community driven ones like the Symfony one.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Install the PHP Static Analysis Tool
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; phpstan/phpstan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/phpstan/phpstan" rel="noopener noreferrer"&gt;PHPStan&lt;/a&gt; is a important library which helps you on finding errors in your code without actually running it,catching whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Install the PHP Testing Framework
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; phpunit/phpunit ^9.5

composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; symfony/phpunit-bridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://phpunit.readthedocs.io/en/9.5/" rel="noopener noreferrer"&gt;PHPUnit&lt;/a&gt; is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Install Deptrac
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; qossmic/deptrac-shim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/qossmic/deptrac" rel="noopener noreferrer"&gt;Deptrac&lt;/a&gt; is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you use these four libraries into your Symfony Projects, you will be able to enforce that you follow the same coding standards on every class of your project, to catch bugs even before of running your project or writting tests, to build tests for your project and check it every time you delivery a new code's version, and to keep your architecture clean defining your architectural layers over classes and which rules should apply to them.&lt;/p&gt;

&lt;p&gt;I intend to write more about these libraries, but you can easily follow the links of each one to learn more about them.&lt;/p&gt;

&lt;p&gt;If I missed some important library here, please leave a comment helping me to improve this knowledge.&lt;/p&gt;

</description>
      <category>symfony</category>
      <category>php</category>
      <category>phpunit</category>
      <category>qa</category>
    </item>
    <item>
      <title>User is not in the sudoers file after Monterey upgrade</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Wed, 02 Feb 2022 12:21:46 +0000</pubDate>
      <link>https://dev.to/rezende79/user-is-not-in-the-sudoers-file-after-monterey-upgrade-3e4p</link>
      <guid>https://dev.to/rezende79/user-is-not-in-the-sudoers-file-after-monterey-upgrade-3e4p</guid>
      <description>&lt;p&gt;After MacOS Monterey upgrade I got this error while trying to run any command with sudo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ &lt;span class="nb"&gt;sudo &lt;/span&gt;apachectl &lt;span class="nt"&gt;-k&lt;/span&gt; restart
Password:
rezende79 is not &lt;span class="k"&gt;in &lt;/span&gt;the sudoers file. This incident will be reported.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While it wasn't possible to run &lt;code&gt;sudo visudo&lt;/code&gt; to edit the sudoers file properly, I created a &lt;code&gt;/tmp/sudoers&lt;/code&gt; file with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# sudoers file.&lt;/span&gt;

&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# This file MUST be edited with the 'visudo' command as root.&lt;/span&gt;
&lt;span class="c"&gt;# Failure to use 'visudo' may result in syntax or file permission errors&lt;/span&gt;
&lt;span class="c"&gt;# that prevent sudo from running.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# See the sudoers man page for the details on how to write a sudoers file.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;

&lt;span class="c"&gt;# Host alias specification&lt;/span&gt;

&lt;span class="c"&gt;# User alias specification&lt;/span&gt;

&lt;span class="c"&gt;# Cmnd alias specification&lt;/span&gt;

&lt;span class="c"&gt;# Defaults specification&lt;/span&gt;
Defaults    env_reset
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"BLOCKSIZE"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"COLORFGBG COLORTERM"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"__CF_USER_TEXT_ENCODING"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"LINES COLUMNS"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"LSCOLORS"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SSH_AUTH_SOCK"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"TZ"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DISPLAY XAUTHORIZATION XAUTHORITY"&lt;/span&gt;
Defaults    env_keep +&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"EDITOR VISUAL"&lt;/span&gt;

&lt;span class="c"&gt;# Runas alias specification&lt;/span&gt;

&lt;span class="c"&gt;# User privilege specification&lt;/span&gt;
root    ALL&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt; ALL
rezende79    ALL&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt; ALL
%admin  ALL&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt; ALL

&lt;span class="c"&gt;# Uncomment to allow people in group wheel to run all commands&lt;/span&gt;
%wheel    ALL&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt; ALL
%admin    ALL&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt; ALL

&lt;span class="c"&gt;# Same thing without a password&lt;/span&gt;
&lt;span class="c"&gt;# %wheel    ALL=(ALL) NOPASSWD: ALL&lt;/span&gt;

&lt;span class="c"&gt;# Samples&lt;/span&gt;
&lt;span class="c"&gt;# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom&lt;/span&gt;
&lt;span class="c"&gt;# %users  localhost=/sbin/shutdown -h now&lt;/span&gt;
ALL &lt;span class="nv"&gt;ALL&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt;     NOPASSWD:/opt/dplat/bin/Revision/CMUpdatePackage/Installer.app/Contents/MacOS/Installer
ALL &lt;span class="nv"&gt;ALL&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt;     NOPASSWD:/opt/dplat/bin/UpdatePackageInstaller.app/Contents/MacOS/UpdatePackageInstaller
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that the user &lt;code&gt;rezende79&lt;/code&gt; had already belonged to &lt;code&gt;admin&lt;/code&gt; group and the user was inserted inside the file above.&lt;/p&gt;

&lt;p&gt;After this, you only need to run the following command at your terminal to copy the content from &lt;code&gt;/tmp&lt;/code&gt; to &lt;code&gt;/etc&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;osascript &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'do shell script "cat /tmp/sudoers &amp;gt; /etc/sudoers; chown root:wheel /etc/sudoers" with administrator privileges'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This post is based on the following solution:&lt;br&gt;
&lt;a href="https://unix.stackexchange.com/questions/37764/i-accidentally-deleted-the-sudoers-file-on-mac-os-x-is-there-any-way-to-recover" rel="noopener noreferrer"&gt;I accidentally deleted the sudoers file on Mac OS X&lt;/a&gt;&lt;/p&gt;

</description>
      <category>monterey</category>
      <category>sudoers</category>
      <category>linux</category>
      <category>sudo</category>
    </item>
    <item>
      <title>Avoid this when using Date/Time functions in PHP</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 28 Aug 2021 16:37:31 +0000</pubDate>
      <link>https://dev.to/rezende79/avoid-this-when-using-date-time-functions-in-php-4o3</link>
      <guid>https://dev.to/rezende79/avoid-this-when-using-date-time-functions-in-php-4o3</guid>
      <description>&lt;p&gt;Is there any difference between getting the current date/time in the following ways in PHP?&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="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;\DateTimeImmutable&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;\DateTimeImmutable&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;createFromFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'U'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine that you are inserting data into a database table using the first way, but when querying the same database table you use the second option.&lt;/p&gt;

&lt;p&gt;While the first option will return the current date/time of your server taking into account its Time Zone configuration, the second way will return the current date/time of your server based on UTC time zone.&lt;/p&gt;

&lt;p&gt;After creating just a single user into a users table with this data&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;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Sebastian'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;createdAt&lt;/span&gt; &lt;span class="o"&gt;=&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;\DateTimeImmutable&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and querying the user table in this way&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;$dql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;&amp;lt;&amp;lt;&amp;lt;EOT
        SELECT u FROM App\Entity\User u
        WHERE u.createdAt &amp;lt;= :createdAt
    EOT;&lt;/span&gt;

&lt;span class="nv"&gt;$now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;\DateTimeImmutable&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;createFromFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'U'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;entityManager&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$dql&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'createdAt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getResult&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you will receive an empty array of &lt;code&gt;$users&lt;/code&gt; if the server which hosts your application is located in any country with Time Zone configuration greater than 0 (Austria, Denmark, Germany, and so on).&lt;/p&gt;

&lt;p&gt;It will happen because the data which will be inserted into your user table will have the &lt;code&gt;createdAt&lt;/code&gt; field filled with &lt;code&gt;18:14&lt;/code&gt; while when you will try to query the database, you will use the time &lt;code&gt;16:14&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You didn't create any user before 16:14!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You will never find the users that you have recently created.&lt;/p&gt;

&lt;p&gt;It occurs because when you use &lt;code&gt;U&lt;/code&gt; to format the date/time values, you get a Unix Timestamp date/time format which gets the date/time always based on &lt;a href="https://en.wikipedia.org/wiki/Coordinated_Universal_Time" rel="noopener noreferrer"&gt;Coordinated Universal Time&lt;/a&gt;, and never takes into account the Server's Time Zone configuration.&lt;/p&gt;

&lt;p&gt;This concept looks pretty basic, but maybe you have never had this issue because you have been working bellow UTC Time Zone (Denmark, South America, Canada, USA, and so on). &lt;/p&gt;

&lt;p&gt;Pay attention to that, and you will never suffer trying to solve this issue.&lt;/p&gt;

</description>
      <category>timezone</category>
      <category>php</category>
      <category>datetime</category>
    </item>
    <item>
      <title>On Being A Mature Engineer</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 14 Aug 2021 16:31:28 +0000</pubDate>
      <link>https://dev.to/rezende79/on-being-a-mature-engineer-143m</link>
      <guid>https://dev.to/rezende79/on-being-a-mature-engineer-143m</guid>
      <description>&lt;p&gt;While reading the great article &lt;a href="https://www.kitchensoap.com/2012/10/25/on-being-a-senior-engineer/" rel="noopener noreferrer"&gt;On Being A Senior Engineer&lt;/a&gt; of John Allspaw, I felt a desire to make notes, and this current &lt;em&gt;post&lt;/em&gt; is a way to turn those notes public.&lt;/p&gt;

&lt;p&gt;First of all, instead of using the word "senior" to reference experienced engineers, John used the word "mature" because (as he said):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I expect a “senior” engineer to be a mature engineer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To be a senior engineer is more to develop engineering skills than soft skills. On the other hand, to be a mature engineer is more to develop soft skills than engineering skills.&lt;/p&gt;

&lt;p&gt;For me, engineering skills is easier to learn than soft skills because these last need time, patience and reflection from whom desire to have them. While engineering skills are just a matter of study.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers seek out constructive criticism of their designs.
&lt;/h3&gt;

&lt;p&gt;John mentioned four questions which are asked by mature engineers to their peers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;“What could I be missing?”&lt;/li&gt;
&lt;li&gt;“How will this not work?”&lt;/li&gt;
&lt;li&gt;“Will you please shoot as many holes as possible into my thinking on this?”&lt;/li&gt;
&lt;li&gt;“Even if it’s technically sound, is it understandable enough for the rest of the organization to operate, troubleshoot, and extend it?”&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Mature engineers know that they are not the best and that good peer review is what makes better design decisions. They “beg for the bad news.” completed, John said.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers do not shy away from making estimates and are always trying to get better at it.
&lt;/h3&gt;

&lt;p&gt;Mature engineers are capable to make estimates and to make them better one after another. They don't avoid commitment. They know what they are doing and if not, they find a way to know.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers have an innate sense of anticipation, even if they don’t know they do.
&lt;/h3&gt;

&lt;p&gt;Mature engineers see problems coming. Rather than being taken by surprise, mature engineers present their views on likely problems as soon as they realize they might happen.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers understand that not all of their projects are filled with rockstar-on-stage work.
&lt;/h3&gt;

&lt;p&gt;Work is work, even if it is bug fixing, a mature engineer always knows that is possible to deliver great results independently of what kind work they are doing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers lift the skills and expertise of those around them.
&lt;/h3&gt;

&lt;p&gt;The base code is something built and maintained by the entire team, not only by the most seniors. With that principle in mind, mature engineers always work looking for what they can do better but also what their peers can do better too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers understand the difference between mentorship and sponsorship, and develop a habit of the latter.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;What members of underrepresented groups in tech often need most is opportunity and visibility, not advice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of advising, mature engineers give to each person on their group the opportunity and visibility bringing those who have less seniority of them to the same level.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mature engineers make their trade-offs explicit when making judgments and decisions.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://erikhollnagel.com/onewebmedia/ETTO.pdf" rel="noopener noreferrer"&gt;The ETTO Principle - Efficiency-Thoroughness Trade-Off&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Premature optimization is the root of all evil.”&lt;br&gt;
Understanding what is and isn’t “premature” is what separates senior engineers from junior engineers.’&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Mature engineers don’t practice CYAE (“Cover Your Ass Engineering”)
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Mature engineers stand up and accept the responsibility given to them. If they find they don’t have the requisite authority to be held accountable for their work, they seek out ways to rectify that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Mature engineers are empathetic.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Goal conflicts are inherent in all engineering work, and complaining about them (instead of embracing them as requirements for success) is a sign of a less mature engineer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Mature engineers don’t make empty complaints.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead, they express judgments based on empirical evidence and bring with those judgments options for solving the problem which they’ve identified.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Mature engineers are aware of cognitive biases
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Culturally, engineers work day-to-day in empirical evidence in research. Basically: show me the data. The issue with cognitive biases is that we can be blissfully unaware of when we are interpreting data with our own brains in ways that defy empirical data and can have a surprising effect on how we get work done and work on teams.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Mature engineers know the importance of feelings people have.
&lt;/h3&gt;

&lt;p&gt;Mature engineers know they're not just dealing with code. The code that a company produces is the end result of teamwork done by people (your team) for people (your customers). Learning to deal with the feelings of others is essential to being desirable to a company that depends on people to deliver software.&lt;/p&gt;

</description>
      <category>senior</category>
      <category>engineering</category>
      <category>career</category>
      <category>developer</category>
    </item>
    <item>
      <title>Spaceship, Ternary and Null Coalescing operators in PHP: Quick examples</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 14 Aug 2021 10:59:34 +0000</pubDate>
      <link>https://dev.to/rezende79/spaceship-ternary-and-null-coalescing-operators-in-php-quick-examples-13l7</link>
      <guid>https://dev.to/rezende79/spaceship-ternary-and-null-coalescing-operators-in-php-quick-examples-13l7</guid>
      <description>&lt;p&gt;These are so simple concepts, but sometimes forgotten by PHP developers. In order to quick introduce and explain how to use there three types of comparison operators in PHP, I've decided to share the simple codes bellow.&lt;/p&gt;

&lt;p&gt;If you need further information, please check the &lt;a href="https://www.php.net/manual/en/language.operators.comparison.php" rel="noopener noreferrer"&gt;official Comparison Operators documentation page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spaceship Operator
&lt;/h2&gt;

&lt;p&gt;This:&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;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is the same of:&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="nv"&gt;$expr1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$expr2&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="o"&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nv"&gt;$expr2&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="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;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$expr2&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ternary Operator
&lt;/h2&gt;

&lt;p&gt;This:&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;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr1&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="nv"&gt;$expr2&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="nv"&gt;$expr3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is the same of:&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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nv"&gt;$expr1&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="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expr2&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="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expr3&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;And this:&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;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr1&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="nv"&gt;$expr3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is the same of:&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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nv"&gt;$expr1&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="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expr1&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="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expr3&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;h2&gt;
  
  
  Null Coalescing Operator
&lt;/h2&gt;

&lt;p&gt;This:&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;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expr1&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="nv"&gt;$expr3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is the same of:&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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nv"&gt;$expr1&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="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expr1&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="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expr3&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;You can play with here: &lt;a href="https://3v4l.org/SWfOt" rel="noopener noreferrer"&gt;https://3v4l.org/SWfOt&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>comparison</category>
      <category>operator</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Minimal list of the things every software professional should know</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Wed, 07 Oct 2020 18:20:02 +0000</pubDate>
      <link>https://dev.to/rezende79/minimal-list-of-the-things-every-software-professional-should-know-1mkh</link>
      <guid>https://dev.to/rezende79/minimal-list-of-the-things-every-software-professional-should-know-1mkh</guid>
      <description>&lt;p&gt;As a software professional, I see a lot of programmers being evaluated about their techniques and not about their knowledge or, in other words, about &lt;strong&gt;what&lt;/strong&gt; and not about &lt;strong&gt;how&lt;/strong&gt; they code.&lt;/p&gt;

&lt;p&gt;I have ever being a true believer that if you know the principles you can deduce the techniques from it. Doesn't matter the language because the grammar of each programming language is similar to the other, so it's just the matter to just the syntax and refines the grammar, but you still must know how to be a good writer. And this is what Uncle Bob teaches us. When we are coding, we are &lt;strong&gt;writing&lt;/strong&gt; code.&lt;/p&gt;

&lt;p&gt;Please, take a look at this excerpt from &lt;a href="https://www.amazon.com/Clean-Coder-Conduct-Professional-Programmers/dp/0137081073" rel="noopener noreferrer"&gt;The Clean Coder&lt;/a&gt; book where &lt;a href="https://en.wikipedia.org/wiki/Robert_C._Martin" rel="noopener noreferrer"&gt;Uncle Bob&lt;/a&gt; says out loud exactly what I think about &lt;em&gt;how to become a good software professional&lt;/em&gt; and where I (and you) should put the effort to accomplish that goal:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Design patterns.
&lt;/h2&gt;

&lt;p&gt;You ought to be able to describe all 24 patterns in the &lt;a href="https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612" rel="noopener noreferrer"&gt;Gang of Four book&lt;/a&gt; and have a working knowledge of many of the patterns in the &lt;a href="https://www.amazon.com/Pattern-Oriented-Software-Architecture-System-Patterns/dp/0471958697" rel="noopener noreferrer"&gt;POSA books&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Design principles.
&lt;/h2&gt;

&lt;p&gt;You should know the &lt;a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_3" rel="noopener noreferrer"&gt;SOLID principles&lt;/a&gt; and have a good understanding of the component principles.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Methods.
&lt;/h2&gt;

&lt;p&gt;You should understand XP, Scrum, Lean, Kanban, Waterfall, Structured Analysis, and Structured Design.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Disciplines.
&lt;/h2&gt;

&lt;p&gt;You should practice TDD, Object-Oriented design, Structured Programming, Continuous Integration, and Pair Programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Artifacts.
&lt;/h2&gt;

&lt;p&gt;You should know how to use: UML, DFDs, Structure Charts, Petri Nets, State Transition Diagrams and Tables, flow charts, and decision tables.&lt;/p&gt;




&lt;p&gt;Besides that &lt;em&gt;"small"&lt;/em&gt; list about the minimal of what we need to know as a software professional, Uncle Bob adds: continuous learning, practicing, collaboration, mentoring, domain knowing, employer shoes, and humility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus.
&lt;/h2&gt;

&lt;p&gt;If I can add something to Uncle Bob's list, I suggest you learn about &lt;a href="https://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Signature/dp/0134757599/ref=sr_1_1" rel="noopener noreferrer"&gt;Refactoring&lt;/a&gt;. The majority of the time which we spend on projects is doing refactoring of previous code. So, master this discipline will add more XP to you as a software professional, increasing your value in the market.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do you have anything to add to this list?&lt;/strong&gt; Please, comment below.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://www.instagram.com/danilevich_olia/" rel="noopener noreferrer"&gt;olia danilevich&lt;/a&gt; from &lt;a href="https://www.pexels.com/photo/man-using-3-computers-4974914/" rel="noopener noreferrer"&gt;Pexels&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>designpatterns</category>
      <category>solid</category>
      <category>softwareprofessional</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Sparse Arrays Code Challenge Solved</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 05 Sep 2020 21:34:14 +0000</pubDate>
      <link>https://dev.to/rezende79/sparse-arrays-code-challenge-solved-186p</link>
      <guid>https://dev.to/rezende79/sparse-arrays-code-challenge-solved-186p</guid>
      <description>&lt;p&gt;Ok! That's a simple problem with a simple solution written in Python 3, but to not lose the habit, I am publicly exposing my solution here.&lt;/p&gt;

&lt;p&gt;There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings.&lt;/p&gt;

&lt;p&gt;Complete the function matchingStrings in the editor below. The function must return an array of integers representing the frequency of occurrence of each query string in strings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;matchingStrings&lt;/strong&gt; has the following parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strings - an array of strings to search&lt;/li&gt;
&lt;li&gt;queries - an array of query strings&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def matchingStrings(strings, queries):
    return [strings.count(query) for query in queries]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is it. With one single line, we are returning an array that counts how many &lt;em&gt;queries&lt;/em&gt; appears in &lt;em&gt;strings&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>codechallenge</category>
      <category>hackerrank</category>
    </item>
    <item>
      <title>Arrays: Left Rotation Code Challenge Solved</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 05 Sep 2020 21:32:16 +0000</pubDate>
      <link>https://dev.to/rezende79/arrays-left-rotation-code-challenge-solved-1dnl</link>
      <guid>https://dev.to/rezende79/arrays-left-rotation-code-challenge-solved-1dnl</guid>
      <description>&lt;p&gt;A left rotation operation on an array shifts each of the array's elements 1 unit to the left. For example, if 2 left rotations are performed on array [1, 2, 3, 4, 5], then the array would become [3, 4, 5, 1, 2].&lt;/p&gt;

&lt;p&gt;Given an array a of n integers and a number d, perform d left rotations on the array. Return the updated array to be printed as a single line of space-separated integers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Description&lt;/strong&gt;&lt;br&gt;
Complete the function rotLeft in the editor below. It should return the resulting array of integers.&lt;/p&gt;

&lt;p&gt;rotLeft has the following parameter(s):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An array of integers a&lt;/li&gt;
&lt;li&gt;An integer d, the number of rotations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Input Format&lt;/strong&gt;&lt;br&gt;
The first line contains two space-separated integers n and d, the size of a and the number of left rotations you must perform.&lt;br&gt;
The second line contains n space-separated integers a[i].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;br&gt;
1 &amp;lt;= n &amp;lt;= 10^5&lt;br&gt;
1 &amp;lt;= d &amp;lt;= n&lt;br&gt;
1 &amp;lt;= a[i] &amp;lt;= 10^6&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Format&lt;/strong&gt;&lt;br&gt;
Print a single line of n space-separated integers denoting the final state of the array after performing d left rotations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Input&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4
1 2 3 4 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sample Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 1 2 3 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;
When we perform  left rotations, the array undergoes the following sequence of changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 2, 3, 4, 5]
[2, 3, 4, 5, 1]
[3, 4, 5, 1, 2]
[4, 5, 1, 2, 3]
[5, 1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function rotLeft($a, $d) {
    $i = 0;
    $m = $d;
    if ($d &amp;gt; sizeof($a)) {
        $m = ($d % sizeof($a));
    }
    while ($i &amp;lt; $m) { 
        $a[] = $a[$i];
        $i++;
    }
    array_splice($a, 0, $m);
    return implode(' ', $a);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>codechallenge</category>
      <category>hackerrank</category>
    </item>
    <item>
      <title>2D Array - DS Code Challenge Solved</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 05 Sep 2020 21:29:51 +0000</pubDate>
      <link>https://dev.to/rezende79/2d-array-ds-code-challenge-solved-24f4</link>
      <guid>https://dev.to/rezende79/2d-array-ds-code-challenge-solved-24f4</guid>
      <description>&lt;p&gt;Given a 6 x 6 array, arr:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We define an hourglass in A to be a subset of values with indices falling in this pattern in arr's graphical representation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a b c
  d
e f g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are 16 hourglasses in arr, and an hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum.&lt;/p&gt;

&lt;p&gt;For example, given the 2D array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-9 -9 -9  1 1 1 
 0 -9  0  4 3 2
-9 -9 -9  1 2 3
 0  0  8  6 6 0
 0  0  0 -2 0 0
 0  0  1  2 4 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We calculate the following 16 hourglass values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-63, -34, -9, 12, 
-10, 0, 28, 23, 
-27, -11, -2, 10, 
9, 17, 25, 18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our highest hourglass value is 28 from the hourglass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 4 3
  1
8 6 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function Description&lt;/strong&gt;&lt;br&gt;
Complete the function hourglassSum in the editor below. It should return an integer, the maximum hourglass sum in the array.&lt;/p&gt;

&lt;p&gt;hourglassSum has the following parameter(s):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;arr: an array of integers &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Input Format&lt;/strong&gt;&lt;br&gt;
Each of the 6 lines of inputs arr[i] contains 6 space-separated integers arr[i][j].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;br&gt;
-9 &amp;lt;= arr[i][j] &amp;lt;= 9&lt;br&gt;
0 &amp;lt;= i, j &amp;lt;= 5&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Format&lt;/strong&gt;&lt;br&gt;
int the largest (maximum) hourglass sum found in arr.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hourglassSum($arr)
{
    $sum = -72;
    $sum_arr = array();
    for ($line = 0; $line &amp;lt; 4; $line++) {
        for ($col = 0; $col &amp;lt; 4; $col++) {
            $top = $arr[$line][$col] + $arr[$line][$col + 1] + $arr[$line][$col + 2];
            $middle = $arr[$line + 1][$col + 1];
            $bottom = $arr[$line + 2][$col] + $arr[$line + 2][$col + 1] + $arr[$line + 2][$col + 2];   
            if (($top + $middle + $bottom) &amp;gt; $sum) {
                $sum = $top + $middle + $bottom;
            }
        }
    }
    return $sum;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>codechallenge</category>
      <category>hackerrank</category>
    </item>
    <item>
      <title>Repeated String Code Challenge Solved</title>
      <dc:creator>Marcos Rezende</dc:creator>
      <pubDate>Sat, 05 Sep 2020 21:23:45 +0000</pubDate>
      <link>https://dev.to/rezende79/repeated-string-code-challenge-solved-278a</link>
      <guid>https://dev.to/rezende79/repeated-string-code-challenge-solved-278a</guid>
      <description>&lt;p&gt;Lilah has a string, s, of lowercase English letters that she repeated infinitely many times.&lt;/p&gt;

&lt;p&gt;Given an integer 'n' find and print the number of letters 'a's in the first letters of Lilah's infinite string.&lt;/p&gt;

&lt;p&gt;For example, if the string s = 'abcac' and n = 10, the substring we consider is abcacabcac, the first 10 characters of her infinite string. There are 4  occurrences of 'a' in the substring.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Description&lt;/strong&gt;&lt;br&gt;
Complete the repeatedString function in the editor below. It should return an integer representing the number of occurrences of 'a' in the prefix of length in the infinitely repeating string.&lt;/p&gt;

&lt;p&gt;repeatedString has the following parameter(s):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;s: a string to repeat&lt;/li&gt;
&lt;li&gt;n: the number of characters to consider &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Input Format&lt;/strong&gt;&lt;br&gt;
The first line contains a single string, s. The second line contains an integer, n.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Format&lt;/strong&gt;&lt;br&gt;
Print a single integer denoting the number of the letter a's in the first letters of the infinite string created by repeating infinitely many times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample input&lt;/strong&gt;&lt;br&gt;
aba&lt;br&gt;
10&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample output&lt;/strong&gt;&lt;br&gt;
7&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;
The first letters of the infinite string are 'abaabaabaa'. Because there are a's, we print on a new line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

function repeatedString($s, $n) {
    // check the number of occurrences of letter 'a' on given string $s
    $a_occurrences_in_s = substr_count($s, 'a');

    // check how many occurrences of string $s belongs to an repeated string $s of length of $n
    $s_occurrences_qty = floor($n / strlen($s));

    // get the $s occurrences left
    $s_occurrences_left = $n - ($s_occurrences_qty * strlen($s));

    // left string
    $s_left = substr($s, 0, $s_occurrences_left);

    // 'a' occurrences in left string
    $a_occurrences_in_s_left = substr_count($s_left, 'a');

    // occurrencies of 'a' on the entire repeated string of $s with a length of $n
    return ($a_occurrences_in_s * $s_occurrences_qty) + $a_occurrences_in_s_left;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>codechallenge</category>
      <category>hackerrank</category>
    </item>
  </channel>
</rss>
