What are your thoughts on using Odin for simple scripts and utilities?
Why Odin?
Odin may not replace very simple shell scripts but it can certainly replace languages like Python, Golang, etc.
Odin has the following features that makes it suitable:
- Easy and simple to learn, write, read and understand.
- Can be written as a single file or a folder (package) of files.
- Has so many things built-in, including vendor packages (even more than Go and Python).
- Can be written like a High Level Language.
- Low Level control when needed.
I can write simple scripts and also simple utilities in Odin. When I need to add more features to my scripts or utilities, I donât need to rewrite it in another language, which is often the case for programs written in shell scripts or Python.
Why not Python?
For very simple scripts I use shell scripts. But for other not-so-simple scripts, I use Python.
But:
- Odin has so many things built-in compared to Python.
- Odin is fast. Python has extremely slow loops.
- Odin can be compiled to a single binary, which makes it ultra-fast to start the program. This matters on my low-tier laptop when many other programs are running.
- Odin has other nice features, see below the Golang section.
Why not Golang?
Golang is a good replacement for Python, and can be compiled to a single binary if I want to. But I am not used to Go (I know it is easy to pick up).
But the main reasons are:
- Odin has so many vendored packages compared to Go.
- Odin has some nice things such as:
- Concise error handling.
- Useful data types such as actual Enums, Bit Sets, etc.
- Ergonomic and powerful
switchstatement. - Useful commonly used functions such as
printfln(),eprintfln(), etc. - Better type annotation syntax.
(Goâs type annotation lacks a separator symbol like colon (:), which is hard to read for complex type annotations). - And many other features that are found to be useful.
Why not C?
I also sometimes use C instead of Python to gain experience in C programming. I started using C for small scripts because of the video in Ginger Billâs article:
The Video That Inspired Me To Create Odin
But the problem with C is that I need to write many things from scratch. I like this if I have time, but if I want something quick then I need to use shell scripts or Python.
Instead, I can also use Odin.
Example
I wanted an Eye Dropper tool that can pick color using mouse from anywhere on the screen. The existing Eye Dropper tools are written using toolkits such as GTK. This makes it slow to open the Eye Dropper tool on my slow computer, especially when I have other programs such as InkScape, Web Browser, etc. are running. My computer has 4GB Ram, Intel i3 processor and a Hard Disk (not SSD). I want the Eye Dropper tool to open instantly when pressing a global keyboard shortcut.
I decided to write a simple Eye Dropper for X11 in Linux that outputs the color to stdout, which can then be copied to clipboard. It is easy to write in C. But I decided to write it in Odin instead. I used the Xlib library binding, which is already included in Odin as a vendor package.
When I wanted a new feature, extending the program was also easier.