<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sukma Rizki</title>
    <description>The latest articles on Forem by Sukma Rizki (@sukma_rizki__444).</description>
    <link>https://forem.com/sukma_rizki__444</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%2F1314803%2F6ac5f7b7-9d1c-4eae-86ab-f41896cbb0f7.png</url>
      <title>Forem: Sukma Rizki</title>
      <link>https://forem.com/sukma_rizki__444</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sukma_rizki__444"/>
    <language>en</language>
    <item>
      <title>UNSUPERVISED LEARNING</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Wed, 31 Dec 2025 11:02:12 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/unsupervised-learning-16hd</link>
      <guid>https://forem.com/sukma_rizki__444/unsupervised-learning-16hd</guid>
      <description>&lt;p&gt;Unsupervised learning occurs when the algorithm is not given a specific “wrong” or “right” outcome. Instead, the algorithm is given unlabeled data. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering Rate Limiting in Golang Strategies for Scalable APIs</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Thu, 24 Jul 2025 06:03:53 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/mastering-rate-limiting-in-golang-strategies-for-scalable-apis-286i</link>
      <guid>https://forem.com/sukma_rizki__444/mastering-rate-limiting-in-golang-strategies-for-scalable-apis-286i</guid>
      <description>&lt;p&gt;In the rapidly growing landscape of microservices and global APIs, managing request volume is critical. Enter rate limiting—a technique every Golang developer should master to maintain performance, prevent abuse, and safeguard infrastructure.&lt;/p&gt;

&lt;p&gt;Why Rate Limiting Matters in 2025.&lt;/p&gt;

&lt;p&gt;As apps scale and edge deployments increase, controlling how often users or services access APIs has become foundational. Whether you're managing burst traffic from IoT devices or throttling spammy requests in a messaging queue, Golang offers elegant solutions to keep services responsive.&lt;/p&gt;

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

&lt;p&gt;Each strategy balances efficiency and control differently. For most real-world APIs, Sliding Window and Token Bucket offer a robust combination of flexibility and accuracy.&lt;/p&gt;

&lt;p&gt;implementation Tip, Redis-Powered Distributed Limiter&lt;br&gt;
Rate limiting across multiple servers? Use Redis for atomic counters and expiration windows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client.Eval(`
  local current = redis.call("INCR", KEYS[1])
  if current &amp;gt; tonumber(ARGV[1]) then return 0 end
  if current == 1 then redis.call("EXPIRE", KEYS[1], ARGV[2]) end
  return 1
`, []string{key}, limit, window)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach keeps things centralized and synchronized—perfect for microservice architectures.&lt;/p&gt;

&lt;p&gt;Best Practices&lt;br&gt;
Combine token-based limiting with IP behavior tracking to detect trolls.&lt;/p&gt;

&lt;p&gt;Use libraries like golang.org/x/time/rate for a clean API and solid performance.&lt;/p&gt;

&lt;p&gt;Monitor key metrics (latency, error rates) and tune limits as traffic evolves.&lt;/p&gt;

&lt;p&gt;Final Thoughts&lt;br&gt;
Rate limiting is no longer just a protective measure—it's a design tool for resilience and fairness. Whether you're building financial apps, chat platforms, or mobile APIs, these concepts are crucial.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>development</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Use of Defer and Close in go</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Wed, 16 Jul 2025 04:34:35 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/use-of-defer-and-close-in-go-35fa</link>
      <guid>https://forem.com/sukma_rizki__444/use-of-defer-and-close-in-go-35fa</guid>
      <description>&lt;p&gt;Defer is used to terminate the execution of a statement just before the function block is completed. While Exit is used to forcefully stop the program(remember, stopping the program, unlike return which only stops a block of code)&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation keyword defer
&lt;/h2&gt;

&lt;p&gt;As briefly explained above, defer is used to delay the execution of a line of code within the scope of a function block. When the execution of the block is almost complete, the deferred statement is executed. Defer can be placed anywhere, the beginning or the end of the block. But it does not affect when it is executed, it will always be executed at the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; package main
 import "fmt"
 func main() {
 defer fmt.Println("halo")
 }
    fmt.Println("selamat datang")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The keyword defer above will terminate the execution of in effect the message &lt;br&gt;
fmt.Println("hello"),&lt;br&gt;
"hello" will appear after &lt;br&gt;
"welcome".&lt;br&gt;
The deferred statement will still appear even if the code block is dismissed midway using return. For example, as in the following code.&lt;/p&gt;

