Python has lot of niche features in which can help improve efficiency or readability of code. Today we will discuss some of those features that you can immediately start using in your day to day scripting.
eg: a =(1, 2) are useful in a sense they occupy the least space, and the closest thing to constant that you you can expect from python. But they are one of the least used datatype. Reading from tuple is based on position like
a. Enter named tuple, that takes advantage of normal tuple and adds the basic subscription of dict…
Create your own classic snake game using the React library.
The snake game is a classic. I have fond memories of playing it on the small LCD screen of a Nokia phone. I always wanted to make a snake game for a long time. I kept postponing it cause I thought it would be complex. Luckily, I was wrong. I was able to make a mediocre snake game.
Let’s start by creating a React app:
$ npx create-react-app snake-game
The basic structure of the snake game in the React class looks like this:
There are other…
Meta programming allows us to write code that manipulates code. Macros are the way of doing meta programming in rust. Macro provide simple API to abstract out code. The macros in rust is different from macro in
C. Instead of using text substitution like
C, rust expands its macros into abstract syntax trees. They hold enormous potential. But macros are complex. Which means they are harder to read, write, maintain and debug. They also increase the size of the binary and increase compile time. There are two types of macros in rust:
Declarative macros: It allows us to write match…
Rust and Python are two of the most beloved programming languages. They both are complement each other very well. Python is easy to code and has a powerful APIs but slow. Rust is fast, and safe but has high code complexity. In this article, we will use
PyO3 to embed python in rust and vice versa. My article just aims to introduce new people to PyO3. The official website has good documentation covering almost everything.
Let's start by creating a new cargo package:
$ cargo new learning-rust
A quick introduction to Haskell’s syntax
Haskell is a purely functional programming language. It is the 28th most popular programming language based on google search in 2021. It has been around since 1990. People like Haskell for its elegant syntax which is both expressive and powerful at the same time.
Learning a new programming language, especially if it's a new paradigm than what we are used to is important for programmers at any level. Python is dynamic, interpreted and procedural while Haskell is static, compiled and functional. I am learning Haskell just for the sake of functional programming. I liked…
Functional programming is a declarative programming paradigm where we break down a problem in a sets of state independent that takes iterable input data and produce as output without modifying the input data. Function programming makes the code modular, and easy to debug. Popular functional programming languages are Haskell, Lisp, or Erlang.
The major concepts of functional programming are:
Recursion: In functional programming we don't use loops. Instead we rely on recursion for iteration.
Pure functions: Pure functions are functions with no side effect i.e they do not modify the global state or input variables. …
Object oriented programming (OOPS) is an really popular programming paradigm based on classes and objects. Objects instances of classes and are used to representation of real life entities. Each object contains a set of attributes which are data which hold the state of object, and behaviors which are the methods which manipulates the data to give meaningful results. Classes are blueprint for creating objects.
Objected oriented programming is based on four main principles:
When we write a normal interpreter, we follow multiple steps: lexer, parser, and compiler and interpreter. Lexer and parser are used to create abstract syntax tree. Compiler is used to create bytecode which is the intermediate representation created at the end of compiler step. And a virtual machine will interpret the byte code to get results. We will be discussing after the byte code has been generated. If you want to learn about previous steps you can refer to Let’s Build an Interpreter in Python from Scratch. To interpret the bytecode we use virtual machine.
Normally when a programming language…
Python is an interpreted language. Interpreted means the source code is translated to machine code as the program runs. But that’s a gross simplification.
Python has basically four steps for running your source code: lexer, parser, compiler and interpreter. Lexer and parser are self evident. It is used to create abstract syntax tree. Compiler may come as shock to most people.
Like most of the other interpreted languages, Python initially compiles the source code written by us to intermediary format
Byte code is a low level set of instructions called that contains set of instructions that can be interpreted…
Hello World in ANTLR using python
Recently, I have been really keen on creating my own programming language. (reference: Lets build interpreter from scratch). But it got boring really quick. Most of my energy is spent on creating a parser. So I wanted to search for tools that will make my life a little easier. I stumbled into ANTLR via quora recommendation.
According to the official website:
ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It’s widely used to build languages, tools, and frameworks. …