<?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: NgeTech</title>
    <description>The latest articles on DEV Community by NgeTech (@bentesolution).</description>
    <link>https://dev.to/bentesolution</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%2F450738%2Fbf271fa2-7135-4091-b325-bd42b0dd904f.png</url>
      <title>DEV Community: NgeTech</title>
      <link>https://dev.to/bentesolution</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bentesolution"/>
    <language>en</language>
    <item>
      <title>Awesome! use Match Expression for simplify your code in PHP 8</title>
      <dc:creator>NgeTech</dc:creator>
      <pubDate>Thu, 01 Aug 2024 23:23:54 +0000</pubDate>
      <link>https://dev.to/bentesolution/awesome-use-match-expression-for-simplify-your-code-in-php-8-4fif</link>
      <guid>https://dev.to/bentesolution/awesome-use-match-expression-for-simplify-your-code-in-php-8-4fif</guid>
      <description>&lt;p&gt;PHP 8 introduces the match expression, which is a more powerful and concise alternative to the traditional switch statement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The traditional switch statement requires break statements and can be more verbose.&lt;/li&gt;
&lt;li&gt;The new match expression simplifies the syntax and returns a value directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;for the example when we use switch case statement :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getDayTypeWithSwitch(int $day): string
{
    switch ($day) {
        case 1:
        case 7:
            return 'weekend';
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
            return 'weekday';
        default:
            return 'unknown';
    }
}

echo getDayTypeWithSwitch(8); // Output: unknown
echo getDayTypeWithSwitch(7); // Output: weekend
echo getDayTypeWithSwitch(4); // Output: weekday
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the we comparing use match expression :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getDayWithMatch(int $day): string
{
    return match ($day) {
        1, 7 =&amp;gt; 'weekend',
        2, 3, 4, 5, 6 =&amp;gt; 'weekday',
        default =&amp;gt; 'unknown',
    };
}

echo getDayWithMatch(8); // Output: unknown
echo getDayWithMatch(7); // Output: weekend
echo getDayWithMatch(4); // Output: weekday
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;awesome you should be try it !&lt;/p&gt;

&lt;p&gt;✅ 𝐁𝐞𝐧𝐞𝐟𝐢𝐭𝐬 𝐨𝐟 𝐔𝐬𝐢𝐧𝐠 𝐌𝐚𝐭𝐜𝐡 𝐄𝐱𝐩𝐫𝐞𝐬𝐬𝐢𝐨𝐧𝐬&lt;/p&gt;

&lt;p&gt;👉 𝐂𝐨𝐧𝐜𝐢𝐬𝐞 𝐒𝐲𝐧𝐭𝐚𝐱: Reduces boilerplate code by eliminating the need for break statements.&lt;br&gt;
👉 𝐑𝐞𝐭𝐮𝐫𝐧𝐬 𝐕𝐚𝐥𝐮𝐞𝐬: Can return values directly, making the code more expressive and functional.&lt;br&gt;
👉 𝐒𝐭𝐫𝐢𝐜𝐭 𝐂𝐨𝐦𝐩𝐚𝐫𝐢𝐬𝐨𝐧𝐬: Uses strict comparisons (===) by default, avoiding type coercion issues.&lt;/p&gt;

&lt;p&gt;By using match expressions in PHP 8, you can write cleaner, more efficient, and more readable code.&lt;/p&gt;

&lt;p&gt;How do you like the new match expressions? Have you used them in your project yet? Share your experience in the comments below.&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Pattern Matching for Switch in Java 21</title>
      <dc:creator>NgeTech</dc:creator>
      <pubDate>Thu, 18 Jul 2024 06:52:43 +0000</pubDate>
      <link>https://dev.to/bentesolution/pattern-matching-for-switch-in-java-21-42pj</link>
      <guid>https://dev.to/bentesolution/pattern-matching-for-switch-in-java-21-42pj</guid>
      <description>&lt;p&gt;Pattern matching has been a highly anticipated feature in Java, bringing more power and flexibility to the language. Java 21 introduces pattern matching for switch statements, which simplifies the code and reduces boilerplate. Let's explore how this new feature works and why it's beneficial.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Pattern Matching for Switch?
&lt;/h3&gt;

&lt;p&gt;Pattern matching for switch allows you to match a value against patterns, making the code more expressive and readable. Instead of using multiple if-else statements or complex switch cases, you can now write more concise and maintainable code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Pattern Matching for Switch
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Readability&lt;/strong&gt;: Makes the code easier to read and understand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conciseness&lt;/strong&gt;: Reduces the amount of boilerplate code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type Safety&lt;/strong&gt;: Provides better type checking at compile time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to Use Pattern Matching for Switch
&lt;/h3&gt;

