So, the “Ruby way” is to use underscores to delimit most identifiers, e.g. “add_months_to_date“, as opposed to the Java camel-case way of “addMonthsToDate“. This was initially something that irked me about Ruby, mostly because typing an underscore is kindof a pain (shift with the left hand and pinky with the other).
Now that I’ve started working, I’ve been reading a lot of code and realizing that code is more often read than written. Ultimately, camel case is a just lot harder to read (especially if you create meaningful method names like myself and my co-workers seem to do).
It’s pretty hard to defend:
Date calculatePersonDataUsageHistoryStartDate() {}
as more readable than:
def calculate_person_data_usage_history_start_date() end
The underscores are like spaces, making the identifier a lot more readable. Of course, both are more readable than:
// Calculates the start date of the
// person's data usage history
time_ prsn_dt_uhst_st_dt(){}
This would never fly with Java (and, honestly, look a bit weird), but I’m no longer gonna curse the Ruby convention.
Why wouldn’t it work with Java? OK, that’s not what the API developers do, but so what?
Sometimes for clarity it’s necessary to do both, especially when nouns can be used as adjectives. For example, firstCompany_location refers to the location of the first company (among several companies), whereas first_companyLocation refers to a company’s first location (among several locations) for a given company.
Both firstCompanyLocation and first_company_location would be ambigous.
I dunno, I think mixed is pretty ugly. First rule of modifying code is to code it as the original author did, style-wise…..