Just released - The Imposter's Roadmap! Go Get It

Calculating Escape Velocity

Buy or Subscribe

You can access this course in just a minute, and support my efforts to rid the world of crappy online courses!

Buy Standalone  Subscribe

Look I'll be honest: you and I are in a battle for our jobs. When you were brought on board I thought we had this Elixir project all sewn up but then we get a new CTO who happens to love .NET and would like nothing more than for us to fail.

I hate to put you in this position, but I think you have what it takes. Prove me right. Now let's write some code.

Organizing the Project

Open up the Physics project in your favorite editor. We need to create a module that will contain the functions we'll need to calculate Escape Velocity (EV). Let's call ours rocketry:

touch lib/physics/rocketry.ex

Every app in Elixir is made up of smaller apps and modules. Organizing these modules can be tricky, but an agreed-upon rule is that you have an "entry module" with the same name as your app. This typically goes in the lib directory. The modules that you write for your app go in a directory with the same name.

Now let's define our module:

defmodule Physics.Rocketry do
  #code here
end

Here I've defined a namespace for the module that follows the structure of our directories. The .NET and Java people will find this a familiar thing. Using namespaces helps keep modules organized.