I'm modeling a chemical system, and I'm having problems with naming my elements / items within an enum.
I'm not sure if I should use:
- the atomic formula
- the chemical name
- an abbreviated chemical name.
For example, sulfuric acid is H2SO4 and hydrochloric acid is HCl.
With those two, I would probably just use the atomic formula as they are reasonably common.
However, I have others like sodium hexafluorosilicate which is Na2SiF6.
In that example, the atomic formula isn't as obvious (to me) but the chemical name is hideously long: myEnum.SodiumHexaFluoroSilicate
. I'm not sure how I would be able to safely come up with an abbreviated chemical name that would have a consistent naming pattern.
There are a few problems that I'm trying to address through naming the enum elements.
The first is readability, with the longer names presenting an issue.
The second is ease of picking up the code for new maintainers, and here the shorter names present an issue.
The next issue is the that business owners usually refer to the full chemical name, but not always. The "mouthful" chemicals are referred to by their formula.
The final concern is making sure it's consistent. I don't wan't a mixed naming convention as it will be impossible to remember which to use.
From a maintenance point of view, which of the naming options above would you prefer to see and why?
Note: Everything here below the line is supplementary | clarifying material. Please don't get bogged down in it. The main question regards naming the awkward objects.
Atomic Option
public myEnum.ChemTypes { H2SO4, HCl, Na2SiF6 }
Chemical Name Option
public myEnum.ChemTypes { SulfuricAcid, HydrochloricAcid, SodiumHexafluorosilicate }
Here are some additional details from the comments on this question:
- Audience for the code will be just programmers, not chemists.
- I'm using C#, but I think this question is more interesting when ignoring the implementation language.
- I'm starting with 10 - 20 compounds and would have at most 100 compounds, so I don't need to worry about every possible compound. Fortunately, it's a fixed domain.
The enum is used as a key for lookups to facilitate common / generic chemical calculations - which means that the equation is the same for all compounds but you insert a property of the compound to complete the equation.
- For example, Molar mass (in g/mol) is used when calculating the number of moles from a mass (in grams) of the compound. FWIW, Molar Mass == Molar Weight.
- Another example of a common calculation is the Ideal Gas Law and its use of the Specific Gas Constant
A sample function might look like:
public double GetMolesFromMass(double mass_grams, myEnum.ChemTypes chem) { double molarWeight = MolarWeightLookupFunctionByChem(chem); //returns grams / mole double moles = mass / molarWeight; //converts to moles return moles; } //Sample Call: myMoles = GetMolesFromMass(1000, myEnum.ChemTypes.Na2SiF6); //*or* myMoles = GetMolesFromMass(1000, myEnum.ChemTypes.SodiumHexafluorosilicate);
public double GetSpecificGravity(myEnum.ChemTypes chem, double conc) { //retrieves specific gravity of chemical compound based upon concentration double sg = SpecificGravityLookupTableByChem(chem, conc); }
So the enum of the compound name is used as a key and to provide consistency in referencing the compound with the related functions.
Substance
with whatever properties they need.