I think Domingo is showing signs of cargo-culting, simply taking some mantra to 
the extreme without even realizing the point of the mantra.

Logically speaking, enumerated values like this 'simple'/'tuple' are program 
identifiers in the same way as variable or field names are.  These enums are 
part of the code, not part of the data.  It makes as much sense to replace them 
with numbers as it is to give all variables and fields names that are numbers, 
because you don't want to repeat the variable/etc names all over the place.

The DRY concept is not meant to say use only numbers for enums.  In this 
particular case, using identifiers, which are strings, is the correct course of 
action.

DRY is better applied where the subject may be mutable like data, such as a 
person's name, not where it is code like these enums.

When I say like code, I mean that presumably with these 'simple'/'tuple' there 
are various places in the application that specifically dispatch different 
logic 
depending on those values, whereas with data, such as an enumeration of country 
names, it would not be the case.

-- Darren Duncan

On 2015-11-25 7:14 AM, Simon Slavin wrote:
> On 25 Nov 2015, at 2:23pm, Domingo Alvarez Duarte <sqlite-mail at 
> dev.dadbiz.es> wrote:
>
>> This way we repeat the string everywhere then it's not DRY !
>
> You know, I think you're the first person to mention DRY here.  I had to look 
> it up.
>
> <https://en.wikipedia.org/wiki/Don%27t_repeat_yourself>
>
> For some reason it seems that under DRY repeating a string in lots of places 
> is bad, but repeating a number in lots of places is good.  I'm not sure about 
> the logic behind that.
>
> Okay, do this instead:
>
> CREATE TABLE enum_type (the_ID INTEGER PRIMARY KEY, the_value TEXT UNIQUE);
> INSERT INTO enum_type (the_value) VALUES ('simple'), ('tuple');
>
> CREATE TABLE use_mytype (...
>     ...
>     one_type TEXT REFERENCES enum_type(theID) DEFAULT 2
> )
>
> It is now harder to know which value to insert for one_type.

Reply via email to