<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Franklyn Roth</title>
    <description>The latest articles on DEV Community by Franklyn Roth (@far3).</description>
    <link>https://dev.to/far3</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%2F763454%2F2d637fed-b59d-48db-a090-65bd0617c902.jpeg</url>
      <title>DEV Community: Franklyn Roth</title>
      <link>https://dev.to/far3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/far3"/>
    <language>en</language>
    <item>
      <title>How optional? chaining works in JavaScript
</title>
      <dc:creator>Franklyn Roth</dc:creator>
      <pubDate>Sat, 04 Dec 2021 04:17:03 +0000</pubDate>
      <link>https://dev.to/far3/how-operational-chaining-works-in-javascript-26bj</link>
      <guid>https://dev.to/far3/how-operational-chaining-works-in-javascript-26bj</guid>
      <description>&lt;p&gt;When developing on a project you will 100% come across a scenario where you need to do conditional logic. Conditional is basically handling multiple decisions and it is often taught very early in any introductory computer science class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Standard Conditionals
&lt;/h2&gt;

&lt;p&gt;We are all familiar with the standard if else below&lt;br&gt;
&lt;strong&gt;If else conditional statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_2rjBG2S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gurcsc7hiet2tw9zjpyl.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_2rjBG2S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gurcsc7hiet2tw9zjpyl.JPG" alt="Image description" width="297" height="116"&gt;&lt;/a&gt;&lt;br&gt;
This is basically saying if the hour is before/less than 18 (3pm in the afternoon) it is a good day greeting and after 3pm is a good evening greeting.&lt;/p&gt;

&lt;p&gt;Another example are switch statements. Ie. Rule of thumb is if the logic is “over 3” a switch statement should be used instead of multiple if else statements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Switch statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oyxhY-0G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xen5bepfu537vykb20ef.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oyxhY-0G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xen5bepfu537vykb20ef.JPG" alt="Image description" width="530" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most common way you’ll see ? used in JavaScript is using it in what is called a ternary operator or inline if. A ternary is a shorthand way of writing the above if / else statement, the first time I saw it as an intern..it broke my brain. I have grown to really enjoy using it, it is short, concise and can be easily read on one line. You will commonly see it in react and other front end JavaScript libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Example&lt;/strong&gt;     &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hFr6s1le--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1xw32r9f9nu1etgaccg.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hFr6s1le--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1xw32r9f9nu1etgaccg.JPG" alt="Image description" width="583" height="36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above example with ternary or inline if&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P9oTVOpQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mizkz7vqr8i8jh61yjap.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P9oTVOpQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mizkz7vqr8i8jh61yjap.JPG" alt="Image description" width="496" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The condition to test is on the left side of the ?. If the value is true the value to the left side of the colon will display. If the value is false the one to the right will display. Much more effective and easy to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optional Chaining
&lt;/h2&gt;

&lt;p&gt;Optional chaining enables you to read the value of a property deep in a chain of connected objects. Instead of causing a runtime error, the expression short circuits and returns undefined. &lt;/p&gt;

&lt;p&gt;Lets say you want to render a component and the data value is deeply nested in the return object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mJjmdLJM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ws6l4i91orordjuvihmt.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mJjmdLJM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ws6l4i91orordjuvihmt.JPG" alt="Image description" width="526" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we didn’t have the ? after doe we would get an all too familiar runtime error.&lt;br&gt;
This saves us from having to explicitly check each value before we render it to the browser.&lt;/p&gt;

&lt;p&gt;catAge = adventurer &amp;amp;&amp;amp; adventurer.cat &amp;amp;&amp;amp; adventurer.cat.age&lt;br&gt;
console.log(catAge);&lt;/p&gt;

&lt;p&gt;By just using adventurer.cat?.age. JavaSCript know to check to make sure the cat? Object is not null or undefined before attempting to a access the age property. If it is, it automatically short circuits and returns undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
We’ve had a short review on conditionals and how to write them as well as switch statements. How to shorten them with ternary/ inline If’s for more readable and succinct code. Finally we learned something new called optional chaining, which prevents you from checking each individual value. I hope this was helpful and you can take it back to your codebase.&lt;/p&gt;

&lt;p&gt;Resources: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/how-the-question-mark-works-in-javascript/"&gt;https://www.freecodecamp.org/news/how-the-question-mark-works-in-javascript/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/docs/conditional-rendering.html"&gt;https://reactjs.org/docs/conditional-rendering.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to debug and troubleshoot production issues</title>
      <dc:creator>Franklyn Roth</dc:creator>
      <pubDate>Sun, 28 Nov 2021 01:08:42 +0000</pubDate>
      <link>https://dev.to/far3/how-to-debug-and-troubleshoot-production-issues-3mj9</link>
      <guid>https://dev.to/far3/how-to-debug-and-troubleshoot-production-issues-3mj9</guid>
      <description>&lt;p&gt;If you've been a software developer for any length of time,  you have had to deal with or be involved with a production support issue. This is doubly so if your application is client facing, ie. facing the general public and has high importance that it is working during peak times. This could be during busy market days or during a huge sale. Uptime is critical.&lt;/p&gt;

&lt;p&gt;On-call is usually on a rotation basis and different companies have different policies. Let's say you get the call, tier 1 support will reach out, tell you a general description and ask that you get online. Before hastily jumping online ask these three questions to get your bearings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"What is happening?"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Where are we at?"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"What did we try?"&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions will give you a general idea of what is going on and may jog your memory and spark a  question that they can look into. Typically support calls interrupt you when you're relaxing at home and not in prime work problem solving mode.&lt;/p&gt;

