<?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: Rohit Awate</title>
    <description>The latest articles on Forem by Rohit Awate (@rohit).</description>
    <link>https://forem.com/rohit</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%2F46349%2F48a78928-9875-4085-9eb2-f9ee00290070.jpg</url>
      <title>Forem: Rohit Awate</title>
      <link>https://forem.com/rohit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rohit"/>
    <language>en</language>
    <item>
      <title>My First Contribution to Firefox</title>
      <dc:creator>Rohit Awate</dc:creator>
      <pubDate>Wed, 06 Nov 2019 17:43:49 +0000</pubDate>
      <link>https://forem.com/rohit/my-first-contribution-to-firefox-l0p</link>
      <guid>https://forem.com/rohit/my-first-contribution-to-firefox-l0p</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://rohitawate.github.io/2019/11/06/firefox-contribution"&gt;my personal blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since the past couple of years, I've open-sourced &lt;a href="https://github.com/RohitAwate"&gt;most of my projects&lt;/a&gt; and also contributed to a few small ones. However, I've always wanted to contribute to a large, popular open-source project. I finally got around to doing that last month: I submitted a patch to Mozilla Firefox's JavaScript engine, &lt;strong&gt;SpiderMonkey&lt;/strong&gt;, which was accepted on November 2.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UysDweHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://rohitawate.github.io/images/posts/2019-11-06-firefox-contribution/header.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UysDweHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://rohitawate.github.io/images/posts/2019-11-06-firefox-contribution/header.jpg" alt="header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I use Firefox every day. I appreciate and believe in the values and principles of privacy and an open Internet that Mozilla holds. Also, I have the highest amount of respect for people that volunteer in such projects. Thus, it felt great to contribute back!&lt;/p&gt;

&lt;p&gt;This post serves two purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;to document my experience with the hopes of inspiring people to contribute to Mozilla &lt;em&gt;(or other major open-source projects, for that matter)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;to serve as a guide for someone making their first contribution to Mozilla since they have a pretty involved process and I don't want you to repeat the same mistakes as me!&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Finding a Bug
&lt;/h1&gt;

&lt;p&gt;My patch fixes &lt;a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1589072"&gt;this bug&lt;/a&gt;, which I found via &lt;a href="https://codetribute.mozilla.org/"&gt;Codetribute&lt;/a&gt;. You can use the 'good first bug' filter to find beginner-friendly bugs. Codetribute only lists bugs; they actually reside on Mozilla's bug tracker, &lt;a href="https://bugzilla.mozilla.org/home"&gt;BugZilla&lt;/a&gt;. Once you find a bug that you find interesting, check if someone else is already working on it. If not, add a comment that you wish to work on it.&lt;/p&gt;

&lt;p&gt;You'll have to search for the instructions to get the source code, build the project, run tests and so on. For example, here's &lt;a href="https://wiki.mozilla.org/JavaScript:New_to_SpiderMonkey"&gt;SpiderMonkey's getting started guide&lt;/a&gt;. This will vary depending on which project/module of Firefox you're contributing to.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Bug I Fixed
&lt;/h1&gt;

&lt;p&gt;My contribution improves the errors reported by the JavaScript parser. Luckily, I got to work on a brand-new feature of JavaScript called numeric separators. This allows you to make your long numeric literals more readable by adding underscores between digits. This feature just shipped in Firefox 70 in late October 2019 and my patch will be live in Firefox 72.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Hard to read&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Numeric separators improve readability&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;_000_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://github.com/tc39/proposal-numeric-separator"&gt;ES6 specification&lt;/a&gt; only allows a single underscore as a numeric separator between two digits. Additionally, a numeric literal must not end with an underscore. Thus, the following lines of code are illegal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;__0&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;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you run this code under Firefox 70, you'll see the same error in both cases:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hb4iVA1d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://rohitawate.github.io/images/posts/2019-11-06-firefox-contribution/ff70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hb4iVA1d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://rohitawate.github.io/images/posts/2019-11-06-firefox-contribution/ff70.png" alt="ff70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Makes sense, right? However, the SpiderMonkey team wanted separate error messages for these cases. Following is a screenshot from Firefox Nightly, which includes my patch:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FLNDpZw1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://rohitawate.github.io/images/posts/2019-11-06-firefox-contribution/ff72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FLNDpZw1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://rohitawate.github.io/images/posts/2019-11-06-firefox-contribution/ff72.png" alt="ff72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These error messages are contextually aware and more in line with what the programmer would expect.&lt;/p&gt;

&lt;h1&gt;
  
  
  Writing the Fix
&lt;/h1&gt;

&lt;p&gt;Thankfully, Mozilla's &lt;a href="https://twitter.com/jorendorff/"&gt;Jason Orendorff&lt;/a&gt; had provided detailed instructions on the BugZilla thread regarding the fix. Hence, it was just a matter of a few lines of C++. It was really simple.&lt;/p&gt;

