On Sep 3, 2015 4:17 AM, "Domingo Alvarez Duarte" <sqlite-mail at dev.dadbiz.es> wrote: > > Hello ! > > I was looking at this particular commit > https://www.sqlite.org/src/info/0ea6e5c9fc6b1dd1 then I realize the usage of > magic number through sqlite3 source code like the one bellow, it's not good > practice to avoid then ?
Generally yes, but like most decisions made in programming, there are exceptions. Much like goto: avoid it when nothing better is available, but use it when it is the right tool. Besides, I have seen code that is harder to read when certain magic numbers are replaced by named constants. It isn't common, but it happens. > > Cheers ! > > ===== case PragTyp_STATS: { static const char *azCol[] = { "table", > "index", "width", "height" }; Index *pIdx; HashElem *i; v = > sqlite3GetVdbe(pParse); pParse->nMem = 4; ///////first appearance of > the a magic number (sizeof(azCol)/sizeof(char*)) > sqlite3CodeVerifySchema(pParse, iDb); setAllColumnNames(v, 4, azCol); > //////// second appearance of a magic number described above > for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ > Table *pTab = sqliteHashData(i); sqlite3VdbeAddOp4(v, OP_String8, 0, > 1, 0, pTab->zName, 0); sqlite3VdbeAddOp2(v, OP_Null, 0, 2); > sqlite3VdbeAddOp2(v, OP_Integer, > (int)sqlite3LogEstToInt(pTab->szTabRow), 3); sqlite3VdbeAddOp2(v, > OP_Integer, > > ===== > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users