<?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: Santosh Venkatraman 🖖</title>
    <description>The latest articles on DEV Community by Santosh Venkatraman 🖖 (@on_stash).</description>
    <link>https://dev.to/on_stash</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%2F74469%2Fc26d1c71-d942-47d8-a91f-5fad4e259ae2.jpg</url>
      <title>DEV Community: Santosh Venkatraman 🖖</title>
      <link>https://dev.to/on_stash</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/on_stash"/>
    <language>en</language>
    <item>
      <title>Configure nginx to host multiple subdomains</title>
      <dc:creator>Santosh Venkatraman 🖖</dc:creator>
      <pubDate>Sun, 17 Feb 2019 02:36:40 +0000</pubDate>
      <link>https://dev.to/on_stash/configure-nginx-to-host-multiple-subdomains-2g0b</link>
      <guid>https://dev.to/on_stash/configure-nginx-to-host-multiple-subdomains-2g0b</guid>
      <description>&lt;p&gt;&lt;em&gt;This post has been cross-posted from my &lt;a href="https://blog.onstash.me/nginx-subdomain-config/"&gt;blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Configuring nginx for subdomains in the same machine was confusing for me. So I am writing this tutorial primarily for (self)reference but people can find it useful. Without much ado, let's get started.&lt;/p&gt;

&lt;p&gt;For those of you who don't know what nginx is exactly, head over to this &lt;a href="https://medium.freecodecamp.org/an-introduction-to-nginx-for-developers-62179b6a458f"&gt;freeCodeCamp article&lt;/a&gt; as a starting point.&lt;/p&gt;

&lt;p&gt;I assume you're on a linux machine and you know what nginx means.&lt;/p&gt;

&lt;p&gt;First and foremost, install nginx -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second head over to &lt;code&gt;/etc/nginx/sites-available/default&lt;/code&gt; by opening it on vim/nano. You would come across something like this -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
    #   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }.
#}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above you can gather the following points - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;server {}&lt;/code&gt; - that tells nginx that "Hey this is how I think you should configure the server"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;listen 80&lt;/code&gt; - translates to "Listen to port 80, which is the default port for web clients"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;root /var/www/html;&lt;/code&gt; - nginx understands that HTML file/files from that location can be served&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;index index.html index.htm index.nginx-debian.html;&lt;/code&gt; - this indicates that these kind of files should be served in a decreasing order of priority (left to right).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;server_name _;&lt;/code&gt; - this conveys that &lt;code&gt;_&lt;/code&gt; is the server name. Assuming our domain to be &lt;code&gt;example.com&lt;/code&gt;, the server name would be &lt;code&gt;example.com&lt;/code&gt;. That's because when a request is received for &lt;code&gt;example.com&lt;/code&gt;, nginx should whether to process it or not.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;location / {}&lt;/code&gt; - this means that all requests must be handled by this server config. There is an option to handle specific requests as well. For example, requests starting with &lt;code&gt;/server_1&lt;/code&gt; can load &lt;code&gt;server_1.html&lt;/code&gt; and all other requests can load &lt;code&gt;default.html&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next obvious question is - how do I configure subdomains?&lt;/p&gt;

&lt;p&gt;It's not that complicated. It involves 7 steps - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy the default configuration and rename it as &lt;code&gt;subdomain1.example.com&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; /etc/nginx/sites-available/default /etc/nginx/sites-available/subdomain1.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You don't necessarily have to name the file &lt;code&gt;subdomain1.example.com&lt;/code&gt;. It's easier if you follow a convention that makes it easy for everybody involved.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open it and remove the term &lt;code&gt;default_server&lt;/code&gt; besides &lt;code&gt;listen 80&lt;/code&gt; and the line below it. This is crucial.&lt;/li&gt;
&lt;li&gt;Change the &lt;code&gt;server_name&lt;/code&gt; as &lt;code&gt;subdomain1.example.com&lt;/code&gt; &amp;amp; change the HTML &lt;code&gt;root&lt;/code&gt; that's being used&lt;/li&gt;
&lt;li&gt;Then link that file to a file in nginx's sites-enabled directory. This is for nginx to understand that configuration &lt;code&gt;subdomain1.example.com&lt;/code&gt; is enabled in the configuration.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ln -s /etc/nginx/sites-available/subdomain1.example.com /etc/nginx/sites-enabled/subdomain1.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Write a HTML file inside &lt;code&gt;/var/www/html&lt;/code&gt; for &lt;code&gt;subdomain1.example.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Restart the nginx server&lt;/li&gt;
&lt;li&gt;If you're using a DNS provider like Cloudflare, add the box's IP to it with an A record &lt;code&gt;subdomain1.example.com&lt;/code&gt;. If not, then add the box's IP and subdomain1.example.com to /etc/hosts.&lt;/li&gt;
&lt;li&gt;Load &lt;code&gt;subdomain1.example.com&lt;/code&gt; on the browser to check how it loads. If everything is fine, you will see the HTML that you wrote for this subdomain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Extend the same approach for any other domain or subdomain that you require.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>config</category>
      <category>subdomain</category>
    </item>
    <item>
      <title>Looking back at 2018</title>
      <dc:creator>Santosh Venkatraman 🖖</dc:creator>
      <pubDate>Mon, 31 Dec 2018 17:43:59 +0000</pubDate>
      <link>https://dev.to/on_stash/looking-back-at-2018-15m1</link>
      <guid>https://dev.to/on_stash/looking-back-at-2018-15m1</guid>
      <description>