&lt;p&gt;You can view the patch &lt;a href="https://hg.mozilla.org/mozilla-central/rev/08d0bf739bad"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have any doubts, just leave a comment on the BugZilla thread or reach out to the respective team on IRC. Mozilla's community is incredibly welcoming, helpful, smart and patient. Don't hesitate to ask questions. Communication is key. That's one of the most important things I learned in this process.&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating a Patch
&lt;/h1&gt;

&lt;p&gt;Once you've made the changes, run the tests and are ready to submit, you can commit to the local Mercurial repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// view the changed files&lt;/span&gt;
&lt;span class="n"&gt;hg&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;

&lt;span class="c1"&gt;// view your changes&lt;/span&gt;
&lt;span class="n"&gt;hg&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;

&lt;span class="c1"&gt;// stage all of your changes&lt;/span&gt;
&lt;span class="n"&gt;hg&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;// commit the staged changes&lt;/span&gt;
&lt;span class="n"&gt;hg&lt;/span&gt; &lt;span class="n"&gt;commit&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="s"&gt;"Bug 1589072 - Improve numeric separators error messages"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For the commit message, use the above format. That number is the ID of the bug and the following message is its title, both from BugZilla.&lt;/p&gt;

&lt;h1&gt;
  
  
  Submitting the Patch
&lt;/h1&gt;

&lt;p&gt;This is the tough part and where I messed up the most. Mozilla uses it's own infrastructure and thus it's not as easy as opening a Pull Request on GitHub.&lt;/p&gt;

&lt;p&gt;First, you need to submit your patch for review. Mozilla uses &lt;a href="https://phabricator.services.mozilla.com/"&gt;Phabricator&lt;/a&gt; for this purpose. In order to submit your patch there, you need to use a command-line tool called &lt;code&gt;moz-phab&lt;/code&gt;. Follow &lt;a href="https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html#setting-up-mozphab"&gt;this guide&lt;/a&gt; for setting up your Phabricator account and to install &lt;code&gt;moz-phab&lt;/code&gt; locally.&lt;/p&gt;

&lt;p&gt;Next, open a terminal and &lt;code&gt;cd&lt;/code&gt; into the Firefox repository. Here, you can simply run &lt;code&gt;moz-phab&lt;/code&gt; and it will push your changes to Phabricator and create a revision. The link to it will appear in your terminal.&lt;/p&gt;

&lt;p&gt;For more information about using Phabricator, check out this &lt;a href="https://moz-conduit.readthedocs.io/en/latest/walkthrough.html"&gt;workflow walkthrough&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Code Review
&lt;/h1&gt;

&lt;p&gt;Now, you need to wait for someone from the team to review your patch. They might request some changes or make some suggestions. Make the necessary changes. Again, if you have any doubts or questions, communicate with the team and get them cleared!&lt;/p&gt;

&lt;h1&gt;
  
  
  Submitting Changes to your Patch
&lt;/h1&gt;

&lt;p&gt;This is where you need to exercise caution. You might assume that you just need to run &lt;code&gt;hg commit&lt;/code&gt; and &lt;code&gt;moz-phab&lt;/code&gt; again to push your changes to Phabricator. If you do this, you'll end up creating a &lt;em&gt;completely new&lt;/em&gt; revision on Phabricator. This is the mistake I made.&lt;/p&gt;

&lt;p&gt;You shouldn't create a new commit. Instead, add the changes to your original commit. You can do this using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;hg&lt;/span&gt; &lt;span class="n"&gt;commit&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;amend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Don't add the &lt;code&gt;-m&lt;/code&gt; flag. Just run the above command, which will open your text editor asking you for a commit message. Add that; it can be the same as before. On the following lines, add this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Differential revision: &amp;lt;link-to-original-phabricator-revision&amp;gt;

// for example:
Differential revision: https://phabricator.services.mozilla.com/D51134
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This tells &lt;code&gt;moz-phab&lt;/code&gt; that this commit is a revision to your original patch. Consequently, it adds these changes to the same revision. You will be able to see your revision on Phabricator now.&lt;/p&gt;

&lt;h1&gt;
  
  
  Acceptance and Landing
&lt;/h1&gt;

&lt;p&gt;If the reviewer is satisfied with your changes, s/he will accept your patch. Next, you need to wait for someone to 'land' your patch. I'm not entirely sure but I think that means committing your patch to the &lt;a href="https://hg.mozilla.org/mozilla-central"&gt;central repository&lt;/a&gt;. One of Mozilla's sheriffs will do that for you since you most likely don't have commit rights if you're reading this post.&lt;/p&gt;

&lt;p&gt;Once that's done, well, congratulations! Not only did you work through your first patch and submit it, but you also got it accepted! You can check out your change live in the Firefox Nightly build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/AoVyddXBybVjq/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/AoVyddXBybVjq/giphy.gif" alt="the-office-dancing-gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope this post served one of its goals &lt;em&gt;(or maybe both)&lt;/em&gt;: either inspiring or helping you. I enjoyed this process and am proud of my patch, however little and simple it was. I hope to contribute regularly to Firefox henceforth.&lt;/p&gt;