</description>
      <category>go</category>
      <category>backend</category>
      <category>development</category>
      <category>developer</category>
    </item>
    <item>
      <title>Certified Cyber</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Wed, 04 Jun 2025 04:31:01 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/certified-cyber-5abo</link>
      <guid>https://forem.com/sukma_rizki__444/certified-cyber-5abo</guid>
      <description>&lt;p&gt;&lt;a href="https://pauljerimy.com/security-certification-roadmap/" rel="noopener noreferrer"&gt;https://pauljerimy.com/security-certification-roadmap/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>programming</category>
      <category>beginners</category>
      <category>alibabachallenge</category>
    </item>
    <item>
      <title>Main difference between struct and class.</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Sun, 04 May 2025 07:33:32 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/main-difference-between-struct-and-class-20kl</link>
      <guid>https://forem.com/sukma_rizki__444/main-difference-between-struct-and-class-20kl</guid>
      <description>&lt;p&gt;The main difference between structs and classes in Swift lies in the way they store and manage data (value type vs. reference type), as well as additional features that only classes have.&lt;/p&gt;

&lt;p&gt;Here are the main differences:&lt;br&gt;
1.Type: value Type vs Reference Type&lt;br&gt;
Comparison: swift &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data Storage
value type(independent copy)
Example: var a1 = b1 creates a new copy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;class &lt;br&gt;
Reference Type (Reference to the same object)&lt;br&gt;
var a1 = b1 (pointing to the same object )&lt;/p&gt;

&lt;p&gt;Example Value Type (struct):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Person {
    var name: String
}

var person1 = Person(name: "Andry")
var person2 = person1
person2.name = "Budi"

print(person1.name) // Andry
print(person2.name) // Budi

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example Reference Type (class):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person {
    var name: String
    init(name: String) {
        self.name = name
    }
}

var person1 = Person(name: "Andry")
var person2 = person1
person2.name = "Budi"

print(person1.name) // Budi
print(person2.name) // Budi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Inheritance &lt;br&gt;
struct : does not support inheritance &lt;br&gt;
class : support inheritance&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal {
    var name: String = "Unknown"
}

