<?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: Jesus Bossa</title>
    <description>The latest articles on Forem by Jesus Bossa (@makinox).</description>
    <link>https://forem.com/makinox</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%2F98956%2F24bbd113-62b5-47a2-b4b9-5fe639abcaa7.jpeg</url>
      <title>Forem: Jesus Bossa</title>
      <link>https://forem.com/makinox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/makinox"/>
    <language>en</language>
    <item>
      <title>tRPC: What the future of the backend looks like</title>
      <dc:creator>Jesus Bossa</dc:creator>
      <pubDate>Wed, 16 Aug 2023 00:48:49 +0000</pubDate>
      <link>https://forem.com/makinox/trpc-what-the-future-of-the-backend-looks-like-3boe</link>
      <guid>https://forem.com/makinox/trpc-what-the-future-of-the-backend-looks-like-3boe</guid>
      <description>&lt;p&gt;A new way of communicating between frontends and backends has arrived in our developer lives, aiming to make things simpler and faster.&lt;/p&gt;

&lt;p&gt;This technology I'm talking about is tRPC, which is a library that facilitates the creation of APIs between the client and the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is tRPC?
&lt;/h2&gt;

&lt;p&gt;tRPC is based on the concept of &lt;strong&gt;RPC&lt;/strong&gt; (Remote Procedure Call) but is specifically designed to be used with TypeScript in modern web environments.&lt;/p&gt;

&lt;p&gt;By using tRPC, you can define your APIs on the server using TypeScript. This allows you to specify data types and ensure that the data sent and received is correct.&lt;/p&gt;