&lt;p&gt;Ok, so you hop online brain foggy, coffee pot not filling quick enough and you're on a  bridge with a bunch of people, amazing!&lt;/p&gt;

&lt;p&gt;Now what?!&lt;/p&gt;

&lt;h2&gt;
  
  
  Replicate the Issue
&lt;/h2&gt;

&lt;p&gt;Always replicate the issue by yourself. In web development, some tricks to reliably replicate issues are to try it in an  incognito browser as some extensions may mess with default behavior.&lt;/p&gt;

&lt;p&gt;If the bug is intermittent and can't be reliably reproduced, this means that you need to keep digging and still get the steps required to reproduce the problem. If someone says "It's intermittent or it's non-replicable" that's BS. More research needs to be done to understand the root problem. A common example is if something 'seems' intermittent, it is usually a server issue and narrowing it down to a specific server or node will help.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mitigate Impact
&lt;/h2&gt;

&lt;p&gt;The next item once it's been reliably replicated and you gain an understanding of what piece of the system is breaking, is to mitigate impact if possible. You are being called because the client/company is losing money either directly or through losing credibility because their site is broken and a lot of people are seeing it.&lt;/p&gt;

&lt;p&gt;Every companies hosting strategy will be different, but most companies will have some form of backup or way to deploy the code to a different location. It could be multiple data centers, multiple instances or containers. In my experience there were multiple data centers and simply moving all traffic to the other data center mitigated the impact while uncovering the root cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  Search back in time
&lt;/h2&gt;

&lt;p&gt;My favorite thing to do and a seemingly unknown tactic is to simply search back in time. Its true that each issue has the potential to be unique. Most of the time it's not. Search ticketing systems, intranet, teams/slack/messaging chat history and support base. I've had it on more than one occasion where I got lucky and this problem has occurred before. I pieced together the solution from multiple tickets and chat histories. Then I documented it myself so future developers and support engineers could learn and solve this issue I was facing that much faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Narrow down search
&lt;/h2&gt;

&lt;p&gt;Keep narrowing down your search and coming up with hypotheses on why XYZ is happening. If there are 2 data centers, each with 4 servers, then check each individual server and hit 101a, 101b, 101c. It's quite common that one of them will be in a bad state. Another option is to narrow it down by service, since web development is a lot of interconnecting technologies, test out each service and see where the point of failure is.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some Common ones
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Do you  get a response from the API? &lt;br&gt;
Is it giving an error message that could indicate the authentication is an issue such as an expired certificate or password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do you get data back, but is the data wrong? &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maybe reach out to the database team and dig into how that data is ingested.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Front end page or module not rendering? &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Possibly a data type change and error handling was not implemented.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sit and think. No really, just sit and think through the problem occurring at hand. This can be tough to do, because support or a client  is often asking for your update quite frequently. Sit and think and even write it out on a pad or draw what is happening and some ideas may come to you. You could even talk out loud like rubber duck debugging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be overly communicating about what you find.
&lt;/h2&gt;

&lt;p&gt;As mentioned earlier, you will be bugged quite a bit for updates and what progress has been made. "Still investigating" is a perfectly fine answer. A better answer would be to over communicate what your findings are. I'm doing x, I suspect it's y, I am trying to do Z. Oftentimes others can chime in and possibly help you in your debug efforts. Another benefit is if someone has already ruled that problem out, they will let you know before you invest any more time into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  If still stuck, reach out to other experts
&lt;/h2&gt;

&lt;p&gt;Everyone eventually needs to call for help at one point or another. It could be because they don't have permissions to view or access something. It could be they don't have the domain knowledge on that particular part of the system. Or you are just stumped with your back against the wall. This happens and is normal. It's important when calling another resource after hours to have the three questions I posted ready to go. It ensures no time is wasted and you made a solid effort instead of "I dunno, just call the tech lead".&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"What is happening?"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Where are we at?"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"What did we try?"&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Document your solution
&lt;/h2&gt;

&lt;p&gt;So you did it, you were able to replicate the issue, mitigate the impact and narrow down your search. You pieced together past tickets and messages and had a few hypotheses. Some were wrong, but a few got you in the right direction. You posted updates to the production support chat room and others chimed in and helped jog your memory of the application. You tested a final hypothesis before calling in backup and it turned out to be 100% correct. Congrats, this is a great feeling. A fix was implemented, ie server restart, config update needed, cache busted..etc and the client is happy, support is happy..you're done right?&lt;/p&gt;

&lt;p&gt;No&lt;/p&gt;

&lt;p&gt;This might be the 2nd most important step next to replicating the problem. It is documenting the solution. Document the steps that you took, post comments step by step in the ticketing system or better yet your production support document. I've seen a "common issues" section and this will help the future developer that gets called late at night or super early in the morning. That next dev could be a close colleague or even better tier 1 could handle it on their own. They will be thankful you did and reduce the &lt;a href="https://en.wikipedia.org/wiki/Bus_factor"&gt;bus factor&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  TLDR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Replicate the Issue&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mitigate Impact&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search back in time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Narrow down search&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sit and think.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Be overly communicating about what you find.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If still stuck, reach out to other experts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Document your solution&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>todayilearned</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