&lt;p&gt;Here's a simple example to illustrate how pattern matching for switch works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static String formatterPatternSwitch(Object obj) {
    return switch (obj) {
        case Integer i -&amp;gt; String.format("int %d", i);
        case Long l    -&amp;gt; String.format("long %d", l);
        case Double d  -&amp;gt; String.format("double %f", d);
        case String s  -&amp;gt; String.format("String %s", s);
        default        -&amp;gt; obj.toString();
    };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, formatterPatternSwitch takes an Object and returns a formatted string based on its type. Here's a breakdown of what's happening:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Switch Expression: The switch expression takes the obj and matches it against different patterns.&lt;/li&gt;
&lt;li&gt;Case Patterns: Each case specifies a pattern to match:

&lt;ul&gt;
&lt;li&gt;Integer i: Matches if obj is an instance of Integer and        binds the value to i.&lt;/li&gt;
&lt;li&gt;Long l: Matches if obj is an instance of Long and binds the value to l.&lt;/li&gt;
&lt;li&gt; Double d: Matches if obj is an instance of Double and binds the value to d.&lt;/li&gt;
&lt;li&gt; String s: Matches if obj is an instance of String and binds the value to s.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Default Case: The default case handles any values that do not match the specified patterns, converting them to a string using obj.toString().&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's me give with detailed example case: Handling Different Shapes&lt;/p&gt;

&lt;p&gt;Consider a scenario where you need to handle different shapes and calculate their areas. Here's how pattern matching for switch can simplify the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract sealed class Shape permits Circle, Square, Rectangle {}

final class Circle extends Shape {
    double radius;
    Circle(double radius) { this.radius = radius; }
}

final class Square extends Shape {
    double side;
    Square(double side) { this.side = side; }
}

final class Rectangle extends Shape {
    double length, width;
    Rectangle(double length, double width) { this.length = length; this.width = width; }
}

