Building Single Purpose Functions

Let’s learn how to use single-purpose functions to build our project.

As we start to build our quiz, we will focus on two basic concepts. First, we’ll try to make each function take on one single task, however simple. Second, functions should be relatively short… Along the way, we can examine other principles of good design. Decoupling concepts is a foundational concept for any programming, regardless of language.

Building our quiz

Let’s put this advice into practice as we build our quiz. Recall our initial structure for quizzes. We have the following:

  • The struct

  • The constructor

  • The common aliases

We’ll add this to /lib/mastery/core/quiz.ex:

Get hands-on with 1200+ tech skills courses.