<?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: Lewis Clarke</title>
    <description>The latest articles on Forem by Lewis Clarke (@nerkmind).</description>
    <link>https://forem.com/nerkmind</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%2F106826%2F6a8af838-1372-4303-a257-21d12eb81114.png</url>
      <title>Forem: Lewis Clarke</title>
      <link>https://forem.com/nerkmind</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nerkmind"/>
    <language>en</language>
    <item>
      <title>When Granularity in React Goes Wrong: A Cautionary Tale</title>
      <dc:creator>Lewis Clarke</dc:creator>
      <pubDate>Tue, 02 May 2023 13:43:41 +0000</pubDate>
      <link>https://forem.com/nerkmind/when-granularity-in-react-goes-wrong-a-cautionary-tale-fm6</link>
      <guid>https://forem.com/nerkmind/when-granularity-in-react-goes-wrong-a-cautionary-tale-fm6</guid>
      <description>&lt;p&gt;React developers love to talk about the importance of creating granular, reusable components, and I get it. It's a very useful practice! But what happens when you take it too far? In this article, we'll explore the dark side of granular components and the pitfalls that can arise when you break everything down into the smallest possible pieces.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Danger of Over-Engineering
&lt;/h2&gt;

&lt;p&gt;Picture this: you're working on a React project, and you've just created a component to display a user's profile. But wait, why stop there? Why not break it down into three separate components—one for the profile picture, one for the name, and one for the bio? Sounds great, right? Well, not necessarily. Creating too many small, single-purpose components can lead to over-engineering, where you end up with a bunch of unnecessary abstractions that just add complexity to your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Curse of Complexity
&lt;/h2&gt;

&lt;p&gt;Another problem with being too granular is that it can lead to increased complexity. Sure, having a lot of small components might make sense in theory, but it can quickly become overwhelming in practice. With dozens of files to manage, it's easy to lose track of how everything fits together. It's like trying to find Waldo in a sea of tiny, almost-identical components—except instead of finding a red and white shirt, you're trying to debug a specific issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Context is King
&lt;/h2&gt;

&lt;p&gt;So, what's the solution? Do we abandon granular components altogether? Not necessarily. Instead, it's important to focus on context and hierarchy. Rather than breaking everything down into the smallest possible pieces, think about how each component fits into the larger architecture of your application. This can help you avoid unnecessary complexity and ensure that your code is maintainable over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what am I saying
&lt;/h2&gt;

&lt;p&gt;At the end of the day, there's nothing inherently wrong with granular components, in fact it's actually a very good practice in the correct time and place. But it's important to remember that more isn't always better. By focusing on context and hierarchy, you can avoid the pitfalls of over-engineering and complexity, and build applications that are both modular and maintainable. And if all else fails, just remember: sometimes it's better to be a little bit coarse than too fine-grained.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>overengineer</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why Typescript is our god now.</title>
      <dc:creator>Lewis Clarke</dc:creator>
      <pubDate>Sat, 29 Apr 2023 15:25:03 +0000</pubDate>
      <link>https://forem.com/nerkmind/why-typescript-is-our-god-now-2m5p</link>
      <guid>https://forem.com/nerkmind/why-typescript-is-our-god-now-2m5p</guid>
      <description>&lt;h2&gt;
  
  
  Using TypeScript for better code quality and maintainability in applications
&lt;/h2&gt;

&lt;p&gt;What sounds like a very fancy idea, is actually something quite simple!&lt;br&gt;
If you're working on a Javascript project, you know that maintaining a large codebase can be...challenging. &lt;br&gt;
There's methods and Objects everywhere, that are ever expanding with no real set "shape", maybe you have an object so large, you couldn't possibly memorise all of its properties, wouldn't it be nice to just type &lt;code&gt;myObject.x&lt;/code&gt; and get a whole list of methods and properties? &lt;br&gt;
That's one of the ways , Typescript , a superset of JavaScript can make your life easier. It also adds static typing and many other useful features to the language. In this article, we'll discuss how TypeScript can help improve code quality and maintainability in a Node.js application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of TypeScript in Node.js applications
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Catching errors at compile-time
&lt;/h3&gt;

&lt;p&gt;One of the main benefits of TypeScript is that it catches errors at compile-time, before your code even runs. This can help prevent bugs from being introduced into your codebase and make it easier to maintain. For example, if you try to assign a string to a variable that is supposed to be a number, TypeScript will give you a compile-time error.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improved code maintainability
&lt;/h3&gt;

&lt;p&gt;TypeScript also makes it easier to maintain large codebases. By adding types to your code, you can make it easier to understand what each function and variable is supposed to do. This can help make your code more self-documenting and reduce the amount of time it takes to understand and modify it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Better tooling support
&lt;/h3&gt;

&lt;p&gt;TypeScript also has better tooling support than plain JavaScript. Many editors and IDEs support TypeScript out of the box, providing features like code completion and error highlighting. Additionally, TypeScript integrates well with popular build tools like webpack and babel, making it easy to set up a build process for your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use TypeScript in a Node.js project
&lt;/h2&gt;

&lt;p&gt;Using TypeScript in a Node.js project is easy. Here are the steps you need to follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Install TypeScript&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To start using TypeScript in your Node.js project, you first need to install it. You can do this using npm (or yarn if you like that kind of thing), a  package manager, by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save-dev typescript&lt;/code&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Set up your TypeScript configuration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next, you need to set up your TypeScript configuration. Create a &lt;code&gt;tsconfig.json&lt;/code&gt; file in the root of your project and add the following configuration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "dist",
    "sourceMap": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This configuration tells TypeScript to compile your code to ES6, use CommonJS as the module system, output the compiled code to the &lt;code&gt;dist&lt;/code&gt; directory, generate source maps to aid in debugging, and include all files in the &lt;code&gt;src&lt;/code&gt; directory. It also excludes the &lt;code&gt;node_modules&lt;/code&gt; directory, which contains third-party modules that you don't need to compile.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Write your TypeScript code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that you have TypeScript installed and configured, you can start writing your code. Use the &lt;code&gt;*.ts&lt;/code&gt; file extension for your TypeScript files.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name: string): void {
  console.log(`Hello, ${name}!`);
}

greet("Reader");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, we've defined a simple function that takes a &lt;code&gt;name&lt;/code&gt; parameter and logs a greeting to the console.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Compile your TypeScript code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To compile your TypeScript code, you need to run the TypeScript compiler. You can do this using the &lt;code&gt;tsc&lt;/code&gt; command, which is included with the TypeScript package. Here's how you can compile your code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx tsc&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;This will compile your TypeScript code and generate JavaScript files in the &lt;code&gt;dist&lt;/code&gt; directory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Run your Node.js application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that you've compiled your TypeScript code to JavaScript, you can run your Node.js application as you normally would. Here's how you can run the example code we defined earlier:&lt;/p&gt;

&lt;p&gt;bash&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node dist/index.js&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;This will run the compiled JavaScript code and output the greeting to the console.&lt;/p&gt;

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

&lt;p&gt;In this article, we've discussed how TypeScript can help improve code quality and maintainability in Node.js applications. We've also shown how to set up TypeScript in a Node.js project and compile TypeScript code to JavaScript. By using TypeScript in your Node.js projects, you can catch errors at compile-time, improve code maintainability, and benefit from better tooling support.&lt;/p&gt;

&lt;p&gt;If you're interested in learning more about TypeScript, check out the official &lt;a href="https://www.typescriptlang.org/docs/"&gt;TypeScript documentation&lt;/a&gt;. Happy hacking!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
