...

/

Using the Right Words

Using the Right Words

This lesson demonstrates the importance of using the right names for variables, methods, classes, and whatnot!

Naming things is hard

Just like programmers are obsessed about formatting, they also care a lot about how to name the things they create.

Why to choose better names?

Choosing good names for your variables, methods, and classes, is important because this makes your code more expressive and easy to read. In fact, once you’ve learned the basic concepts of Ruby, a well-crafted code will read almost like a prose text to you. Not necessarily like your favorite novel, but maybe like a recipe or other instructional prose. Ruby is particularly great for writing expressive, readable code.

Here are a few examples of great, and rather bad names to pick.

Consider this code:

Press + to interact
class Email
def initialize(str, string2, headers_hash)
# ...
end
# more methods ...
end
puts an_email = Email.new("Hi there, Ruby Monstas!", "2015-01-02", { :from => "Ferdous" })

From looking at the first two lines of this code you can figure out that the author defines an Email class, and it takes 3 arguments, two of which probably are supposed to be strings, and one is a hash containing some headers.

But what’s the purpose of the first two arguments? All we know the ...

Create a free account to access the full course.

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