&lt;p&gt;We use open-source software every day, knowingly or not. If you have the time and skills, please contribute! The feeling of giving back is amazing.&lt;/p&gt;

&lt;p&gt;That's it for today, see you in the next one!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS: I would like to thank my friend, &lt;a href="https://dev.to/jaydeepborkar"&gt;Jaydeep Borkar&lt;/a&gt;, whose contribution to &lt;a href="https://github.com/explosion/spaCy"&gt;spaCy&lt;/a&gt; inspired me to do this!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>firefox</category>
      <category>opensource</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Demystifying Tail Call Optimization</title>
      <dc:creator>Rohit Awate</dc:creator>
      <pubDate>Thu, 11 Jul 2019 16:09:52 +0000</pubDate>
      <link>https://forem.com/rohit/demystifying-tail-call-optimization-5bf3</link>
      <guid>https://forem.com/rohit/demystifying-tail-call-optimization-5bf3</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fdog_tail.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fdog_tail.jpg" alt="main"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://rohitawate.github.io/2019/07/11/tail-call-optimization" rel="noopener noreferrer"&gt;my personal blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tail call optimization (a.k.a. tail call elimination) is a technique used by language implementers to improve the recursive performance of your programs. It is a clever little trick that eliminates the memory overhead of recursion. In this post, we'll talk about how recursion is implemented under the hood, what tail recursion is and how it provides a chance for some serious optimization.&lt;/p&gt;

&lt;h1&gt;
  
  
  Recursion 101
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;If you're familiar with function call stacks and recursion, feel free to skip this section.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most languages use a stack to keep track of function calls. Let's take a very simple example: a "hello, world" program in C.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello, world!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&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;Every function call in your program gets its own frame pushed onto the stack. This frame contains the local data of that call. When you execute the above program, the &lt;code&gt;main&lt;/code&gt; function would be the first frame on the stack, since that's where your program begins execution. The topmost frame in the stack is the one currently being executed. After it completes execution, it is popped from the stack and the bottom frame resumes execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fmain.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fmain.png" alt="main"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our example, &lt;code&gt;main&lt;/code&gt; in turn calls &lt;code&gt;printf&lt;/code&gt;, another function, thereby pushing a new frame onto the stack. This frame will contain &lt;code&gt;printf&lt;/code&gt;'s local data. Once &lt;code&gt;printf&lt;/code&gt; completes execution, its frame is popped and control returns to the &lt;code&gt;main&lt;/code&gt; frame.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fprintf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fprintf.png" alt="printf"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recursive functions do the same. Every recursive call gets its own frame on the stack. Here's a &lt;em&gt;horrible example&lt;/em&gt; of a recursive function which prints "hello" &lt;code&gt;n&lt;/code&gt; times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// hello_recursive.c&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&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="n"&gt;n&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="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&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;The above code gives the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function call stack will be something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fhello.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Fhello.png" alt="hello"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first two calls will print out "hello" and make recursive calls with &lt;code&gt;n - 1&lt;/code&gt;. Once we hit the last call with &lt;code&gt;n = 0&lt;/code&gt;, we begin unwinding the stack.&lt;/p&gt;

&lt;p&gt;Now imagine that we wish to print "hello" a million times. We'll need a million stack frames! I tried this out and my program ran out of memory and crashed. Thus, recursion requires &lt;code&gt;O(n)&lt;/code&gt; space complexity, &lt;code&gt;n&lt;/code&gt; being the number of recursive calls. This is bad news, since recursion is usually a natural, elegant solution for many algorithms and data structures. However, memory poses a physical limit on how tall (or deep, depending on how you look at it) your stack grows. Iterative algorithms are usually far more efficient, since they eliminate the overhead of multiple stack frames. But they can grow unwieldy and complex.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tail Recursion
&lt;/h1&gt;

&lt;p&gt;Now that we've understood what recursion is and what its limitations are, let's look at an interesting type of recursion: &lt;strong&gt;tail recursion&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Whenever the recursive call is the last statement in a function, we call it tail recursion. However, there's a catch: there cannot be any computation after the recursive call. Our &lt;code&gt;hello_recursive.c&lt;/code&gt; example is tail recursive, since the recursive call is made at the very end i.e. tail of the function, with no computation performed after it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since this example is plain silly, let's take a look at something serious: &lt;strong&gt;Fibonacci numbers&lt;/strong&gt;. Here's a non tail-recursive variant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Returns the nth Fibonacci number.&lt;/span&gt;
&lt;span class="c1"&gt;// 1 1 2 3 5 8 13 21 34 ...&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&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="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&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;n&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;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&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;You might argue that this is tail recursive, since the recursive calls appear at the end of the function. However, the results of the calls are added &lt;em&gt;after&lt;/em&gt; they return. Thus, &lt;code&gt;fib&lt;/code&gt; is not tail recursive.&lt;/p&gt;

&lt;p&gt;Here's the tail-recursive variant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;fib_tail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&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="n"&gt;a&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="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&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;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;fib_tail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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="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="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;The recursive call appears last and there are no computations following it. Cool.&lt;/p&gt;

&lt;p&gt;You may be thinking, &lt;em&gt;"Hmm, tail recursion is interesting, but what is the point of this?"&lt;/em&gt;. Turns out, it is more than just a way of writing recursive functions. It opens up the possibility for some clever optimization.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tail Call Optimization
&lt;/h1&gt;

&lt;p&gt;Tail call optimization reduces the space complexity of recursion from &lt;code&gt;O(n)&lt;/code&gt; to &lt;code&gt;O(1)&lt;/code&gt;. Our function would require constant memory for execution. It does so by eliminating the need for having a separate stack frame for every call.&lt;/p&gt;

&lt;p&gt;If a function is tail recursive, it's either making a simple recursive call or returning the value from that call. &lt;strong&gt;No computation is performed on the returned value&lt;/strong&gt;. Thus, there is no real need to preserve the stack frame for that call. We won't need any of the local data once the tail recursive call is made: we don't have any more statements or computations left. We can simply modify the state of the frame as per the call arguments and jump back to the first statement of the function. No need to push a new stack frame! We can do this over and over again with just one stack frame!&lt;/p&gt;

&lt;p&gt;Let's look at our example with the non tail-recursive &lt;code&gt;fib&lt;/code&gt; function. To find out the 3rd Fibonacci number, we'd do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;third_fib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&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;Assuming right-to-left precedence (i.e. the direction in which an expression is evaluated), the call stack would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Ffib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Ffib.png" alt="fib"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quite large, isn't it? Imagine the size of the stack for finding out a later Fibonacci number! The problem here is that all the stack frames need to be preserved. You may use one of the local variables in the addition and hence the compiler needs to keep the frames around. If you look at the assembled output of this program, you'll see a &lt;code&gt;call&lt;/code&gt; instruction for the &lt;code&gt;fib&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;You can use the &lt;code&gt;-S&lt;/code&gt; flag on GCC to output the assembly code. I've deliberately used the &lt;code&gt;-O2&lt;/code&gt; flag which uses the 2nd level of optimization among GCC's 0-3 levels. O2 enables tail call optimization. If you're not familiar with assembly, use GCC's &lt;code&gt;-fverbose-asm&lt;/code&gt; flag while compiling. It adds your C code as comments before its corresponding assembled output. Here's the final command, which will produce a &lt;code&gt;.s&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;gcc&lt;/span&gt; &lt;span class="n"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;O2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;fverbose&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;asm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what our tail call translates to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;# Snippet extracted from: fib.s
&lt;/span&gt;
&lt;span class="cp"&gt;# fib.c:7:  return fib(n - 1) + fib(n - 2);
&lt;/span&gt;&lt;span class="n"&gt;movl&lt;/span&gt;    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;ecx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;edi&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;ivtmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;call&lt;/span&gt;    &lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;
&lt;span class="n"&gt;subl&lt;/span&gt;    &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;ecx&lt;/span&gt;    &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ivtmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;
&lt;span class="n"&gt;addl&lt;/span&gt;    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;edx&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;_4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;add_acc_7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, I'm not going to pretend that I understand this completely, because I don't. We only care about the instructions, none of the operand details. Notice the &lt;code&gt;call fib&lt;/code&gt; instruction? That's the recursive call. It pushes a new frame onto the stack. Once that completes and pops, we have our addition instruction. Thus, we conclude that even at the 2nd level of optimization, the recursive calls cannot be eliminated, thanks to the addition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fib_tail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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="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="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take a look at our tail recursive Fibonacci function, &lt;code&gt;fib_tail&lt;/code&gt;. Once the above recursive call is made, there's no need to keep the local data around. There's no computation following the statement and it's simply returning the value returned by the recursive call; we could do that straight from the recursive call.&lt;/p&gt;

&lt;p&gt;This presents an opportunity to simply replace the values of the local &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; variables with the ones used in the recursive call. Instead of a &lt;code&gt;call&lt;/code&gt; instruction like before, the compiler can simply redirect the flow of execution to the first instruction in the function, effectively emulating a recursive call. But, without the overhead of one! Basically, the compiler goes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbit.ly%2F2XQZZob" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbit.ly%2F2XQZZob" alt="gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how the call stack would look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Ffib_tail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frohitawate.github.io%2Fimages%2Fposts%2F2019-07-10-tail-call-optimization%2Ffib_tail.png" alt="fib_tail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You don't have to take my word for it, let's look at the assembler output for &lt;code&gt;fib_tail&lt;/code&gt;. We compile the same way as before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;gcc&lt;/span&gt; &lt;span class="n"&gt;fib_tail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;O2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;fverbose&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;asm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For our tail recursive call, I see the following snippets of assembly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;# fib_tail.c:11:    return fib(n - 1, b, a + b);
&lt;/span&gt;    &lt;span class="n"&gt;movl&lt;/span&gt;    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;edx&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;retval&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;

