Elixir is a functional language - does that mean Elixir can’t handle or run scripts in a procedural way?

Hi, sorry if my question sounds basic. I got interested in Elixir because my senior suggested it as my first programming language. I started learning by reading Joy of Elixir. It emphasizes that Elixir is a functional language. Does that mean Elixir can’t handle or run scripts in a procedural way? For example, if I want to create a script that combines git add, commit, and push into one command using a procedural approach?

Again, sorry if this is too basic. I’m just starting to focus on programming this month. My background is in communications, not IT, but I want to make a career switch and become a programmer. Hopefully, I can become a professional elixir programmer in the future.

1 Like

Hey Saiba, welcome to the forum!
Elixir is quite flexible and can accommodate various programming styles, including procedural approaches when needed.

Here’s a simple example of how you might write such a script in Elixir:

defmodule GitHelper do
  def add_commit_push(message) do
    System.cmd("git", ["add", "."])
    System.cmd("git", ["commit", "-m", message])
    System.cmd("git", ["push"])
    IO.puts("Changes added, committed, and pushed successfully!")
  end
end

# Usage
GitHelper.add_commit_push("Update project files")
10 Likes

thanks @bartblast for the answer.

1 Like