&lt;p&gt;Yelo and welcome to yet another episode in the "looking back at" series. This time it's 2018 and boy does it look positive. &lt;a href="/looking-back-at-2017/"&gt;Last year&lt;/a&gt;, backstreet dogs inaugurated the new year. 2k18 began with a piss drunk gentleman hanging off a parapet wall. He was shouting "Happy New Year" while his friends were begging him not to drop dead.&lt;/p&gt;

&lt;p&gt;Notable things - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Moved to a new house&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This year saw me leaving my old house and moving into a new house with one of my closest college friends, Kate. For the uninitiated, he's a Marathi guy.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Got closer to the family&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Familial struggles became a general topic of discussion. Also group-calling the sister's kid.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Started getting fitter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My close friend Achyuth and I are in the process of going back to college first-year/freshman sizes. 95 =&amp;gt; 81.5.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Started cooking&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to achieve my continuous goal of becoming fitter, I had to start cooking on my own. And man do I love cooking. I hate doing the dishes, tho (gotten used to it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Got my head dunked in water on stage in a serious play&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As part of Creashakthi Bangalore's 2nd production, this serious play 'The Undertrials' was a whole new experience. For those who don't know, Creashakthi is a Chennai based theater group. I got to work with new people from different backgrounds (college kid, marketing manager, nano-chip designer, lawyer-turned-actor, and a full-time actor). Dushyanth (founder of Creashakthi) liked my performance and got head dunked in water on stage &amp;amp; beaten to a pulp. I guess I could check off two things of my &lt;em&gt;bucket&lt;/em&gt; list.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Highly recommend &lt;strong&gt;&lt;a href="http://www.hemingwayapp.com/"&gt;Hemingwayapp&lt;/a&gt; and Grammarly&lt;/strong&gt; for &lt;strong&gt;content writing&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fell in love with &lt;a href="https://mobile.twitter.com"&gt;Twitter's mobile site&lt;/a&gt;, it's tweet thread &amp;amp; bookmarks features&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Discovered a beautiful platform called &lt;a href="https://dev.to"&gt;dev.to&lt;/a&gt; through &lt;a href="https://mobile.twitter.com"&gt;Twitter&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Marketing is hard, especially in the B2C space&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Last year I was enthusiastic about building Footyfollowr. My main pitch point was sOmE tEcHy ThInG tHaT aDdS nO tAnGiBlE vAlUe To A nOrMaL uSeR. Yes, I am a fan of Spongebob memes. TODO - Have to read more about marketing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Code review is easy if done in smaller chunks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the last couple of years, I have felt that reviewing code is easy if done in smaller chunks or commits if you will. When you look at the large diff(erence) after you've reviewed the smaller ones, you will get the big picture. This is not an intuition alone. I have implemented it with my mentor and it works.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That was quoted by Martin Fowler, in "Refactoring: Improving the Design of Existing Code". A solo developer in a team full of developers becomes that 'fool'. Incoherent documentation, broken setup scripts, improper dependency versioning, etc is a common theme. It could be worse - single line readme and unmaintainable hacky "legacy" codebase that some poor soul has to inherit. It takes a toll on the other employees (mental) and the company (financial) to inherit and maintain such codebases with large technical debt.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Email communication is &lt;strong&gt;underrated&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built a &lt;a href="/type-checking-in-python/"&gt;type-checker in Python&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built a &lt;a href="https://github.com/onstash/hackernews"&gt;hackernews app&lt;/a&gt; using Google's Flutter SDK&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Wrote a &lt;a href="https://knowyourmeme.com/memes/mocking-spongebob"&gt;Spongebob mocking meme&lt;/a&gt; text converter in Typescript&lt;/p&gt;

&lt;p&gt;It converts "Spongebob mocking meme" into "sPoNgEbOb MoCkInG mEmE".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Started learning golang&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built a Twitter thread extractor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Fixing performance bottleneck&lt;/p&gt;

&lt;p&gt;This particular performance bottleneck came to be because of the architecture. An infinite horizontal content view became slow via notifications. Had to figure out how, how much, and why using analytics (fun aspect).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Got my feet wet in native Android development by building a custom notification layout&lt;/p&gt;

&lt;p&gt;Had to build a custom notification layout (with image, icon, ability to share, etc) for an app I am building. Coming from the background of React Native, paying the abstraction tax was hard. The native world is different.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stay away from unethical peeps coz they will pull you down eventually&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TODO - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lots&lt;/li&gt;
&lt;li&gt;of&lt;/li&gt;
&lt;li&gt;things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2019 has a lot in store and I am looking forward to this Christian concept of New Year (thanks Yeshua).&lt;/p&gt;

&lt;p&gt;(This post originally appeared on &lt;a href="https://blog.onstash.me/looking-back-at-2018"&gt;blog.onstash.me&lt;/a&gt;)&lt;/p&gt;


</description>
      <category>yearinreview</category>
      <category>2018</category>
      <category>blog</category>
      <category>personalblog</category>
    </item>
    <item>
      <title>Type-checking in Python</title>
      <dc:creator>Santosh Venkatraman 🖖</dc:creator>
      <pubDate>Wed, 06 Jun 2018 00:59:14 +0000</pubDate>
      <link>https://dev.to/on_stash/type-checking-in-python-1mcn</link>
      <guid>https://dev.to/on_stash/type-checking-in-python-1mcn</guid>
      <description>

&lt;p&gt;Type checking function arguments is a common sanity check for function arguments in Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do you mean "type-checking function arguments"?
&lt;/h2&gt;

&lt;p&gt;Let's say you have a function &lt;code&gt;add&lt;/code&gt; that takes in two arguments &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;. There is an implicit understanding that &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; must be either integer (type &lt;code&gt;int&lt;/code&gt;) or float (type &lt;code&gt;float&lt;/code&gt;).&lt;/p&gt;



&lt;div class="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;add&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;add(1, 2)&lt;/code&gt; gives the output &lt;code&gt;3&lt;/code&gt; which is what we intended the function for.&lt;br&gt;
But &lt;code&gt;add([2], [3])&lt;/code&gt; seems to be returning &lt;code&gt;[2, 3]&lt;/code&gt;, a concatenated list.&lt;br&gt;
Also &lt;code&gt;add((2,), (3,))&lt;/code&gt; seems to be returning &lt;code&gt;(2, 3)&lt;/code&gt;, a concatenated tuple.&lt;/p&gt;

&lt;p&gt;To operate only on &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;float&lt;/code&gt; arguments, we can add &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;isinstance&lt;/code&gt; checks. Check out this &lt;a href="https://stackoverflow.com/questions/1549801/what-are-the-differences-between-type-and-isinstance"&gt;StackOverflow post&lt;/a&gt; for understanding the difference between &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;isinstance&lt;/code&gt; checks.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;valid_add_types&lt;/span&gt; &lt;span class="o"&gt;=&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="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&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;if&lt;/span&gt; &lt;span class="nb"&gt;isinstance&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;valid_add_types&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nb"&gt;isinstance&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;valid_add_types&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;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;add(1, 2)&lt;/code&gt; gives the output &lt;code&gt;3&lt;/code&gt; which is what we intended the function for.&lt;br&gt;
&lt;code&gt;add([2], [3])&lt;/code&gt; and &lt;code&gt;add((2,), (3,))&lt;/code&gt; return &lt;code&gt;None&lt;/code&gt; because they're are neither integers nor floats.&lt;/p&gt;

&lt;p&gt;Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can help you, the developer, understand what types of arguments a function needs at a glance&lt;/li&gt;
&lt;li&gt;Useful for existing and new developers&lt;/li&gt;
&lt;li&gt;Bug-fixes and feature additions are less painful&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is manageable for small codebases&lt;/li&gt;
&lt;li&gt;Manual type checking makes large codebases convoluted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the course of discussing how to improve the Developer Experience (DX) of a Python developer, my mentor, Sriram, and I came with up with an idea of a type checking decorator for type checking function arguments.&lt;/p&gt;

&lt;p&gt;Introducing &lt;a href="https://github.com/onstash/typy_checker"&gt;&lt;code&gt;typy_checker&lt;/code&gt;&lt;/a&gt;, an easy-to-use library for type-checking your functions without losing your sanity over it.&lt;/p&gt;

&lt;p&gt;Here is how we could use &lt;code&gt;typy_checker&lt;/code&gt; in our example.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;typy_checker&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;type_checker&lt;/span&gt;

&lt;span class="n"&gt;valid_add_types&lt;/span&gt; &lt;span class="o"&gt;=&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="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;type_checker&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;valid_add_types&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;valid_add_types&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Calling &lt;code&gt;add([2], [3])&lt;/code&gt; will result in the following error - &lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SystemError: add(): Invalid type for variable 'a'. Expected int / float but got list.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;typy_checker&lt;/code&gt; results in a cleaner codebase, from my experience. I have used it in two codebases and they are running in production at the moment.&lt;/p&gt;


</description>
      <category>python</category>
      <category>types</category>
      <category>typechecking</category>
    </item>
  </channel>
</rss>