&lt;span class="cp"&gt;# fib_tail.c:11:    return fib(n - 1, b, a + b);
&lt;/span&gt;    &lt;span class="n"&gt;leal&lt;/span&gt;    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;rsi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;rdx&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;   &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;retval&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;# fib_tail.c:11:    return fib(n - 1, b, a + b);
&lt;/span&gt;    &lt;span class="n"&gt;leal&lt;/span&gt;    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;rcx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;rdx&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;esi&lt;/span&gt;   &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_5&lt;/span&gt;

&lt;span class="cp"&gt;# fib_tail.c:11:    return fib(n - 1, b, a + b);
&lt;/span&gt;    &lt;span class="n"&gt;movl&lt;/span&gt;    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;esi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;edx&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;_5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I said, I don't really understand assembly, but we're just checking if we've eliminated the &lt;code&gt;call fib&lt;/code&gt; recursive calls. I'm not really sure how GCC is redirecting the control flow. What matters, however, is that there are no &lt;code&gt;call fib&lt;/code&gt; instructions in the code. That means there are no recursive calls. The tail call has been eliminated. Feel free to dive into the assembly and verify for yourself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbit.ly%2F2XVE9zQ" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbit.ly%2F2XVE9zQ" alt="chandler dancing gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Support
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;We've been using &lt;strong&gt;C&lt;/strong&gt; in this post since GCC and Clang both support tail call optimization (TCO).&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;C++&lt;/strong&gt;, the case holds with Microsoft's Visual C++ also offering support.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java&lt;/strong&gt; and &lt;strong&gt;Python&lt;/strong&gt; do not support TCO with the intention of preserving the stack trace for debugging. Some internal Java classes also rely on the number of stack frames. Python's BDFL, Guido van Rossum, has explicitly stated that no Python implementations should support TCO.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kotlin&lt;/strong&gt; even comes with a dedicated &lt;code&gt;tailrec&lt;/code&gt; keyword which converts recursive functions to iterative ones, since the JVM (Kotlin compiles to JVM bytecode) doesn't support TCO.&lt;/li&gt;
&lt;li&gt;TCO is part of ECMAScript 6 i.e. the &lt;strong&gt;JavaScript&lt;/strong&gt; specification, however, only Safari's JavaScriptCore engine supports TCO. Chrome's V8 retracted support for TCO.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C#&lt;/strong&gt; does not support TCO, however, the VM it runs within, Common Language Runtime (CLR) supports TCO.&lt;/li&gt;
&lt;li&gt;Functional languages such as &lt;strong&gt;Haskell&lt;/strong&gt;, &lt;strong&gt;F#&lt;/strong&gt;, &lt;strong&gt;Scala&lt;/strong&gt; and &lt;strong&gt;Elixir&lt;/strong&gt; support TCO.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It appears that support for TCO is more of an ideological choice for language implementers, rather than a technical one. It does manipulate the stack in ways the programmer would not expect and hence makes debugging harder. Refer the documentation of the specific implementation of your favorite language to check if it supports tail call optimization.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope you understood the idea and techniques behind TCO. I guess the takeaway here is to prefer iterative solutions over recursive ones &lt;em&gt;(that is almost always a good idea, performance-wise)&lt;/em&gt;. If you absolutely need to use recursion, try to analyze how big your stack would grow with a non-tail call.&lt;/p&gt;

&lt;p&gt;If both of these conditions don't work for you and your language implementation supports tail call optimization, go for it. Keep in mind that debugging will get harder so you might want to turn off TCO in development and only enable it for production builds which are thoroughly tested.&lt;/p&gt;

&lt;p&gt;That's it for today, see you in the next post!&lt;/p&gt;

</description>
      <category>tailrecursion</category>
      <category>tailcalloptimization</category>
      <category>compiler</category>
      <category>c</category>
    </item>
    <item>
      <title>How Everest orchestrates pseudo tab-switching</title>
      <dc:creator>Rohit Awate</dc:creator>
      <pubDate>Wed, 19 Sep 2018 18:04:07 +0000</pubDate>
      <link>https://forem.com/rohit/how-everest-orchestrates-pseudo-tab-switching-49gp</link>
      <guid>https://forem.com/rohit/how-everest-orchestrates-pseudo-tab-switching-49gp</guid>
      <description>&lt;p&gt;Everest is a REST API testing client that I've been working on this year. Its written in JavaFX and aims to be a &lt;strong&gt;lighter, open-source&lt;/strong&gt; alternative to Electron-based options like &lt;em&gt;Postman&lt;/em&gt;. It occupied the &lt;strong&gt;#2 spot on GitHub's Java Trending&lt;/strong&gt; for a week back in May this year when I released the first alpha. Today, I'll be talking about a memory optimization technique that I've implemented in the most recent alpha release.&lt;/p&gt;

