Writing conditional expressions is pretty easy to do. But there is room for improvement in the way we have been doing it. And with the flexibility that JavaScript provides, we can replace conditionals with clean code by using some good practices. And it can lead to more maintainable code. Let us take a look at writing better conditional expressions in this post.

1. Early returns

When we start learning programming, we are taught that we should only have one return statement. While the advice is not wrong, it becomes challenging to read code if the code base is large. …


As you might know, I recently switched jobs. And in my long journey of finding a new one, there was a moment where I was offered way more money than I had anticipated for a role that I was not as passionate about. And I wish I could say that it was an easy no for me. But it was not. I wanted to say no. But instead, I kept asking myself, “Am I really going to do this?”. And I even talked to quite a few close friends about that decision. And everybody, including my parents, told me that…


Introduction of type hinting opened the gates for a lot of great new features in Python. And data validation and parsing became easier to do with the use of type hints. Pydantic is one such package that enforces type hints at runtime. It throws errors allowing developers to catch invalid data.

Pydantic not only does type checking and validation, it can be used to add constraints to properties and create custom validations for Python variables. It guarantees the types and constraints of the model have been applied and that the data is valid.

This is useful especially when we have…


Every now and then, you come across a JavaScript feature that vastly changes the way you write it. Destructuring, arrow functions, modules have been some of those features for me. Optional chaining is going to be the next one on that list for me.

Optional Chaining is in stage 4 of the ES2020 proposal, therefore should be added to the specification. It changes the way properties inside an object are accessed, especially the deeply nested ones. It is also available as a feature in TypeScript 3.7+.

The challenge

I am pretty sure you have run into null and undefined properties in JavaScript…


With the introduction of type hinting in Python 3.5, static typing and checking Python codes has started to gain popularity. While MyPy was the first tool to do static type checking of Python code, many other frameworks have been built after it. Pyright is one such tool built by Microsoft and is the one that we will be discussing in this post.

Type hints in Python

Python has been a dynamically typed language. While that flexibility has its benefits, it becomes a hassle when working on large scale projects. Inferring the type of an object can be hard at times for the interpreter. …


As we discussed in our post on getting started with Pytest, the framework allows us to re-use tests by making use of test fixtures and parameterized functions. In this post, we will learn how to do so.

We will build on our simple calculator example that we discussed in the previous post and add to it. Without further ado, let us get started.

Adding test fixtures

As we saw in our small example, there is some repetition in the two basic tests that we wrote:

# calculator_test.py from calculator import add def test_add(): firstNumber = 2 secondNumber = 1 assert add(firstNumber, secondNumber) ==…

Testing our code brings in a variety of benefits, including building confidence in the code’s functioning and having lesser regressions.

Writing and maintaining tests requires some additional work, and that is why we want to leverage tools as much as we can.

Python does provide inbuilt tools such as unittest for supporting testing, but it involves writing a lot of boilerplate code. It also has a limited ability to reuse components (or fixtures in PyTest). Therefore we will be testing Python applications using Pytest instead of other tools. Pytest is the most popular tool among other alternatives as well.

(We…


The process to format a number as currency can be a tedious task. It feels like a small task, but the number of lines and the edge cases can keep on increasing when considering factors such as internationalization and different formatting standards. Luckily, ES2015 introduced an internationalization API which can make the process to format a number as currency super easy.

Writing our own formatting function

We can surely put together a hacky function for this, right?

let formatCurrency = (val, currency) => { let val; switch (currency) { case 'USD': val = `$ ${val}`; break; case 'EUR': val = `€ ${val}`; break; default: throw…

I recently got the new Apple Silicon Mac (aka the M1 mac), and that means having to deal with the pain points of buying the first generation of something product. Though things are slowly improving, there are still many gotchas when it comes to using the first generation of a product. Installing Intel-based packages using Homebrew on the M1 mac ended up being one such pain for me.

I love the M1 mac’s performance, but installing packages and software using Homebrew has not been as straightforward as I had hoped for. As you might know, the M1 macs run on…


Flask is a python framework for writing web applications. It is a microframework, which as the name suggests, is a small, clean, and simple to use framework. It comes with a minimal set of features, which sounds like a strange choice at first. So why would we choose Flask if it does a minimal amount of things? Flask is

  • clean and simple;
  • un-opinionated (aka flexible);
  • well documented;
  • popular and has active community support;
  • does not have any additional bloatware that might not be needed;
  • extensible to include extensions that we want to add.

What is included in Flask?

  • Jinja 2…

saransh kataria

For over and over, I have failed & in the process of losing it all, I realized that I might actually win.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store