<?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: George O. E. Campbell</title>
    <description>The latest articles on Forem by George O. E. Campbell (@campbellgoe).</description>
    <link>https://forem.com/campbellgoe</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%2F88424%2Fd4003d6d-9789-4f15-931a-2331283e11af.png</url>
      <title>Forem: George O. E. Campbell</title>
      <link>https://forem.com/campbellgoe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/campbellgoe"/>
    <language>en</language>
    <item>
      <title>Refactoring 101</title>
      <dc:creator>George O. E. Campbell</dc:creator>
      <pubDate>Wed, 14 Aug 2024 02:50:02 +0000</pubDate>
      <link>https://forem.com/campbellgoe/refactoring-101-4i7c</link>
      <guid>https://forem.com/campbellgoe/refactoring-101-4i7c</guid>
      <description>&lt;h4&gt;
  
  
  What is Refactoring?
&lt;/h4&gt;

&lt;p&gt;Refactoring is the process of restructuring existing code without changing its external behavior. The goal of refactoring is to improve the internal structure of the code, making it cleaner, more readable, and easier to maintain. This process often involves simplifying complex sections, reducing redundancy, and ensuring the code adheres to best practices like DRY (Don't Repeat Yourself) and modularity.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key aspects of refactoring include:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Simplification: Breaking down complex code into smaller, more manageable pieces.&lt;/li&gt;
&lt;li&gt;Modularity: Extracting code into independent modules or functions that can be reused across the application.&lt;/li&gt;
&lt;li&gt;Readability: Improving the clarity of the code, making it easier for developers to understand and modify in the future.&lt;/li&gt;
&lt;li&gt;Why Do Good Engineers Continuously Refactor Code?
Refactoring is a critical practice for maintaining a healthy codebase. Here’s why good engineers make it a continuous effort:&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Code is Dynamic:
&lt;/h4&gt;

&lt;p&gt;Code isn't just about what it outputs or displays; it's also about how easily it can be understood, modified, and extended by developers. As the codebase evolves, refactoring helps keep the structure in line with the current understanding and needs of the project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enhanced Productivity:
&lt;/h4&gt;

&lt;p&gt;Clean, well-organized code is easier to navigate and understand. When developers can quickly comprehend the code, they can implement new features or fix bugs more efficiently. Refactoring reduces the cognitive load on developers, allowing them to focus on solving new problems rather than deciphering tangled code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Managing Technical Debt:
&lt;/h4&gt;

&lt;p&gt;Technical debt accumulates when shortcuts are taken in the codebase to meet deadlines or when quick fixes are applied without consideration of long-term consequences. If left unchecked, technical debt can slow down development and introduce bugs. Continuous refactoring is a proactive way to manage and reduce technical debt by keeping the codebase clean and up-to-date.&lt;/p&gt;

&lt;h4&gt;
  
  
  Facilitating Testing:
&lt;/h4&gt;

&lt;p&gt;Well-refactored code is often easier to test, both manually and through automated testing frameworks. Modular code allows for better isolation of components, making unit testing more straightforward. By refactoring continuously, you ensure that the code remains testable, reducing the risk of introducing bugs when new features are added.&lt;/p&gt;

&lt;h4&gt;
  
  
  Future-Proofing the Codebase:
&lt;/h4&gt;

&lt;p&gt;As projects grow, requirements change, and new technologies emerge, codebases need to adapt. Regular refactoring helps ensure that the code remains flexible and can accommodate future changes without significant rewrites. This adaptability is crucial for long-term project success.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Refactoring is an essential practice for maintaining high-quality code. It ensures that the codebase remains clean, modular, and easy to work with, allowing developers to be more productive and reducing the accumulation of technical debt. Good engineers understand that refactoring is not just a one-time task but a continuous process that accompanies the entire development lifecycle. By making refactoring a habit, teams can create more sustainable and maintainable codebases that stand the test of time.&lt;/p&gt;

</description>
      <category>refactoring</category>
      <category>engineering</category>
      <category>development</category>
    </item>
    <item>
      <title>Websocket starter in Rust with client and server example</title>
      <dc:creator>George O. E. Campbell</dc:creator>
      <pubDate>Tue, 30 Jul 2024 21:46:02 +0000</pubDate>
      <link>https://forem.com/campbellgoe/websocket-starter-in-rust-with-client-and-server-example-4ahj</link>
      <guid>https://forem.com/campbellgoe/websocket-starter-in-rust-with-client-and-server-example-4ahj</guid>
      <description>&lt;h2&gt;
  
  
  Server code for websockets
&lt;/h2&gt;

&lt;p&gt;(server): &lt;a href="https://github.com/campbellgoe/rust_websocket_server" rel="noopener noreferrer"&gt;https://github.com/campbellgoe/rust_websocket_server&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;tokio&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;net&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;TcpListener&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;tokio_tungstenite&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;accept_async&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;tokio_tungstenite&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;tungstenite&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;anyhow&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;futures_util&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;SinkExt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;StreamExt&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nd"&gt;#[tokio::main]&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"127.0.0.1:8080"&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;TcpListener&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"WebSocket server started on ws://{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="nf"&gt;.accept&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nn"&gt;tokio&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;spawn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;handle_connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;handle_connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;tokio&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;net&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;TcpStream&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;ws_stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;accept_async&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"WebSocket connection established"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ws_stream&lt;/span&gt;&lt;span class="nf"&gt;.next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="nf"&gt;.is_text&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;received_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="nf"&gt;.to_text&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="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received message: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;received_text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;ws_stream&lt;/span&gt;&lt;span class="nf"&gt;.send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;received_text&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&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;Cargo.toml (server):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[dependencies]&lt;/span&gt;
&lt;span class="py"&gt;tokio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"1.12"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="py"&gt;features&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"full"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="py"&gt;tokio-stream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.1"&lt;/span&gt;
&lt;span class="py"&gt;tokio-tungstenite&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.23.1"&lt;/span&gt;
&lt;span class="py"&gt;anyhow&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"1.0"&lt;/span&gt;
&lt;span class="py"&gt;futures-util&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.3"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Client websocket code
&lt;/h2&gt;

&lt;p&gt;(client): &lt;a href="https://github.com/campbellgoe/rust_websocket_client" rel="noopener noreferrer"&gt;https://github.com/campbellgoe/rust_websocket_client&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;tokio_tungstenite&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;connect_async&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;tokio_tungstenite&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;tungstenite&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;anyhow&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;futures_util&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;SinkExt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;StreamExt&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;url&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Url&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[tokio::main]&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Url&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ws://127.0.0.1:8080"&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="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;ws_stream&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;connect_async&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="nf"&gt;.as_str&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed to connect"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"WebSocket client connected"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Sending a message to the server&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, Server!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;ws_stream&lt;/span&gt;&lt;span class="nf"&gt;.send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="nf"&gt;.into&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Receiving messages from the server&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ws_stream&lt;/span&gt;&lt;span class="nf"&gt;.next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nn"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received message from server: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&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;client Cargo.toml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[dependencies]&lt;/span&gt;
&lt;span class="py"&gt;tokio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"1.12"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="py"&gt;features&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"full"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="py"&gt;tokio-stream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.1"&lt;/span&gt;
&lt;span class="py"&gt;tokio-tungstenite&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.23.1"&lt;/span&gt;
&lt;span class="py"&gt;url&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"2"&lt;/span&gt;
&lt;span class="py"&gt;anyhow&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"1.0"&lt;/span&gt;
&lt;span class="py"&gt;futures-util&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.3"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could use this as a starting point for your Rust websocket project.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>websocket</category>
      <category>server</category>
      <category>client</category>
    </item>
    <item>
      <title>26 communication tips to advance your career in software</title>
      <dc:creator>George O. E. Campbell</dc:creator>
      <pubDate>Thu, 25 Jan 2024 09:38:00 +0000</pubDate>
      <link>https://forem.com/campbellgoe/26-communication-tips-to-advance-your-career-in-software-3j73</link>
      <guid>https://forem.com/campbellgoe/26-communication-tips-to-advance-your-career-in-software-3j73</guid>
      <description>&lt;h2&gt;
  
  
  You want to advance your career, maybe you're looking for your first job in software, or you're a seasoned professional but you want to get a promotion - one way you could improve yourself is by developing your communication skills, a set of soft skills you can use to improve your career trajectory whilst benefiting you and the people around you.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Understand the Importance of Communication:&lt;/strong&gt; The first step is to understand how important communication is in a team environment. &lt;a href="https://www.inc.com/kaleigh-moore/study-73-of-employers-want-candidates-with-this-skill.html"&gt;A study&lt;/a&gt; found that 73.4% of employers want to find people with strong written communication skills. Developers, designers and other team members must be able to effectively communicate their ideas and feedback to one another, as well as work collaboratively on projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn Active Listening:&lt;/strong&gt; Active listening is an essential skill for effective communication. It involves fully concentrating on what is being said rather than just passively hearing the message. This can be practiced by paying close attention to the speaker, not interrupting, and providing feedback to show that you understand what they are saying.&lt;/p&gt;

&lt;p&gt;Active listening involves fully concentrating, understanding, responding, and then remembering what is being said. This skill helps in understanding tasks better, avoids misunderstandings, and shows your colleagues and superiors that you value their input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Master Written Communication:&lt;/strong&gt; In many jobs, you’ll need to write clearly and persuasively. Good writing skills ensure your ideas are conveyed effectively.&lt;/p&gt;

&lt;p&gt;When writing for technical audiences, it's crucial to employ specific language and jargon pertinent to the field, showcasing an understanding of complex concepts. Technical writing should be detail-oriented, providing in-depth explanations and data to support statements. It's important to organize content logically, using examples, diagrams, and evidence for practical demonstration. Focus on the functionality and accuracy of information, ensuring a clear, coherent structure without superfluous details, maintaining brevity and clarity throughout.&lt;/p&gt;

&lt;p&gt;For non-technical audiences, the key is to simplify complex concepts into more understandable terms, avoiding or explaining industry jargon. The content should highlight the relevance of information to the reader's daily life, using a friendly and conversational tone to make it more engaging and relatable. Employing analogies and metaphors can be especially effective in making technical subjects accessible, helping to convey intricate ideas in simpler, more familiar terms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ask questions one at a time:&lt;/strong&gt; When communicating with colleagues, if you have questions, I suggest asking them one at a time, instead of asking several questions at the same time. This makes the flow of the conversation better and you will more likely get an answer to each of your questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clarity and Conciseness:&lt;/strong&gt; Whether speaking or writing, conveying your message as clearly and as succinctly as possible is crucial. Avoid using unnecessary jargon or complex language. Clear and concise messages are more likely to be understood and remembered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn a little more about the other side:&lt;/strong&gt; If you're a developer, learn about design. If you are a designer, learn a about development. Understanding design thinking can help developers communicate better with designers and similarly designers can more easily communicate their designs if they understand the technical side a little more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuous Learning:&lt;/strong&gt; Communication is a skill that requires continuous learning and practice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice Public Speaking:&lt;/strong&gt; Many teams have meetings where members present their work or discuss ideas. Learning how to give effective presentations can be a valuable skill in these situations. This includes learning how to structure your presentation, use visual aids effectively, and handle questions or challenges from the audience.&lt;/p&gt;

&lt;p&gt;Whether you're giving a formal presentation or speaking in a meeting, being able to communicate your ideas effectively in front of an audience is a valuable skill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Give and Get Feedback:&lt;/strong&gt; Ask for feedback from your team members or supervisors about how you're doing with your communication skills. This can help you identify areas where you need improvement and make adjustments. Both giving and receiving feedback are important. Constructive feedback helps improve work processes and personal performance. When receiving feedback, it’s important to listen actively and respond reasonably.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remember Empathy:&lt;/strong&gt; Understanding and sharing the feelings of others is vital in the workplace. Empathy helps you to address concerns and conflicts in a manner that respects others' feelings and can lead to more effective and harmonious working relationships.&lt;/p&gt;

&lt;p&gt;In software development, it's important to remember that everyone has different perspectives and ways of working. By trying to understand where others are coming from and being empathetic, you can foster a more collaborative and productive team environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  Some other things to keep in mind that could be helpful to think about
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Non-Verbal Communication:&lt;/strong&gt; Your body language, eye contact, hand gestures, and tone all color the message you are trying to convey. A relaxed, open stance and a friendly tone makes your communication more effective. This still applies when on video calls. Stay professional at all times, although a good laugh with your colleagues can be helpful for team building.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adaptability:&lt;/strong&gt; Different situations require different styles of communication. Being able to adapt your communication style to the situation and the audience is an important skill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conflict Resolution:&lt;/strong&gt; Disagreements and conflicts are inevitable in any workplace. Being able to handle these situations diplomatically is crucial. It involves understanding different perspectives, finding common ground, and negotiating solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cultural Awareness:&lt;/strong&gt; In today's globalized work environment, understanding and respecting cultural differences in communication is vital. This includes understanding verbal and non-verbal norms in different cultures.&lt;/p&gt;




&lt;h2&gt;
  
  
  Here are some more practical steps you can take that I'll leave you with
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Collaborate on Projects:&lt;/strong&gt; One of the best ways to learn team communication skills is by working on projects with others. This can be done through pair programming (working on code with another developer), participating in coding challenges or hackathons, or contributing to open-source projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Join a Community:&lt;/strong&gt; There are many online communities where developers and designers share ideas and work together on projects. Joining one of these can provide opportunities to practice communication skills in a supportive environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Participate in Coding Workshops and Hackathons:&lt;/strong&gt; These events often require teamwork and collaboration, offering a great environment to practice communicating technical ideas, receiving feedback, and working towards a common goal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contribute to Open Source Projects:&lt;/strong&gt;&lt;br&gt;
Engaging in open source projects can expose learners to collaborative software development. They’ll learn to communicate through issue trackers, pull requests, and code reviews, which are essential aspects of team-based software development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Join Online Programming Communities:&lt;/strong&gt;&lt;br&gt;
Platforms like GitHub, Stack Overflow, or Reddit's programming forums allow learners to interact with other developers, ask questions, share knowledge, and get feedback, all of which require clear communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice Pair Programming:&lt;/strong&gt;&lt;br&gt;
Pair programming involves two programmers working together at one workstation. It’s an effective way to learn from others and improve communication skills, as it requires constant verbal interaction and clear explanation of thought processes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engage in Team Projects in Learning Environments:&lt;/strong&gt;&lt;br&gt;
Many coding bootcamps and online courses offer team-based projects. These are invaluable for practicing how to communicate technical problems and solutions effectively within a team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take Courses in Communication:&lt;/strong&gt;&lt;br&gt;
Enrolling in courses or workshops focusing on communication skills can be highly beneficial. Look for courses that cover topics like active listening, effective speaking, and technical writing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn from Mentors and Peers:&lt;/strong&gt;&lt;br&gt;
Seeking mentorship from experienced developers can provide insights into effective communication within a team. Regular interactions with mentors and peers can help in understanding the nuances of technical communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice Technical Writing:&lt;/strong&gt;&lt;br&gt;
Writing blogs or articles about programming concepts not only consolidates learning but also improves the ability to explain complex technical ideas in writing, a key skill in team communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attend Tech Meetups and Conferences:&lt;/strong&gt;&lt;br&gt;
These gatherings are great opportunities to network with other professionals, practice public speaking, and learn how others communicate technical ideas effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simulate Real-World Scenarios:&lt;/strong&gt;&lt;br&gt;
Create or participate in simulations of real-world scenarios like sprint planning, stand-ups, or design meetings. These exercises can familiarize learners with the communication dynamics of software development teams.&lt;/p&gt;




&lt;p&gt;In conclusion, improving your communication skills is crucial for success in software development. By understanding the importance of effective communication, learning active listening, mastering written and public speaking, collaborating with others, and continuously learning and adapting, you can enhance your ability to work effectively in teams of developers and designers.&lt;br&gt;
Remember to always be empathetic, show respect, and maintain a positive attitude towards others. With these strategies, you will not only improve your communication skills but also significantly boost your career prospects in the competitive world of software development&lt;/p&gt;




&lt;p&gt;I'm planning on releasing more technical articles and tutorials for people learning web development in particular so consider following me.&lt;/p&gt;

&lt;p&gt;Thanks for reading my article.&lt;/p&gt;

</description>
      <category>communication</category>
      <category>career</category>
      <category>softskills</category>
      <category>software</category>
    </item>
    <item>
      <title>Enhancing Your Creative Process with ChatGPT and Dolphin Ollama: A Guide to Maintaining Originality</title>
      <dc:creator>George O. E. Campbell</dc:creator>
      <pubDate>Wed, 27 Dec 2023 09:06:27 +0000</pubDate>
      <link>https://forem.com/campbellgoe/enhancing-your-creative-process-with-chatgpt-and-dolphin-mixtral-a-guide-to-maintaining-originality-24ab</link>
      <guid>https://forem.com/campbellgoe/enhancing-your-creative-process-with-chatgpt-and-dolphin-mixtral-a-guide-to-maintaining-originality-24ab</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcyyqqld4y6udx1knbuob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcyyqqld4y6udx1knbuob.png" alt="AI brain" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  To effectively utilize Chat GPT and Dolphin Mixtral, start by creating content with your original ideas, and then use these tools for feedback and iterative improvement. This approach ensures your work maintains your unique voice and perspective, essential for authenticity.
&lt;/h2&gt;

&lt;p&gt;Both ChatGPT and Dolphin Mixtral are valuable in generating quality content, but relying solely on them can lead to a lack of personal perspective and potential inaccuracies. Therefore, it's crucial to verify facts and rework AI-generated content with correct information, especially in critical fields like health and finance.&lt;/p&gt;

&lt;p&gt;By balancing the use of AI for technical support with your creativity and insight, your content will not only resonate with your audience but also stand out from AI-generated material. Incorporate feedback to refine your work, using AI tools to explore different versions or perspectives.&lt;/p&gt;

&lt;p&gt;In summary, leveraging ChatGPT and Dolphin Mixtral as aids rather than primary creators allows you to maintain the authenticity and individuality of your content. This strategy harnesses AI's efficiency and capabilities while ensuring that your personal touch is evident in every piece you create.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>dolphinollama</category>
      <category>contentcreation</category>
      <category>writingtips</category>
    </item>
    <item>
      <title>When to use redux state vs internal component state</title>
      <dc:creator>George O. E. Campbell</dc:creator>
      <pubDate>Mon, 06 Apr 2020 13:10:34 +0000</pubDate>
      <link>https://forem.com/campbellgoe/when-to-use-redux-state-vs-internal-component-state-i1g</link>
      <guid>https://forem.com/campbellgoe/when-to-use-redux-state-vs-internal-component-state-i1g</guid>
      <description>&lt;h2&gt;
  
  
  In the realm of React development, state management is a critical component that can define the architecture and performance of an application. While there are various state management systems like Zustand or React Context, this article focuses on Redux and the useState React hook due to it's widespread use.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Overhead of Redux&lt;/strong&gt;&lt;br&gt;
Redux is a powerful state management tool, but it comes with an overhead. The time invested in creating and maintaining actions, reducers, selectors, and dispatchers can be significant. This leads many developers to initially lean towards using useState or this.setState for managing state within a component. The simplicity of these hooks is appealing, especially when dealing with straightforward state logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deciding Early: Redux or Internal State?&lt;/strong&gt;&lt;br&gt;
Speed in development is crucial, but so is foresight. Making an early decision on whether to use Redux or internal component state can streamline your development process. Consider the following factors:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shared State Across Components:&lt;/strong&gt; If the state of your component is likely to be used across different parts of your application, Redux is a suitable choice. For instance, a 'dark mode/theme' setting in a &lt;code&gt;&amp;lt;UserSettings/&amp;gt;&lt;/code&gt; component should be accessible across all UI components. Using Redux, you can easily maintain consistency and avoid prop drilling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Component-Specific State:&lt;/strong&gt; For states that are confined to a single component, useState offers a quick and efficient solution. For example, managing the state of an  for image uploads can be effectively handled with useState.&lt;/p&gt;

&lt;p&gt;Here, useState provides a straightforward way to manage the file URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fileUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFileUrl&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// render the file input and image&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;
    &lt;span class="na"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"image/*"&lt;/span&gt;
    &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
      &lt;span class="nf"&gt;setFileUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
    &lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;fileUrl&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Weighing the Trade-Offs&lt;/strong&gt;&lt;br&gt;
While useState allows for rapid development and proof of concept, Redux ensures a scalable solution for complex state management. It's crucial to assess each component's needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Will the component's data be required elsewhere in the app?&lt;/li&gt;
&lt;li&gt;Is a quick proof of concept with internal state beneficial before transitioning to Redux?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Analogy: Bicycle vs. Car&lt;/strong&gt;&lt;br&gt;
Think of useState as a bicycle and Redux as a car. The bicycle (useState) is quick and efficient for short distances, just like managing simple state within a component. The car (Redux), though more complex, is essential for longer journeys, akin to managing shared state across an application.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Assess Data Usage&lt;/strong&gt;: Before building a new component, consider where and how its data will be used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Balance Simplicity and Scalability&lt;/strong&gt;: Weigh the benefits of a quick implementation with useState against the scalability and shared state management of Redux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid Overhead&lt;/strong&gt;: Don't default to Redux for every component; use it judiciously to avoid unnecessary complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debugging Simplicity&lt;/strong&gt;: Internal state is often easier to debug due to its confined nature within a component.&lt;/p&gt;

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

&lt;p&gt;Choosing between Redux and internal component state is a decision that impacts both the development process and the application's architecture. By understanding the specific needs of each component and considering the overall structure of your application, you can make informed decisions that balance development efficiency with scalable, maintainable code.&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering Error Handling in JavaScript: Beyond Console Logs</title>
      <dc:creator>George O. E. Campbell</dc:creator>
      <pubDate>Wed, 25 Mar 2020 18:11:39 +0000</pubDate>
      <link>https://forem.com/campbellgoe/how-to-handle-errors-3kob</link>
      <guid>https://forem.com/campbellgoe/how-to-handle-errors-3kob</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fngbosfvlnpdj4hi3iyfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fngbosfvlnpdj4hi3iyfj.png" alt="Random code" width="627" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In coding, it's tempting to quickly log errors to the console and move on. However, this approach often falls short in production environments.&lt;/p&gt;

&lt;p&gt;As your program grows, your console will start filling up with a messy set of messages hinting at what's wrong and your code will be full of console logs, warns and errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;//handle divide by zero case&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cannot divide by 0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;b&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;This might feel sufficient, but would you really write this for a production application?&lt;/p&gt;

&lt;p&gt;The first improvement would be to take advantage of JavaScript's built in error support using Error objects, to give your console messages a lot more useful information.&lt;/p&gt;

&lt;p&gt;Let's create a more practical example that demonstrates error handling in a simple web application scenario. We will create a function that fetches user data from an API and processes it. This example will show both synchronous and asynchronous error handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Synchronous Error Handling:&lt;/strong&gt;&lt;br&gt;
We'll start by defining a function to process user data. This function will throw an error if the data is not in the expected format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid user data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// Process user data (e.g., extract and format user details)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Processed data for &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Asynchronous Error Handling with async/await:&lt;/strong&gt;&lt;br&gt;
Next, we incorporate an asynchronous function that fetches user data from an API. We use async/await for clean and readable asynchronous code, and try-catch to handle errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchAndProcessUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`https://api.example.com/users/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`An error occurred: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusText&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error fetching user data:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle the fetch error (e.g., show a user-friendly message)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;processedData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;processUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;processedData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Further actions (e.g., display the data in the UI)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error processing user data:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle the processing error&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Synchronous Error Handling:&lt;/strong&gt; The &lt;code&gt;processUserData&lt;/code&gt; function validates the input and throws an error if the data is invalid. This is an example of a synchronous operation where errors can occur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous Error Handling:&lt;/strong&gt; The &lt;code&gt;fetchAndProcessUserData&lt;/code&gt; function demonstrates handling errors in an asynchronous context. It fetches user data from an API. If the fetch operation fails or the server returns an error response, it catches the error and logs it. After fetching, it attempts to process the data using the &lt;code&gt;processUserData&lt;/code&gt; function. If an error occurs during processing, it catches and handles that error separately.&lt;/p&gt;

&lt;p&gt;Effective error handling in JavaScript is akin to building a robust safety net for your application. By implementing strategic error throwing in smaller, self-contained functions—the fundamental building blocks of your code—you lay the groundwork for cleaner and more reliable error management. Catching these errors at a higher level, where your functions interconnect to form the application's logic, not only streamlines the process but also clarifies the distinction between different types of errors.&lt;/p&gt;

&lt;p&gt;When errors are a result of logical flaws in your code, using specialized Error objects is invaluable. These objects provide detailed stack traces, turning the daunting task of debugging into a more manageable one. This approach allows you to pinpoint the exact location and nature of code issues swiftly, significantly reducing the time and effort needed for troubleshooting.&lt;/p&gt;

&lt;p&gt;Conversely, for errors stemming from user input, your strategy shifts towards user communication. Here, the focus is on delivering clear, non-technical error messages or UI indicators that inform users of the issue without overwhelming them. This not only enhances the user experience but also encourages correct input practices.&lt;/p&gt;

&lt;p&gt;In essence, mastering error handling in JavaScript is about striking the right balance between technical precision and user-centric communication. It's about ensuring that your application not only runs smoothly but also communicates effectively with its users during unexpected situations. Embracing these practices will not only improve the quality of your code but also elevate the overall experience for both developers and users alike.&lt;/p&gt;

&lt;p&gt;By adopting these strategies, you equip your application to handle the unexpected with grace and efficiency, making it more robust, user-friendly, and maintainable.&lt;/p&gt;

</description>
      <category>errors</category>
      <category>console</category>
      <category>logging</category>
      <category>catch</category>
    </item>
  </channel>
</rss>