&lt;p&gt;I'm calling it &lt;em&gt;pseudo tab-switching&lt;/em&gt;. Why? Because I'm an engineer and we like to give fancy names to simple stuff.&lt;/p&gt;

&lt;p&gt;This article is quite technical and some stuff is done in a certain way because JavaFX demands so. However, the concept itself is framework/lanuguage-agnostic and you can use it with any other tech stack and make better use of your resources.&lt;/p&gt;

&lt;p&gt;A disclaimer before we begin: I'm a student. I'm still attending university and have no professional experience. I have literally conjured up these ideas out of thin air and implemented them because they sounded promising. If you are an experienced developer, you may find this rather simple and obvious. Nonetheless, this was easily the most complex thing I've implemented in Everest and I'm excited to share it with you. Any feedback is welcome!&lt;/p&gt;

&lt;h1&gt;
  
  
  The Problem
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh856ldo18013tjzyaeap.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh856ldo18013tjzyaeap.jpg" alt="dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the Dashboard in Everest. You can compose and send requests and also view their responses within it. You can have multiple of them open in separate tabs.&lt;/p&gt;

&lt;p&gt;Prior to pseudo tab-switching &lt;em&gt;(lets call it PTS, shall we?)&lt;/em&gt;, for every new tab that you opened in Everest, a new Dashboard was created. That includes the view and the controller. Just a handful of tabs would push the memory usage north of 400MB.&lt;br&gt;
This was really depressing and demotivating for me. At one point I even thought of removing the tabs altogether but that would mean giving in to a few electrons in my laptop and you won't be reading this article.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Eureka moment
&lt;/h1&gt;

&lt;p&gt;About two months back, as I was dreaming on a separate thread of my brain during a university lecture, I had an idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What if I load just &lt;em&gt;one&lt;/em&gt; Dashboard and change the content within it every time the user switches to a different tab?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Makes sense right? All tabs show the same attributes (API endpoint, HTTP method, status code and so on) just with different values.&lt;/p&gt;

&lt;p&gt;This would give the illusion of switching between tabs but you'd actually just be switching between &lt;em&gt;states&lt;/em&gt; of the Dashboard. This would not only require way less memory but also facilitate better re-use of allocated memory. And that's where the name comes from!&lt;/p&gt;

&lt;p&gt;Sounds simple, eh?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Why did you have to write an article about this, Rohit? My cat could do this while asleep.", you'd say.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/o0vwzuFwCGAFO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/o0vwzuFwCGAFO/giphy.gif" alt="cat typing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, you have one smart cat. Jokes aside, implementing this logic was not a smooth ride and I ran into some design issues that I had not anticipated but ended up with some solutions that I'm quite happy with and proud of.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Challenges
&lt;/h1&gt;

&lt;p&gt;So, barely able to contain my excitement, I bunked the remainder of the day's lectures, came home and fired up IntelliJ IDEA to implement my idea. (pun totally intended)&lt;/p&gt;

&lt;p&gt;I wrote a new &lt;code&gt;DashboardState&lt;/code&gt; class which would hold the values contained by all the UI elements ie the URL, the params, the HTTP method and so on. Everest already had a &lt;code&gt;HomeWindowController&lt;/code&gt; class which handled the tabbing logic among other stuff. Before PTS, whenever a new tab was opened, HWC would simply create a new Dashboard and set it as the content for the new tab.&lt;/p&gt;

&lt;p&gt;But since we've decided to use a single Dashboard and switch between its states, I wrote a new method in &lt;code&gt;DashboardController&lt;/code&gt; called &lt;code&gt;setState(DashboardState state)&lt;/code&gt;. Now, every time a new tab is opened, I create a new, blank DashboardState object and set that as the state of the Dashboard using this method. HWC also holds a &lt;code&gt;HashMap&lt;/code&gt; to keep track of which state belongs to which tab.&lt;/p&gt;

&lt;p&gt;I also wrote a nifty little &lt;code&gt;reset()&lt;/code&gt; method in &lt;code&gt;DashboardController&lt;/code&gt; which clears the Dashboard of the previous tab's state.&lt;/p&gt;

&lt;p&gt;By now, we can properly display a state in the Dashboard. But when you switch from tab A to tab B and return to A again, how do we display A again? This is something I realized quite late. Before making the switch from A to B, we need to store the state of A in the aforementioned map.&lt;/p&gt;

&lt;p&gt;So I wrote another getState() method in &lt;code&gt;DashboardController&lt;/code&gt; which returns the current state of the Dashboard, which can then be saved. Simply put, when the user shifts back to tab A, HWC finds its state from the map and then uses &lt;code&gt;setState()&lt;/code&gt; to apply it to the Dashboard thereby completing the switch.&lt;/p&gt;

&lt;p&gt;So far so good. But a big monster lurked by as Rohit rejoiced in his pseudo tab-switching glory..&lt;/p&gt;
&lt;h1&gt;
  
  
  The Monster
&lt;/h1&gt;

