0

In Scala is it acceptable to have id variables written as _id instead of the regular camel case notation?

In the code most variables respect the camel case notation. However for variables referring to id, I like to append _id at the end instead of Id. To me it makes it clearer and also different from other variables. Example:

let's say I have an object Employee in a case class

case class Employee(id: Long, firstName: String, lastName: String, email: String, company_id: Long, job_id: Long)

instead of

case class Employee(id: Long, firstName: String, lastName: String, email: String, companyId: Long, jobId: Long)

Thoughts?

4

Underscores in names (_) are not actually forbidden by the compiler, but are strongly discouraged as they have special meaning within the Scala syntax.

Mutators for example use the "_=" convention;

def bar_=(bar: Bar) {
    ...
}

It's (over)used in imports;

import _root_.net.liftweb._

From Scala Docs: Naming Conventions

... and so on. The main notion is that underscores have their own unique use in Scala (as opposed to other languages, e.g. Java) and should be avoided using in variable names; saved for where appropriate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.