DEV Community

Discussion on: What are the great function/method/etc. names in popular libs/languages?

Collapse
 
burdettelamar profile image
Burdette Lamar

I love Ruby's naming conventions foo? and foo!.

The former is for a method that returns a boolean (like IsFoo in some languages):

irb(main):006:0> s = 'abc'
=> "abc"
irb(main):007:0> s.empty?
=> false

The latter for a method that may do something possibly unexpected, such as modifying a given argument:

irb(main):001:0> s = 'abc'
=> "abc"
irb(main):002:0> s.reverse
=> "cba"
irb(main):003:0> s
=> "abc"
irb(main):004:0> s.reverse!
=> "cba"
irb(main):005:0> s
=> "cba"