&lt;p&gt;Before we get to the big problem, we need to understand how Everest handles HTTP requests. The requests obviously need to be made on a background thread. But Everest also needs to show a nice loading animation while the request is being made. To make this possible, I use JavaFX's excellent &lt;code&gt;Service&lt;/code&gt; API. Not only does it allow me to make HTTP requests on a background thread, but also provides me with methods to update the UI concurrently. These include &lt;code&gt;setOnRunning()&lt;/code&gt;, &lt;code&gt;setOnSucceeded()&lt;/code&gt; and &lt;code&gt;setOnFailed()&lt;/code&gt; which accept &lt;strong&gt;lambdas&lt;/strong&gt; that update the UI.&lt;/p&gt;

&lt;p&gt;Everest uses &lt;code&gt;setOnRunning()&lt;/code&gt; to trigger the loading animation of the Dashboard, &lt;code&gt;setOnSucceeded()&lt;/code&gt; to display the response (status code, body, elapsed time and so on) and &lt;code&gt;setOnFailed()&lt;/code&gt;, the error messages. What I intend to establish here is that these lambdas act on the Dashboard.&lt;/p&gt;

&lt;p&gt;But, if the user initiates a request in tab A and switches to tab B &lt;strong&gt;while&lt;/strong&gt; the request is still running on the Dashboard, &lt;code&gt;setOnSucceeded()&lt;/code&gt; would display tab A's result when tab B is selected.&lt;/p&gt;

&lt;p&gt;The lambdas, somehow, need to be removed on a tab switch. But, we also need to keep the request running because if it is terminated or even halted, the utility of multi-tabbing ceases to exist.&lt;/p&gt;

&lt;p&gt;Here's an elegant solution that I came up with, which I'm quite proud of.&lt;/p&gt;
&lt;h1&gt;
  
  
  Beating the Monster
&lt;/h1&gt;

&lt;p&gt;Remember that getState() method from &lt;code&gt;DashboardController&lt;/code&gt;? I added a simple check within that to see what the Dashboard is currently doing. If a request is running, it will take that Service object, and hand it over to the &lt;code&gt;DashboardState&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now comes the clever bit: DS decommissions the lambdas that modified the Dashboard and adds its own which modify its own members!&lt;/p&gt;

&lt;p&gt;For example, if &lt;code&gt;DashboardController&lt;/code&gt;'s lambda for&lt;code&gt;setOnSucceeded()&lt;/code&gt;displayed the status code of the response by modifying the text value of a Label onscreen, the corresponding one set by &lt;code&gt;DashboardState&lt;/code&gt; would modify the &lt;code&gt;statusCode&lt;/code&gt; attribute within itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F89d3h2mhggdqvq96xdsu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F89d3h2mhggdqvq96xdsu.gif" alt="PTS in action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, when the user switches back to tab A, A's state will be applied to the Dashboard which in turn will have been updated by the lambdas set by DashboardState!&lt;/p&gt;

&lt;p&gt;TLDR? PTS allows you to switch between tabs even when you've got requests running in one or more of them.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Gains 💪
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fuwy63e5kvz0ul3z5lzwz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fuwy63e5kvz0ul3z5lzwz.jpg" alt="comparison"&gt;&lt;/a&gt;&lt;br&gt;
This comparison was made between Alpha 1.2 &lt;em&gt;(without PTS)&lt;/em&gt; and the upcoming Alpha 1.4 &lt;em&gt;(with PTS)&lt;/em&gt; with 7 tabs in each instance. With more tabs, the difference can become even larger since v1.4 has to only create another instance of a &lt;code&gt;DashboardState&lt;/code&gt; rather than a full Dashboard like v1.2 does.&lt;/p&gt;

&lt;p&gt;There is still scope for tiny improvements here and there, which will be done once we hit a feature-lock, which should happen by the end of this year or early next year.&lt;/p&gt;
&lt;h1&gt;
  
  
  Summing it up
&lt;/h1&gt;

&lt;p&gt;It all boils down to this simple algorithm:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save the state of the Dashboard&lt;/li&gt;
&lt;li&gt;Reset the Dashboard&lt;/li&gt;
&lt;li&gt;If a new tab is being opened, create and then apply a blank new DashboardState to the Dashboard&lt;/li&gt;
&lt;li&gt;If switching back to an existing tab, fetch its state from the map and apply it to the dashboard&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a formal-ish definition for pseudo tab-switching:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you have multiple UI elements that house a common UI element, then instead of creating multiple instances of the latter, create just one and share it between multiple instances of the former by switching between states.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1&gt;
  
  
  "Okay, now shut up Rohit!"
&lt;/h1&gt;

&lt;p&gt;Yes, I hear you! This has been a very long post with a galaxy worth of jargon. I was going to make some announcements and ask a couple of questions but lets save it for next time.&lt;/p&gt;

