You Are Using Old Technology

Monday, January 13, 2025

viewpoint may be largely unrelated to its usefulness. Many if not most of the software we use is probably obsolete according to the latest design criteria. Most users could probably care less if the internals of the operating system they use is obsolete. They are rightly more interested in its performance and capabilities at the user level. - Ken Thompson, The Tanenbaum-Torvalds Debate

At the moment when you start using cutting-edge technology, it quickly becomes outdated. At the same time, someone is fixing a bug, making your cutting-edge technology one patch version old. Someone else might be adding a new feature, making your cutting-edge technology one minor version old. Or, someone could have a grand plan to improve it, making your cutting-edge technology one major version old, or even deprecated! In other words, as soon as you use a particular technology, it is already old. What I’m saying is, you’re always using old technology.

---

Elixir Pt. 4

Sunday, January 5, 2025

We are continuing our journey with composite data types, and in this article, we briefly touch on the next composite data type: Tuples.

Tuples are defined using {} and can hold any type of value.

Go ahead and create a file named tuple.ex. Open this file in your favorite text editor and write the following code in it:

tuple1 = {3, "hi"}
tuple2 = {0, {1, false}, 2.0, "three"}

IO.inspect(tuple1)
IO.inspect(tuple2)

Let’s run this program, and then I’ll explain. Use the following command to run the program:

$ elixir tuple.ex 
{3, "hi"}
{0, {1, false}, 2.0, "three"}

Explanation

  • The first two lines define the tuples tuple1 and tuple2, each containing values of different types. Even further, tuple2 contains a tuple!
  • Finally, as we know, we cannot use the IO.puts function to print the composite data type values. Instead, we have used the same IO.inspect function to inspect and print the values of tuple1 and tuple2.

---

From a user’s (or developer’s) perspective, both lists and tuples store the same types of values (though not internally in the same way). However, if you want to save a small number of values, such as two, three, or five, use tuples. For all other scenarios, use lists.

---

Elixir Pt. 3

Saturday, January 4, 2025

Now, you know a few primitive data types such as Integer, Floating-point numbers, Boolean, and String. Let’s move on and talk about a few composite data types, starting with Lists.

Lists are defined using [] and can hold any type of value.

Go ahead and create a file named list.ex. Open this file in your favorite text editor and write the following code in it:

list1 = [1, true, 3, "four", 5.0]
list2 = [ [0, 1], 1, 2.0]

IO.inspect(list1)
IO.inspect(list2)

Let’s run this program, and then I’ll explain. Use the following command to run the program:

$ elixir list.ex 
[1, true, 3, "four", 5.0]
[[0, 1], 1, 2.0]

Explanation

  • The first two lines define the lists list1 and list2, each containing values of different types. Even further, list2 contains a list!
  • Here, we also define true and 5.0. These are examples of the Boolean and Floating-point data types in Elixir.
  • Finally, we cannot directly print the List data type values using the IO.puts function. That’s why we use a specialized function IO.inspect to inspect and print the values of list1 and list2.

---

Elixir Pt. 2

Friday, January 3, 2025

Elixir is a dynamic programming language. Assign the value to a variable, and you’re good to go.

Go ahead and create a new file named var.ex and write the following code in it:

name = "Bruce"
age = 26

IO.puts("Hi " <> name <> ".")
IO.puts("You're " <> Integer.to_string(age) <> " years old.")

Let’s run this program, and then I’ll explain. Use the following command to run the program:

$ elixir var.ex
Hi Bruce.
You're 26 years old.

Explanation

We’ve defined two variables, name and age, with initial values of Bruce and 26, respectively.

  • Bruce is string in Elixir and due to this, all the functions associated with type String are applicable to name variable.
  • 26 is integer in Elixir and due to this, all the the functions associated with type Integer are applicable to age variable.

In the last two lines, we’re printing text to the terminal.

  • In the first printing line, we’re greeting Bruce with “Hi Bruce.”. The <> is a binary concatenation operator used to combine strings.
  • In the second printing line, we’re printing the age message as “You’re 26 years old.”. Since age is an integer, we need to convert the number into a string. To do this, we use the to_string function from the Integer module.

---

Finally, there are two other primitive data types that I haven’t covered in this article which are Boolean and floating point numbers. Boolean has true and false value and floating numbers are numbers with decimal points.

---

Elixir Pt. 1

Elixir is a dynamic, functional programming language designed for building scalable and maintainable applications. It runs on the Erlang VM (BEAM), known for its low-latency, distributed, and fault-tolerant capabilities.

---

Go ahead and create a file with the name hello_world.ex. Open this file in your favorite text editor and write the following code in it:

IO.puts("hello, world")

Let’s run this program, and then I’ll explain. To run the program, use the following command (elixir followed by the name of the program):

$ elixir hello_world
hello, world

Explanation

IO.puts is a function in the Elixir programming language that prints a string to the terminal with a newline at the end.

  • IO is the module that contains the puts function.
  • puts is the function responsible for outputting the string.

Elixir is a functional programming language that organizes code into modules, and functions are defined inside these modules. In this case, IO is the module, and puts is the function that performs the printing.

---