You Are Using Old Technology
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
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
tuple1andtuple2, each containing values of different types. Even further,tuple2contains a tuple! - Finally, as we know, we cannot use the
IO.putsfunction to print the composite data type values. Instead, we have used the sameIO.inspectfunction to inspect and print the values oftuple1andtuple2.
---
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
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
list1andlist2, each containing values of different types. Even further,list2contains a list! - Here, we also define
trueand5.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.putsfunction. That’s why we use a specialized functionIO.inspectto inspect and print the values oflist1andlist2.
---
Elixir Pt. 2
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.
Bruceis string in Elixir and due to this, all the functions associated with typeStringare applicable tonamevariable.- 26 is integer in Elixir and due to this, all the the functions associated with type
Integerare applicable toagevariable.
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
agemessage as “You’re 26 years old.”. Sinceageis an integer, we need to convert the number into a string. To do this, we use theto_stringfunction from theIntegermodule.
---
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.
IOis the module that contains theputsfunction.putsis 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.
---