nozavroni / csvelte

🕺🏻 CSV and Tabular Data library for PHP
http://phpcsv.com/
Other
6 stars 0 forks source link

Should I change Flavor class constant QUOTE_* values? #86

Closed nozavroni closed 6 years ago

nozavroni commented 8 years ago

I never know what to use as values for class constants I'm using as flags or whatever. In cases like this where I'm just using a constant as a level of abstraction/consistent flag name... the value, to me, seems irrelevant. So long as it's unique. In the past I've opted for text values because they can describe themselves without the need for the constant (for instance, when I var_dump a flavor, the value for $quoteStyle is "quote_all" rather than like "3"). But in every other library I've seen (with the exception of js-redux, which uses string values identical to the constant name), they use integer values. Sometimes they even use factorials of 2 so that they can do bitwise logic. That is definitely not necessary in this particular case because quoteStyle can only be one of four possible values. Although now that I think about it, I suppose technically QUOTE_MINIMAL | QUOTE_NONNUMERIC makes sense (quote if it has special char or if it is non-numeric) and so does QUOTE_MINIMAL & QUOTE_NONNUMERIC (quote if it is non-numeric AND has special chars) even QUOTE_MINIMAL ^ QUOTE_NONNUMERIC (quote if it is non-numeric OR has special chars but not both). But I digress. What I'm wondering is, is there any particular reason to go with integer values as my constant values in this case? Does it add any value or is it simply the accepted practice, so people do it? Do some research on it and if it adds value, change the values to the same as their Python counterparts.

nozavroni commented 6 years ago

I changed them to 0-3