Programming Language 💻, import 🚢, spawn vs exec ⚙️, Linux 🐧 command in async ⏱️

By Prajwal Haniya

Techletter #76 | June 8, 2024

Does Programming Language matter?

If you think it doesn’t matter then why do we have so many programming languages? If you think it matters, then why a backend app that can be built with Java can also be built with JavaScript or Python more quickly and efficiently?

Because there is positioning for every language. If you are building a web app then the default go-to language is JavaScript/TypeScript. They are just beautiful languages you can build very good backend and frontend applications with them. But if you are building a mobile app, then I think you should go for Java/Kotlin. I have built a mobile app with React Native. It’s frustrating when you want to access hardware-level APIs.

During college, I used to code in C in the first year, Java in the second and third years, and Python & JavaScript in the fourth year. After that, I got into pure JavaScript (React and Node) & TypeScript. I have no interest in writing long syntax just to print a string. That is the reason I chose JavaScript early when I started coding.

I believe that you should explore different languages, and stick to one because sticking to one for the initial few years will help in building a better understanding of the language, help us build software quickly have a better understanding of what happens under the hood. At the end of the day, more than a programming language, the problem that we are solving matters.

Every week I publish a newsletter where I write about some interesting things I learned. You can subscribe to it on my blog(link in the comments section)


What are the different ways of writing import statements in TypeScript?


How do you get all the import statements inside a project in one go?

I landed up in such a situation where I would need all the import statements in a typescript project. I couldn’t find any package that does this, so I have written a simple function to replicate this functionality.

First, you must go inside the directory from which you need “import statements”.

I will fetch all the strings with the import command by reading all files. This can be achieved with the following command. I used shelljs to execute this command.

find ./src -type f -name "*.ts" -exec grep -H -r -e "import" {} +

now, YOUR_TEXT has the value in string format. Once you have this, you can separate all the import statements using regex;

const importRegex = /import\s+(?:{[^{}]+}|.*?)\s*(?:from)?\s*['"].*?['"]|import$$.*?$$/g;

const imports = YOUR_TEXT.match(importRegex)

What is the difference between spawn and execute in the node process?

spawn

exec


How to execute a Linux command asynchronously in nodejs?