&lt;p&gt;Check out Everest on GitHub and try out Alpha 1.3. Let your developer friends know about it. Stay tuned for future updates as we're approaching a stable release early next year.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/RohitAwate" rel="noopener noreferrer"&gt;
        RohitAwate
      &lt;/a&gt; / &lt;a href="https://github.com/RohitAwate/Everest" rel="noopener noreferrer"&gt;
        Everest
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A beautiful, cross-platform REST client.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/23148259/39124644-c886b47a-4719-11e8-953c-f079b3edb664.png"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F23148259%2F39124644-c886b47a-4719-11e8-953c-f079b3edb664.png" alt="everestheader"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Everest &lt;em&gt;(formerly RESTaurant)&lt;/em&gt; is an upcoming REST API testing client written in JavaFX.&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/23148259/45769743-23e5a380-bc5e-11e8-9e45-5ea50342c19f.PNG"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F23148259%2F45769743-23e5a380-bc5e-11e8-9e45-5ea50342c19f.PNG" alt="home"&gt;&lt;/a&gt;
&lt;em&gt;Everest running on Windows 10.&lt;/em&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Why Everest?&lt;/h1&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Everest is written in Java. Thus, it is significantly &lt;strong&gt;lighter on resources and more responsive&lt;/strong&gt; than its Electron-based alternatives like &lt;em&gt;Postman&lt;/em&gt;. It aims to provide the same level of functionality in a lighter, native but equally slick package.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Aesthetic is very important. With a &lt;strong&gt;gorgeous, flat design&lt;/strong&gt;, Everest is a pleasure to look at and to work with. It is also entirely theme-&lt;em&gt;able&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I want you to want to use it!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Being a Java application, Everest is inherently &lt;strong&gt;cross-platform&lt;/strong&gt;. It will run anywhere there's a JVM.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Everest will offer cloud synchronization of your projects powered by &lt;a href="https://github.com/RohitAwate/Summit" rel="noopener noreferrer"&gt;Summit&lt;/a&gt;. It will be available as a cloud service early next year or you may also choose to self-host it.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Live Features 🔥&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;All of the most common&lt;/h4&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/RohitAwate/Everest" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I hope you found something of value here. PTS can be useful even if you're doing front-end web development or native mobile app development.&lt;/p&gt;

&lt;p&gt;Thank you for reading this! Leave a comment if you have suggestions, questions or anything else to say.&lt;/p&gt;

&lt;p&gt;You may now Alt + Tab back to your text editor.&lt;br&gt;
&lt;em&gt;Goodbye!&lt;/em&gt; :)&lt;/p&gt;

</description>
      <category>javafx</category>
      <category>restapi</category>
      <category>optimization</category>
      <category>desktopapp</category>
    </item>
    <item>
      <title>Everest: A gorgeous REST API client written in JavaFX</title>
      <dc:creator>Rohit Awate</dc:creator>
      <pubDate>Wed, 02 May 2018 15:31:23 +0000</pubDate>
      <link>https://forem.com/rohit/everest-a-gorgeous-rest-api-client-written-in-javafx-25f2</link>
      <guid>https://forem.com/rohit/everest-a-gorgeous-rest-api-client-written-in-javafx-25f2</guid>
      <description>&lt;p&gt;Hi! I'm Rohit, a student currently in the second-year of Computer Engineering. For the past 4 months, I've been building a REST API client with JavaFX. I'm really excited to share my work with you folks! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F23148259%2F41772368-f9276dae-7635-11e8-97ec-1a1e8aa608c4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F23148259%2F41772368-f9276dae-7635-11e8-97ec-1a1e8aa608c4.PNG" alt="Windows10"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My goal with this project was to make something similar to &lt;em&gt;Postman&lt;/em&gt; and &lt;em&gt;Insomnia&lt;/em&gt; but in a lighter package using JavaFX without compromising on the beautiful design that Electron-based applications come with, while maintaining a comparable level of functionality. I'm currently focused on optimizing every thing that comes under my radar but I also add new features occasionally.&lt;/p&gt;

&lt;p&gt;Here are some of the core features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A gorgeous user-interface.&lt;/li&gt;
&lt;li&gt;Making  GET, POST, PUT, DELETE and PATCH requests. (&lt;em&gt;duh&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-tab&lt;/strong&gt; layout.&lt;/li&gt;
&lt;li&gt;History tab to quickly search through your recent requests.&lt;/li&gt;
&lt;li&gt;Support for &lt;strong&gt;custom themes&lt;/strong&gt; via JavaFX CSS!&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Visualizer&lt;/strong&gt; which shows you a nice tree for your response bodies&lt;/li&gt;
&lt;li&gt;Being written in Java, Everest is inherently &lt;strong&gt;cross-platform&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay enough, my beautiful README is getting jealous so why don't you go check her out on GitHub: &lt;a href="https://github.com/RohitAwate/Everest" rel="noopener noreferrer"&gt;https://github.com/RohitAwate/Everest&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please try out the alpha and let me know what you think! :)&lt;/p&gt;

</description>
      <category>javafx</category>
      <category>restapi</category>
      <category>showdev</category>
      <category>desktopapp</category>
    </item>
  </channel>
</rss>