&lt;p&gt;On the client side, you can also leverage TypeScript to obtain strong type checking in API calls, which builds robust and reliable communication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// BackEnd&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appRouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;userList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;publicProcedure&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;david&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;andres&lt;/span&gt;&lt;span class="dl"&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;users&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="c1"&gt;// FrontEnd&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&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;trpc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; [{ name: 'david' }, { name: 'andres' }]&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;¿How does tRPC work? / ¿How is it possible?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We can describe the functioning of tRPC as an eight-step process.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Definition on the Server:&lt;/strong&gt;&lt;br&gt;
First, the API is defined on the server using tRPC. This involves creating functions and methods that can be remotely called by clients. Each function is defined with its name, input parameters, and the expected data type to be returned.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generation of TypeScript Code:&lt;/strong&gt;&lt;br&gt;
tRPC uses this API definition on the server to automatically generate TypeScript code that represents the API functions. These generated functions will be used by the client to make API calls.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client Installation:&lt;/strong&gt;&lt;br&gt;
On the client side (such as a web application), the tRPC client is installed. This involves installing &lt;code&gt;@trpc/client&lt;/code&gt; or a library provided by the community. This library provides the generated functions that correspond to the API defined on the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Calls on the Client:&lt;/strong&gt;&lt;br&gt;
On the client, you can directly call the functions generated by tRPC as if they were local functions. These calls can be made synchronously or asynchronously, depending on your preferred way of handling them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Serialization and Data Sending:&lt;/strong&gt;&lt;br&gt;
When a tRPC function call is made on the client, the data and parameters are serialized (converted into a suitable format for transfer) and sent to the server through an HTTP/1.1 or HTTP/2 request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Execution on the Server:&lt;/strong&gt;&lt;br&gt;
On the server, tRPC deserializes the received data, identifies the corresponding function based on the call name and parameters, and executes the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Response Processing:&lt;/strong&gt;&lt;br&gt;
After executing the function on the server, a response is generated that may include the requested results or data. This response is serialized and sent back to the client.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reception and Usage by the Client:&lt;/strong&gt;&lt;br&gt;
On the client, the response is deserialized and delivered to the function on the client that initiated the original call. The data or results can be used in the client's code as needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nPWgj_0W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zgls9qqny50edp9jivox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nPWgj_0W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zgls9qqny50edp9jivox.png" alt="Describing how does tRPC work" width="800" height="646"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What's the difference between tRPC and gRPC?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;tRPC and gRPC are two different technologies, although they share similarities in their names due to their relationship with RPC. Here are some key differences between tRPC and gRPC:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Programming language and platform:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tRPC&lt;/strong&gt;: It's specifically designed to work with TypeScript and is most commonly used in the context of web applications based on JavaScript/TypeScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;gRPC&lt;/strong&gt;: It's designed to be cross-platform and supports multiple programming languages, including C++, Java, Python, Go, and more. It's commonly used in microservices architectures and broader distributed applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Communication Protocol:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tRPC&lt;/strong&gt;: It uses HTTP/1.1 or HTTP/2 as the communication protocol. It can send data in JSON or binary format, making it suitable for modern web environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;gRPC&lt;/strong&gt;: It uses HTTP/2 as the communication protocol, and the default data serialization format is Protocol Buffers (protobuf), which is more efficient and compact than JSON. This makes it more suitable for high-traffic and performance-intensive applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flexibility and Ease of Use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tRPC&lt;/strong&gt;: It's designed with a simple syntax and structure, making it easy to use and quick to set up for small to medium-sized projects. It's lightweight and can be suitable for cases where quick setup is desired.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;gRPC&lt;/strong&gt;: It has a more complex syntax due to the use of protocol buffers and requires more initial setup. It's more powerful in larger and more complex scenarios, such as distributed systems and microservice architectures.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Should Someone Use tRPC?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are several reasons why someone might consider using tRPC in their TypeScript web projects:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; &lt;br&gt;
tRPC is designed with a simple and easily understandable syntax, making implementation and usage straightforward. It doesn't require a steep learning curve, making it ideal for small to medium-sized projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TypeScript-Friendly:&lt;/strong&gt;&lt;br&gt;
Being TypeScript-specific, tRPC allows you to define data types both on the server and the client, providing greater safety and helping to avoid common data type-related errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Transparent Communication:&lt;/strong&gt;&lt;br&gt;
tRPC facilitates communication between the client and server, abstracting much of the underlying logic and enabling API calls to be made transparently as if they were local functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lightweight Approach:&lt;/strong&gt; &lt;br&gt;
tRPC is designed to be a lightweight and agile solution, making it suitable for smaller projects or when a quick setup without complications is needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modern Web Technology Compatibility:&lt;/strong&gt; &lt;br&gt;
By using HTTP/1.1 or HTTP/2 and allowing data to be sent in JSON or binary format, tRPC is compatible with modern web technologies, allowing easy integration into existing web applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Documentation and Active Community:&lt;/strong&gt; &lt;br&gt;
tRPC comes with solid documentation and an active community of users and developers, which can facilitate the learning process and provide additional support for any questions or issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; &lt;br&gt;
While tRPC is more suitable for small to medium-sized projects, it can be scalable as your application grows. It's possible to migrate to more complex RPC solutions like gRPC if the project reaches a higher level of complexity.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ultimately, the choice to use tRPC will depend on the specific needs of your project and the context you're in. If you're looking for a simple, quickly implementable solution focused on TypeScript to facilitate communication between the client and server, tRPC can be a suitable option.&lt;br&gt;
And if you would like to start testing technology, I will share the following links for you to discover the ecosystem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://trpc.io/docs"&gt;Official documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/iway1/trpc-panel"&gt;Template a complete backend with each end point documented to work with a team&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://create.t3.gg/"&gt;Template to start a full-stack app with Next.js, tRPC, tailwind CSS and prisma&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>frontend</category>
      <category>backend</category>
    </item>
    <item>
      <title>¿How to make unbreakable code?</title>
      <dc:creator>Jesus Bossa</dc:creator>
      <pubDate>Fri, 11 Nov 2022 13:55:00 +0000</pubDate>
      <link>https://forem.com/makinox/how-to-make-unbreakable-code-2le9</link>
      <guid>https://forem.com/makinox/how-to-make-unbreakable-code-2le9</guid>
      <description>&lt;p&gt;&lt;em&gt;Available spanish version &lt;a href="https://voib.jesusbossa.dev/article/Como_crear_codigo_irrompible"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Suddenly, it sounds weird, at first, unbreakable code, what does it mean.&lt;br&gt;
In short, it is a code that breaks, basically that the compiler or interpreter generates an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿How do we get to something like this?
&lt;/h2&gt;

