Thought Process Behind Writing a New Method

Break the task of writing a new method into smaller steps.

We'll cover the following

As programmers, we like to split our tasks up and do one thing after another. This allows us to focus on a tiny task, and once we’ve solved it, we move on to the next one.

When we need to add some new functionality to our program, we’ll constantly need to add methods because they are what add behavior.

Method name

The first thing we should ask is what the method should do. The answer to this gives us a hint for a good method name.

Let’s say we’re working on an application that deals with emails, and we’re specifically trying to format an email. Our method name can be format_email.

With this first task solved, knowing the method name, we can already go ahead and write down the method definition:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy