Pregunta

I'm using the HNC in this way for variables in PHP: $p_nId. p stands for parameter, so the scope of the variable, n for the type (though PHP is loosely typed, it gives some structure), so numeral here. Is there a type prefix in the HNC for a mixed type as well?

¿Fue útil?

Solución

As far as I know, there is no standard set of abbreviations for Hungarian Notation, so you can just decide on your own (ensuring they are documented appropriately, of course!)

You may want to think carefully about what you want to indicate in your notation, however, rather than thinking in terms of base data types. For instance, an ID may be an integer, but $foo = $id +10 isn't likely to be a meaningful operation, so a HN which captures this distinction may be more useful.

Where you have a "mixed type" variable, it's likely that you actually know that it is one of a limited set of types - either a string or an array, say, but never a number or object. In that case, perhaps your HN should capture that information, rather than simply labeling the variable as "type unknown".

Edit: I just found a link to Charles Simonyi's original paper outlining the concepts, and skimming through I see that he does indeed suggest types should be related to their use, not their representation:

The test for type equivalence is simple: could the same set of operations be meaningfully applied to the quantities in questions? If so, the types are thought to be the same. If there are operations that apply to a quantity in exclusion of others, the type of the quantity is different.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top