...

/

Using the Right Words

Using the Right Words

Learn the importance of using the right names for variables, methods, classes, and so on.

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

Why choose better names?

Choosing good names for our variables, methods, and classes is important because this makes our code more expressive and easy to read. In fact, once we’ve learnt the basic concepts of Ruby, well-crafted code should read almost like prose. It’s 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 some great and some rather bad example names.

Consider this code:

Press + to interact
Ruby
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" })

Here, the author defines an Email class, and it takes three arguments, two of ...