class Dog: Animal {
    var breed: String = "Bulldog"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.Deinitializers&lt;br&gt;
struct : no deinit.&lt;br&gt;
class : has deinit for cleanup when the object is removed from memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyClass {
    deinit {
        print("Object is being deallocated")
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Mutability (Data Changes)&lt;br&gt;
struct: requires the mutating keyword to change properties from within the method.&lt;br&gt;
class: bebas mengubah properti tanpa keyword tambahan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Counter {
    var count = 0

    mutating func increment() {
        count += 1
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're building a Swift/iOS app, most data models can simply use structs. But for UI components and complex logic with inheritance, classes are more appropriate.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
      <category>basic</category>
      <category>programming</category>
    </item>
    <item>
      <title>Observer Pattern</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Sat, 01 Feb 2025 09:01:58 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/observer-pattern-c7c</link>
      <guid>https://forem.com/sukma_rizki__444/observer-pattern-c7c</guid>
      <description>&lt;p&gt;The Observer Pattern is a behavioral design pattern that defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. This pattern is particularly useful for implementing distributed event-handling systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Purpose
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Establish a one-to-Many dependency between objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatically notify and update dependents when the state of the subjet changes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Structure
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Subject : Maintains a list of observers and provides methods to attach and detach observers.&lt;/li&gt;
&lt;li&gt;Observer : Defines an updating interfaces for objects that should be notified of changes in the subject&lt;/li&gt;
&lt;li&gt;Concrete Subject: Implements the subject interface and maintains state tha interest the observers.&lt;/li&gt;
&lt;li&gt;Concurete Observer : Implements the observer interface and keeps a reference to a concrete subject.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation in Dart or Flutter Framework
&lt;/h2&gt;

&lt;p&gt;Let create an Example:&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Observer Interface: NewsSubscriber defines an interface for updating objects.&lt;/li&gt;
&lt;li&gt;Subject: NewsPublisher maintains a list of subscribers and notifies them of any changes.&lt;/li&gt;
&lt;li&gt;Concrete Observer: ConcreteNewsSubscriber implements the observer interface and updates its state when notified.&lt;/li&gt;
&lt;li&gt;Client: The main function subscribes observers to the publisher and triggers notifications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Use Case
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Event Handling: When a change in one object requires others to be notified and updated.&lt;/li&gt;
&lt;li&gt;Data Binding: In GUI components where changes in the model should reflect in the view.&lt;/li&gt;
&lt;li&gt;Logging: When multiple logging objects need to be notified of an event.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Loose Coupling: Observers are loosely coupled to the subject, allowing for easier maintenance and scalability.&lt;/li&gt;
&lt;li&gt;Dynamic Relationships: Observers can be added or removed at runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Drawbacks
&lt;/h2&gt;

&lt;p&gt;Memory Leaks: If observers are not properly removed, it can lead to memory leaks.&lt;br&gt;
Unpredictable Behavior: Notifications can cause unpredictable behavior if not managed carefully.&lt;br&gt;
The Observer Pattern is quite powerful for creating systems where changes in one part need to be reflected in others. Let me know if you need more details or want to explore another design pattern!&lt;/p&gt;

&lt;p&gt;Stay Connected with Me!&lt;br&gt;
Hey there! If you’ve enjoyed my content, let’s stay connected across multiple platforms. Follow me to stay updated with the latest insights, tips, and discussions.&lt;/p&gt;

</description>
      <category>designpatterns</category>
      <category>flutter</category>
      <category>dart</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Builder Pattern-Pattern</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Sat, 01 Feb 2025 07:37:31 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/builder-pattern-pattern-e72</link>
      <guid>https://forem.com/sukma_rizki__444/builder-pattern-pattern-e72</guid>
      <description>&lt;p&gt;The Builder Pattern is a creational design pattern that allows for the step-by-step creation of complex objects. It separates the construction of an object from its representation, enabling the same construction process to create various representations.&lt;br&gt;
Purpose&lt;br&gt;
Construct a complex object step by step.&lt;br&gt;
Separate the construction process from the actual representation.&lt;br&gt;
Structure&lt;br&gt;
Builder Interface: Specifies the abstract steps for creating a product.&lt;br&gt;
Concrete Builder: Implements the builder interface to create specific parts of the product.&lt;br&gt;
Product: The complex object that is being built.&lt;br&gt;
Director: Controls the building process.&lt;br&gt;
Example: Custom Card Builder&lt;br&gt;
We’ll create a CustomCard widget using the Builder Pattern.&lt;/p&gt;

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

&lt;p&gt;Explanation&lt;br&gt;
Adaptee: SquarePeg is the existing class that we want to adapt.&lt;br&gt;
Target: RoundHole is the interface that SquarePeg needs to adapt to.&lt;br&gt;
Adapter: SquarePegAdapter converts the SquarePeg interface to RoundHole.&lt;br&gt;
Use Case&lt;br&gt;
In this example, we are adapting a SquarePeg to fit into a RoundHole using an adapter that converts the width of the square peg to the radius of the round hole. This allows us to determine if the square peg can fit into the round hole.&lt;/p&gt;

&lt;p&gt;The Adapter Pattern is quite helpful when you need to integrate classes that have incompatible interfaces but you want them to work together seamlessly.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>android</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Singleton Pattern</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Fri, 31 Jan 2025 08:42:36 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/singleton-pattern-3ii2</link>
      <guid>https://forem.com/sukma_rizki__444/singleton-pattern-3ii2</guid>
      <description>&lt;p&gt;1.Purpose&lt;br&gt;
The Singleton Pattern is a creational design pattern that ensures a class has only one instance and provides a global point of acces to that instance.it's commonly used managing shared resources like configuration settings, logging, or network connections.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Core Concepts&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Single Instance: The class ensures that only one instance of itself is created.&lt;/li&gt;
&lt;li&gt;Global Access: Provides a global access point to this instance, allowing it to be accessed from anywhere in the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Benefits &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Controlled Access : Ensures tha a class has only one instance, controlling acces to shared resources.&lt;/li&gt;
&lt;li&gt;Memory Efficiency: Reduces memory consumption by reusing the same instance.&lt;/li&gt;
&lt;li&gt;Global State : Maintains a global state that can be accessed from anywhere.
Let'go to Example Code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Define the Singleton Class
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Use The Singleton in App
&lt;/h2&gt;

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

&lt;p&gt;However, it’s important to use Singleton Pattern judiciously as overuse can lead to issues with testing and can cause hidden dependencies.&lt;/p&gt;

&lt;p&gt;You may provide additional references to make this writing more perfect.&lt;br&gt;
Enjoy the Coding. Enjoy the Process&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>mobile</category>
      <category>android</category>
    </item>
    <item>
      <title>Flutter Design Pattern Bussines Logic Component (BLOC)</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Sat, 11 Jan 2025 06:17:05 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/flutter-design-pattern-bussines-logic-component-bloc-bko</link>
      <guid>https://forem.com/sukma_rizki__444/flutter-design-pattern-bussines-logic-component-bloc-bko</guid>
      <description>&lt;p&gt;BLoC (Business Logic Component) Design Pattern&lt;br&gt;
Purpose: The BLoC (Business Logic Component) design pattern is used to separate business logic from the UI in Flutter applications, making the code more maintainable and testable. It utilizes streams to manage state and makes the app reactive.&lt;/p&gt;

&lt;p&gt;Core Concepts:&lt;/p&gt;

&lt;p&gt;Events: Inputs to the BLoC that represent actions or triggers, such as button clicks or user inputs.&lt;br&gt;
States: Outputs from the BLoC that represent the current state of the application or UI.&lt;br&gt;
Streams: Used to manage the flow of data. Events are added to a stream, processed by the BLoC, and result in new states emitted through another stream.&lt;br&gt;
Benefits:&lt;br&gt;
Separation of Concerns: Keeps business logic separate from UI code.&lt;br&gt;
Reusability: Business logic can be reused across different parts of the application.&lt;br&gt;
Testability: Business logic can be tested independently of the UI.&lt;br&gt;
Reactive Programming: Makes the app responsive and able to handle asynchronous data streams.&lt;br&gt;
Example Code:&lt;br&gt;
Let’s create a simple counter app using the BLoC pattern.&lt;/p&gt;

&lt;p&gt;Step 1: Define Events&lt;/p&gt;

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

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

&lt;p&gt;Step 3: Create the BLoC&lt;/p&gt;

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

&lt;p&gt;Step 4: Connect BLoC to UI&lt;/p&gt;

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

&lt;p&gt;This example demonstrates a simple counter application where the BLoC pattern is used to manage the state. The CounterBloc listens for Increment and Decrement events and updates the counter state accordingly. The UI subscribes to the state stream and updates the display when the state changes.&lt;/p&gt;

</description>
      <category>dart</category>
      <category>flutter</category>
      <category>mobile</category>
      <category>android</category>
    </item>
    <item>
      <title>Design Pattern in Flutter MVVM</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Wed, 08 Jan 2025 06:51:12 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/design-pattern-in-flutter-mvvm-4mkm</link>
      <guid>https://forem.com/sukma_rizki__444/design-pattern-in-flutter-mvvm-4mkm</guid>
      <description>&lt;p&gt;Purpose: The MVVM (Model-View-ViewModel) pattern is used to separate the UI (View) from the business logic and data (Model) in Flutter applications. This separation improves code maintainability, testability, and scalability.&lt;br&gt;
Core Concepts:&lt;/p&gt;

&lt;p&gt;Model: Represents the data and business logic.&lt;br&gt;
View: Displays the data and listens to user interactions.&lt;br&gt;
ViewModel: Acts as a mediator between the View and the Model. It handles the presentation logic and exposes data to the View.&lt;br&gt;
Benefits:&lt;br&gt;
Separation of Concerns: Keeps the UI code separate from the business logic.&lt;br&gt;
Testability: Makes it easier to test the business logic and UI separately.&lt;br&gt;
Maintainability: Simplifies the codebase and makes it easier to maintain.&lt;br&gt;
Example Code:&lt;br&gt;
Let’s create a simple counter app using the MVVM pattern.&lt;/p&gt;

&lt;p&gt;Step 1: Create the Model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// models/counter_model.dart
class CounterModel {
  int counter;

  CounterModel({this.counter = 0});
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Create the ViewModel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// viewmodels/counter_view_model.dart
import 'package:flutter/material.dart';
import '../models/counter_model.dart';

class CounterViewModel extends ChangeNotifier {
  CounterModel _counterModel = CounterModel();

  int get counter =&amp;gt; _counterModel.counter;

  void increment() {
    _counterModel.counter++;
    notifyListeners();
  }

  void decrement() {
    _counterModel.counter--;
    notifyListeners();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Provide the ViewModel&lt;br&gt;
Wrap your main app widget with a ChangeNotifierProvider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// main.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'viewmodels/counter_view_model.dart';
import 'views/counter_page.dart';

void main() {
  runApp(
    ChangeNotifierProvider(
      create: (context) =&amp;gt; CounterViewModel(),
      child: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: CounterPage(),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4: Create the View&lt;br&gt;
Use the Consumer widget to listen to changes and rebuild the UI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// views/counter_page.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../viewmodels/counter_view_model.dart';

class CounterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('MVVM Counter'),
      ),
      body: Center(
        child: Consumer&amp;lt;CounterViewModel&amp;gt;(
          builder: (context, counterViewModel, child) {
            return Text(
              'Counter: ${counterViewModel.counter}',
              style: TextStyle(fontSize: 24),
            );
          },
        ),
      ),
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          FloatingActionButton(
            onPressed: () =&amp;gt; context.read&amp;lt;CounterViewModel&amp;gt;().increment(),
            child: Icon(Icons.add),
          ),
          SizedBox(height: 8),
          FloatingActionButton(
            onPressed: () =&amp;gt; context.read&amp;lt;CounterViewModel&amp;gt;().decrement(),
            child: Icon(Icons.remove),
          ),
        ],
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the CounterModel class holds the data. The CounterViewModel class acts as a mediator between the model and the UI, handling the presentation logic. The CounterPage widget is the View, which uses the CounterViewModel to display and interact with the counter data.&lt;/p&gt;

&lt;p&gt;By using the MVVM pattern, we achieve a clean separation of concerns, making our code more maintainable and testable.&lt;/p&gt;

</description>
      <category>dart</category>
      <category>flutter</category>
      <category>mobile</category>
      <category>programming</category>
    </item>
    <item>
      <title>Interesting Control Flow in the circle</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Wed, 28 Aug 2024 16:46:41 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/interesting-control-flow-in-the-circle-bm</link>
      <guid>https://forem.com/sukma_rizki__444/interesting-control-flow-in-the-circle-bm</guid>
      <description>&lt;p&gt;in Go (Golang), control flow is managed using several fundamental constructs, including conditionals (if, else), loops (for), and switch statements. Here's an overview of how these constructs work in Go:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conditionals: if, else, else if
In Go, if statements are used to execute code based on a condition. Unlike some other languages, Go doesn't require parentheses around the condition. However, the curly braces {} are mandatory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Basic Statement&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    age := 20

    if age &amp;gt;= 18 {
        fmt.Println("You are an adult.")
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'if-else statement' Example&lt;br&gt;
`package main&lt;/p&gt;

&lt;p&gt;import "fmt"&lt;/p&gt;

&lt;p&gt;func main() {&lt;br&gt;
    age := 16&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if age &amp;gt;= 18 {
    fmt.Println("You are an adult.")
} else {
    fmt.Println("You are not an adult.")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;br&gt;
`&lt;br&gt;
'if-else if-else' Statement:&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    age := 20

    if age &amp;gt;= 21 {
        fmt.Println("You can drink alcohol.")
    } else if age &amp;gt;= 18 {
        fmt.Println("You are an adult, but cannot drink alcohol.")
    } else {
        fmt.Println("You are not an adult.")
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Loops: for &lt;br&gt;
Go uses the 'for' loop for all looping needs; it does not have a 'while' or loop&lt;br&gt;
basic 'for' loop:&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    for i := 0; i &amp;lt; 5; i++ {
        fmt.Println(i)
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'for' as a 'while' loop:&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    i := 0
    for i &amp;lt; 5 {
        fmt.Println(i)
        i++
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Infinite Loop:&lt;br&gt;
&lt;/p&gt;

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

func main() {
    for {
        // This loop will run forever
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'for' loop with 'range':&lt;br&gt;
This is often used to iterate over slices,arrays,maps or strings.&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    numbers := []int{1, 2, 3, 4, 5}

    for index, value := range numbers {
        fmt.Println("Index:", index, "Value:", value)
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Switch Statement Go 
The 'Switch' statement in Go is used to select one of many code blocks to be executed.Go 'switch'is more powerful than in some other languages and can be used with any type of value, not just integers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Basic 'switch'&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    day := "Monday"

    switch day {
    case "Monday":
        fmt.Println("Start of the work week.")
    case "Friday":
        fmt.Println("End of the work week.")
    default:
        fmt.Println("Midweek.")
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch with multiple expressions in a case:&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    day := "Saturday"

    switch day {
    case "Saturday", "Sunday":
        fmt.Println("Weekend!")
    default:
        fmt.Println("Weekday.")
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A switch with no expression acts like a chain of if-else statements.&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    age := 18

    switch {
    case age &amp;lt; 18:
        fmt.Println("Underage")
    case age &amp;gt;= 18 &amp;amp;&amp;amp; age &amp;lt; 21:
        fmt.Println("Young adult")
    default:
        fmt.Println("Adult")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Defer, panic and recover
&lt;/li&gt;
&lt;/ol&gt;

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

import "fmt"

func main() {
    defer fmt.Println("This is deferred and will run at the end.")
    fmt.Println("This will run first.")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Panic And Recover&lt;br&gt;
&lt;/p&gt;

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

import "fmt"

func main() {
    defer func() {
        if r := recover(); r != nil {
            fmt.Println("Recovered from panic:", r)
        }
    }()

    fmt.Println("About to panic!")
    panic("Something went wrong.")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
      <category>google</category>
      <category>backend</category>
      <category>backenddevelopment</category>
    </item>
    <item>
      <title>Query a database Using Go</title>
      <dc:creator>Sukma Rizki</dc:creator>
      <pubDate>Thu, 15 Aug 2024 17:30:22 +0000</pubDate>
      <link>https://forem.com/sukma_rizki__444/query-a-database-using-go-5f41</link>
      <guid>https://forem.com/sukma_rizki__444/query-a-database-using-go-5f41</guid>
      <description>&lt;p&gt;Step 1: Install the MySQL driver&lt;br&gt;
First, you'll need to install a MySQL driver for Go. A popular one is go-sql-driver/mysql. You can install it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go get -u github.com/go-sql-driver/mysql

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Write the Go code&lt;br&gt;
Here’s an example of how you can connect to a MySQL database and query data:&lt;br&gt;
&lt;/p&gt;

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

import (
    "database/sql"
    "fmt"
    "log"

    _ "github.com/go-sql-driver/mysql"
)

func main() {
    // Open the database connection
    db, err := sql.Open("mysql", "username:password@tcp(127.0.0.1:3306)/dbname")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    // Ping the database to check if the connection is alive
    if err := db.Ping(); err != nil {
        log.Fatal(err)
    }

    // Define the query
    query := "SELECT id, name FROM users WHERE active = ?"
    active := true

    // Execute the query
    rows, err := db.Query(query, active)
    if err != nil {
        log.Fatal(err)
    }
    defer rows.Close()

    // Iterate through the result set
    for rows.Next() {
        var id int
        var name string
        if err := rows.Scan(&amp;amp;id, &amp;amp;name); err != nil {
            log.Fatal(err)
        }
        fmt.Printf("ID: %d, Name: %s\n", id, name)
    }

    // Check for errors from iterating over rows
    if err := rows.Err(); err != nil {
        log.Fatal(err)
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
Import necessary packages: You import the database/sql package for database interactions and the MySQL driver (github.com/go-sql-driver/mysql).&lt;/p&gt;

&lt;p&gt;Open the database connection: You open a connection to the database using sql.Open. The connection string format is username:password@tcp(host:port)/dbname.&lt;/p&gt;

&lt;p&gt;Ping the database: It’s a good practice to ping the database to ensure that the connection is established.&lt;/p&gt;

&lt;p&gt;Execute the query: You execute a query using db.Query. The Query method returns a *sql.Rows object, which you can iterate over to get the result set.&lt;/p&gt;

&lt;p&gt;Iterate through the results: You use a loop to iterate through the rows and Scan each row into variables.&lt;/p&gt;

&lt;p&gt;Handle errors: You should handle any errors that occur during the execution of the query or during iteration.&lt;/p&gt;

&lt;p&gt;Step 3: Run your code&lt;br&gt;
Make sure to replace username, password, 127.0.0.1:3306, and dbname with your actual MySQL credentials and database details.&lt;/p&gt;

&lt;p&gt;Run your Go program, and it should output the results of your query.&lt;/p&gt;

&lt;p&gt;This example can be adapted for other databases by changing the driver and connection string accordingly.&lt;/p&gt;

</description>
      <category>go</category>
      <category>backend</category>
      <category>development</category>
    </item>
  </channel>
</rss>