static double calculateArea(Shape shape) {
    return switch (shape) {
        case Circle c -&amp;gt; Math.PI * c.radius * c.radius;
        case Square s -&amp;gt; s.side * s.side;
        case Rectangle r -&amp;gt; r.length * r.width;
    };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sealed Classes: &lt;strong&gt;Shape&lt;/strong&gt; is a sealed class, and only &lt;strong&gt;Circle&lt;/strong&gt;, &lt;strong&gt;Square&lt;/strong&gt;, and &lt;strong&gt;Rectangle&lt;/strong&gt; can extend it.&lt;/li&gt;
&lt;li&gt;Switch Expression: The &lt;strong&gt;calculateArea&lt;/strong&gt; method uses a switch expression to determaine the type of &lt;strong&gt;shape&lt;/strong&gt; and calculate its area.&lt;/li&gt;
&lt;li&gt;Case Patterns: Each case matches a spesific shape type and performs the corressponding area calculation:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Circle c&lt;/strong&gt;: Matches if &lt;strong&gt;shape&lt;/strong&gt; is a &lt;strong&gt;Circle&lt;/strong&gt; and binds it to &lt;strong&gt;c&lt;/strong&gt;, the calculates the area using &lt;strong&gt;c.radius&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Square s&lt;/strong&gt;: Matches if &lt;strong&gt;shape&lt;/strong&gt; is a &lt;strong&gt;Square&lt;/strong&gt; and binds it to &lt;strong&gt;s&lt;/strong&gt;, the calculates the area using &lt;strong&gt;s.side&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rectangle r&lt;/strong&gt;: Matches if &lt;strong&gt;shape&lt;/strong&gt; is a &lt;strong&gt;Rectangle&lt;/strong&gt; and binds it to &lt;strong&gt;r&lt;/strong&gt;, the calculates the area using &lt;strong&gt;r.length&lt;/strong&gt; and &lt;strong&gt;r.width&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Pattern matching for switch in Java 21 is a powerful feature that enhances code readability, conciseness, and type safety. By allowing you to match values against patterns directly in switch statements, it simplifies many common coding tasks. Java developers should definitely explore and adopt this feature to write cleaner and more maintainable code.&lt;/p&gt;

&lt;p&gt;Feel free to modify or expand upon this section to suit your needs!&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>coding</category>
    </item>
    <item>
      <title>New in PHP 8! Simplify Your Code with the Nullsafe Operator</title>
      <dc:creator>NgeTech</dc:creator>
      <pubDate>Sat, 06 Jul 2024 00:59:22 +0000</pubDate>
      <link>https://dev.to/bentesolution/new-in-php-8-53ig</link>
      <guid>https://dev.to/bentesolution/new-in-php-8-53ig</guid>
      <description>&lt;p&gt;The Nullsafe operator, introduced in PHP 8.0, is a game-changer for handling nullable properties and method calls more gracefully. It allows you to avoid verbose null checks, making your code cleaner and more readable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example Tradition Null Check
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$userCountry = null;
if ($user !== null) {
   if ($user-&amp;gt;getAddress() !== null) {
      $userCountry = $user-&amp;gt;getAddress()-&amp;gt;getCountry();  
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;𝐖𝐡𝐲 𝐔𝐬𝐞 𝐭𝐡𝐞 𝐍𝐮𝐥𝐥𝐬𝐚𝐟𝐞 𝐎𝐩𝐞𝐫𝐚𝐭𝐨𝐫?&lt;/p&gt;

&lt;p&gt;✅ 𝐂𝐨𝐧𝐜𝐢𝐬𝐞𝐧𝐞𝐬𝐬: Reduces the amount of boilerplate code required for null checks.&lt;br&gt;
✅ 𝐑𝐞𝐚𝐝𝐚𝐛𝐢𝐥𝐢𝐭𝐲: Makes your code more readable and expressive, clearly showing the intent of handling nullable values.&lt;br&gt;
✅ 𝐒𝐚𝐟𝐞𝐭𝐲: Helps avoid null dereference errors in a more elegant way, ensuring your code handles potential null values seamlessly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nullsafe implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$userCountry = $user?-&amp;gt;getAddress()?-&amp;gt;getCountry();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Have you started using the Nullsafe operator in your PHP 8 projects? Share your thoughts and experiences!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
    </item>
    <item>
      <title>Use an Object Literal, Better than Using Conditional Statements in JavaScript</title>
      <dc:creator>NgeTech</dc:creator>
      <pubDate>Fri, 28 Jun 2024 09:20:55 +0000</pubDate>
      <link>https://dev.to/bentesolution/use-an-object-literal-better-than-using-conditional-statements-in-javascript-1269</link>
      <guid>https://dev.to/bentesolution/use-an-object-literal-better-than-using-conditional-statements-in-javascript-1269</guid>
      <description>&lt;p&gt;Conditional Statements (If-Else, Switch) can be easily replaced with Object Literals. They make the code better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object Literals
&lt;/h2&gt;

&lt;p&gt;An Object Literal is one of the most popular and widely used pattern to define objects in JavaScript. It is a collection of key-value pairs. JavaScript being powerful, adds some additional functionalities to the simple objects through object literals.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
   first_name: 'Irpan',
   last_name: 'Abdul Rahman'
}
// An example of an object literal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How can we use Object Literal as a replacement to Conditional Statements?&lt;/p&gt;

&lt;p&gt;Let us consider an example scenario to understand this.&lt;/p&gt;

&lt;p&gt;A user enters an animal, we need to return the name of its baby (what is is called).&lt;/p&gt;

&lt;p&gt;Look at the following codes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//if conditional
if(animal.toLowerCase()==='cat'){
    return 'Kitten'
} else if(animal.toLowerCase()=='cattle'){
     return 'Calf'
} else if(animal.toLowerCase()==='cheetah'){
     return 'Cub';
} else if(animal.toLowerCase()==='dog'){
     return 'Pup';
} else{
   return "I don't know that"
}

//switch case
switch(animal.toLowerCase()){
   case 'cat': return 'Kitten'
   case 'cattle': return 'Calf'
   case 'cheetah': return 'Cub'
   case 'dog': return 'Pup'
   default: return "I don't know that"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above codes have many lines as we can see. No matter if we write it using if-else or switch case, though switch case reduces the redundant ‘animal.toLowerCase()’.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const babyAnimal = {
   cat:'Kitten',
   cattle:'Calf',
   cheetah:'Cub',
   dog:'Pup'
}
return babyAnimal[animal.toLowerCase()] ?? "I don't know that"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, this code works exactly same as the above two codes do. But the difference is that it looks neater and has lesser conditions to check thereby reducing the load time.&lt;/p&gt;

&lt;p&gt;I think it’s pretty nice to use this wherever possible. Any thoughts on this? please comment bellow.&lt;/p&gt;

&lt;p&gt;credit cover images by &lt;a href="https://unsplash.com/@markusspiske?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Markus Spiske&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/code-on-a-computer-AaEQmoufHLk?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>es6</category>
      <category>react</category>
    </item>
  </channel>
</rss>
