views:

89

answers:

4

The standard abbreviations for decibels is "dB" (note the case!)

So, if I have a variable, holding (for instance) a maximum dB value, how best to name it?

  1. maxDbValue
  2. maxdBValue
  3. maxDecibelValue
  4. something else?

Each has disdvantages - #1 swaps the case of the unit, #2 doesn't clearly split max from dB, and #3 is verbose...

I think #1 feels best, but...???

+6  A: 

I would use maxVolume.

If I had to use one of yours, it would be maxDecibelValue.

Also, if it is a constant, it shouldn't be camelcase, it should be all caps, as in MAX_DECIBEL_VALUE.

glowcoder
+100 - solves the problem so easily...
ck
Plus- do actually know "decibels", or is it a more-arbitrary volume setting? The APIs that I'm familiar with make no mention of decibels directly since the underlying hardware is going to be doing a lot more than taking the value that I give it...
dash-tom-bang
"volume" isn't sufficiently self-descriptive. (and no, it's not a constant).
Roddy
Oh yes, I know it's decibels - This is too wonky a requirement for APIs to have much to do with it :-~
Roddy
If it's not, what prevents it from being so? Are there other measurements of volume you are using? The variable name does not need to describe everything about a variable. For example, there's nothing wrong with `float distance = 15.0f; // in meters`. It is unnecessary to put `float distanceInMeters = 15.0f`.
glowcoder
this has nothing to do with the question, but why should constants be all caps with underscores? is there some official recommendation for that?
stmax
It's standard convention to have all caps for constants, similar to starting variables with lower case and classes with upper case. See http://java.sun.com/docs/codeconv/ and click html, go to section 9.
glowcoder
@glowcoder, the naming convention you deride might have prevented at least one distaster if it were used: http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#The_metric.2Fimperial_mix-up
Mark Ransom
+3  A: 

I like #3: maxDecibelValue. It also prevents confusion with DB representing "Database."

SethO
+1  A: 

In this case, (pun not intended) the capitalization you choose for the abbreviation matters less than the gigantic body of code out there that associates 'db' with 'database'. Normally commenting variable names is a code-smell but you have an exception on your hands. If you use either #1 or #2, you might want to leave a comment to clarify what 'db' really means.

//measured in dB 

or

//sound measurement 

This is why you'll see the preference for maxDecibelValue.

Either way, I'd recommend you use whatever annotation system your language/IDE has to provide a flyover/tool-tip/etc. for the places the variable is used. That way to won't have to find the declaration to understand the name.

Kelly French
+1  A: 

I suggest to create a new type, Decibel, and then use, as glowcoder suggested, maxVolume such that the line will read:

Decibel maxVolume

It's convention not to mix name with it's type. Clearly Decibel is a type.

Working with an application that mixes units, for instance Celsius, Fahrenheit and Kelvin, what would the following mean:

temperature

Also then I suggest using the type:

Celsius temperature
or
Kelvin temperature
or
Fahrenheit temperature

The type Decibel can now also contain some helper-methods; for instance, Decibel is a logarithmic unit, so you can provide some basic arithmetic function for it.

Pindatjuh