&lt;p&gt;Well, when we write code, many things that we normally do are exposed to errors, some more than others, even occasions that are not caused by developers or users, for example, let's consider the following example.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cu0CKXDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kvmcspnpozu5wppmrml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cu0CKXDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kvmcspnpozu5wppmrml.png" alt="Normal flow of an app" width="880" height="450"&gt;&lt;/a&gt;&lt;br&gt;
A simple request, we want to update our age in a social network, and the back-end receives the request from the front-end, then it checks that the data is correct, changes the database, and tells us that everything went fine. At any of those points, the example could fail, like if the internet connection went out or if the data was incomplete.&lt;br&gt;
So, how we handle error cases, depending on the language, there are several options, try/catch, promise catch, which is basically exception handling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's talk about try/catch
&lt;/h2&gt;

&lt;p&gt;This way of handling exceptions was implemented way back in the &lt;a href="https://en.wikipedia.org/wiki/Exception_handling#History"&gt;60s&lt;/a&gt;, it started in lisp, it was popular enough that the programming languages of the time decided to implement it as well.&lt;br&gt;
Why do I think this is not the best idea? Well, it happens that in this structure.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B_-Rvir2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iizpkyy30kbcw8ip8vie.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B_-Rvir2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iizpkyy30kbcw8ip8vie.png" alt="Try / catch and railway oriented programming" width="880" height="612"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;TRY&lt;/code&gt; executes the happy path, all that should happen if all goes well, if it doesn't execute &lt;code&gt;CATCH&lt;/code&gt;, the exception handler.&lt;br&gt;
&lt;code&gt;CATCH&lt;/code&gt; which is what happens when the above process fails.&lt;br&gt;
In the &lt;code&gt;⁣CATCH&lt;/code&gt; we are saying that something happened that we probably don't know what happened. We entered an exception and exited the normal execution of the app. Errors should not be exceptional, at least not in a system or robust development architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿So if not, then how?
&lt;/h2&gt;

&lt;p&gt;It is always helpful to take charge of knowing what is happening in the code. The best friend in these cases is the compiler, which is a well-informed interpreter of everything we enter into the code. It is always helpful to avoid dynamic typing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 15
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Mark'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# BobMark
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 15
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Mark'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Error
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Javascript / Typescript
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum_numbers&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="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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mark&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// BobMark&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum_numbers&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="kr"&gt;number&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="kr"&gt;number&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mark&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// Error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the first example of each language, we see an example of as a common and harmless function, but not knowing the type of each parameter that the function receives could trigger an error in the long or short term.&lt;br&gt;
I would recommend in these cases to use strong typing, we should tell in the example that they are numbers or text or only numbers, whatever you think works for you; we should make sure what we are going to receive in the functions to not receive unknown parameters and trigger an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  However
&lt;/h2&gt;

&lt;p&gt;This solves the simplest problems, but what happens when the data is optional or is one or the other, simply here we could handle this cases with &lt;code&gt;IF&lt;/code&gt;, &lt;code&gt;CASES&lt;/code&gt;, to identify if data or an error is coming.&lt;br&gt;
However, there is a more complicated case, which happens when the native functions of the interpreter or compiler fail us; what if we do a division by zero, that the compiler knows that it is going to work with numbers but never what numbers.&lt;br&gt;
There are times that it is not until the execution that we realize, unless we take them into account, the easy one is an &lt;code&gt;IF&lt;/code&gt; watching cases of having a zero in both sides to not execute the code, but what if we have no way of knowing this.&lt;br&gt;
There are libraries of safe mathematical operations that take care of this type of validation. Programming languages also tend to update themselves to be more kind to the developer and detect this type of problem in time. For example, they could use &lt;code&gt;TypeScript&lt;/code&gt; or &lt;code&gt;Rust&lt;/code&gt; to check for potential errors.&lt;br&gt;
In my opinion, there is a language that does this spectacularly, &lt;code&gt;Rust&lt;/code&gt; introduces a concept called &lt;code&gt;panic&lt;/code&gt;, which is not an error, but it gives us an early warning that what we are doing may fail and almost forces us to handle it; In fact, a curious fact about why Rust is so loved is because it is very difficult to make it fail, since the compiler of this language is excellent, so much that it is effortless to make unbreakable code.&lt;/p&gt;

&lt;p&gt;Sometimes technology, like Rust and strong typing, can be more or less complicated depending on the type of the educational moment or company that you are, but at least knowing that these things exist is important, and I hope that someone learned something new today or was encouraged to use some of these technologies. Thank you for reading.&lt;/p&gt;

</description>
      <category>opinion</category>
      <category>goodpractices</category>
      <category>cleancode</category>
      <category>development</category>
    </item>
  </channel>
</rss>
