You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Stas Bekman <st...@stason.org> on 2004/05/22 03:02:36 UTC

enum and defines naming

Before apr 1.0 is cast in stone any chance public enums and defines will get 
sensible names?

e.g. take a look at:

typedef enum {
     APR_NOFILE = 0,     /**< no file type determined */
     APR_REG,            /**< a regular file */
     APR_DIR,            /**< a directory */
     APR_CHR,            /**< a character device */
     APR_BLK,            /**< a block device */
     APR_PIPE,           /**< a FIFO / pipe */
     APR_LNK,            /**< a symbolic link */
     APR_SOCK,           /**< a [unix domain] socket */
     APR_UNKFILE = 127   /**< a file of some other unknown type */
} apr_filetype_e;

It all looks nice in the declaration but in the code, one needs to scratch the 
head to figure out what APR_REG means. Why not have /^APR_FILETYPE_/ prefix? 
APR_FILETYPE_REG requires no head scratching when reading the code and won't 
collide with some other enum with a totally different functionality.

Same goes for defines, for example:

#define APR_UREAD       0x0400 /**< Read by user */
#define APR_UWRITE      0x0200 /**< Write by user */
#define APR_UEXECUTE    0x0100 /**< Execute by user */

#define APR_GREAD       0x0040 /**< Read by group */
#define APR_GWRITE      0x0020 /**< Write by group */
#define APR_GEXECUTE    0x0010 /**< Execute by group */

#define APR_WREAD       0x0004 /**< Read by others */
#define APR_WWRITE      0x0002 /**< Write by others */
#define APR_WEXECUTE    0x0001 /**< Execute by others */

There are all related to files, why pollute the namespace with such short 
names and not fix them to have a sensible prefix similar to above suggestion? 
/^APR_FILETYPE_/ as in APR_FILETYPE_UREAD.

Further down in the same file we find:

#define APR_FINFO_LINK   0x00000001 /**< Stat the link not the file itself if 
it is a link */
#define APR_FINFO_MTIME  0x00000010 /**< Modification Time */
#define APR_FINFO_CTIME  0x00000020 /**< Creation Time */
#define APR_FINFO_ATIME  0x00000040 /**< Access Time */
...

which looks great!

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: enum and defines naming

Posted by Graham Leggett <mi...@sharp.fm>.
Stas Bekman wrote:

> Before apr 1.0 is cast in stone any chance public enums and defines will 
> get sensible names?

+1

I am all for legibility...

Regards,
Graham
--

Re: enum and defines naming

Posted by Stas Bekman <st...@stason.org>.
Anybody?

Stas Bekman wrote:
> William A. Rowe, Jr. wrote:
> 
>> At 08:02 PM 5/21/2004, Stas Bekman wrote:
>>
>>> Before apr 1.0 is cast in stone any chance public enums and defines will
>>> get sensible names? It all looks nice in the declaration but in the 
>>> code,
>>> one needs to scratch the head to figure out what APR_REG means. Why not
>>> have /^APR_FILETYPE_/ prefix? APR_FILETYPE_REG requires no head
>>> scratching when reading the code and won't collide with some other enum
>>> with a totally different functionality.
>>
>>
>>
>> +1
>>
>>
>>> Same goes for defines, for example: There are all related to files, why
>>> pollute the namespace with such short names and not fix them to have a
>>> sensible prefix similar to above suggestion? /^APR_FILETYPE_/ as in
>>> APR_FILETYPE_UREAD.
>>
>>
>>
>>
>> +1 again.  This is why 1.0 isn''t ready just yet, IMHO :)
> 
> 
> Thanks. So what's the next step? How one performs this kind of rename? I 
> have seen that done with functions, not sure how does it work for enums. 
> I guess defines are the same as functions.
> 
> Should it be s/APR_/APR_FILETYPE_/ and s/APR_/APR_FINFO_/ or something 
> else? Like so?
> 
> typedef enum {
>     APR_FILETYPE_NOFILE = 0,     /**< no file type determined */
>     APR_FILETYPE_REG,            /**< a regular file */
>     APR_FILETYPE_DIR,            /**< a directory */
>     APR_FILETYPE_CHR,            /**< a character device */
>     APR_FILETYPE_BLK,            /**< a block device */
>     APR_FILETYPE_PIPE,           /**< a FIFO / pipe */
>     APR_FILETYPE_LNK,            /**< a symbolic link */
>     APR_FILETYPE_SOCK,           /**< a [unix domain] socket */
>     APR_FILETYPE_UNKFILE = 127   /**< a file of some other unknown type */
> } apr_filetype_e;
> 
> 
> 
> #define APR_FINFO_UREAD       0x0400 /**< Read by user */
> #define APR_FINFO_UWRITE      0x0200 /**< Write by user */
> #define APR_FINFO_UEXECUTE    0x0100 /**< Execute by user */
> 
> #define APR_FINFO_GREAD       0x0040 /**< Read by group */
> #define APR_FINFO_GWRITE      0x0020 /**< Write by group */
> #define APR_FINFO_GEXECUTE    0x0010 /**< Execute by group */
> 
> #define APR_FINFO_WREAD       0x0004 /**< Read by others */
> #define APR_FINFO_WWRITE      0x0002 /**< Write by others */
> #define APR_FINFO_WEXECUTE    0x0001 /**< Execute by others */
> 
> 


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: enum and defines naming

Posted by Stas Bekman <st...@stason.org>.
William A. Rowe, Jr. wrote:
> At 08:02 PM 5/21/2004, Stas Bekman wrote:
> 
>> Before apr 1.0 is cast in stone any chance public enums and defines will
>> get sensible names? It all looks nice in the declaration but in the code,
>> one needs to scratch the head to figure out what APR_REG means. Why not
>> have /^APR_FILETYPE_/ prefix? APR_FILETYPE_REG requires no head
>> scratching when reading the code and won't collide with some other enum
>> with a totally different functionality.
> 
> 
> +1
> 
> 
>> Same goes for defines, for example: There are all related to files, why
>> pollute the namespace with such short names and not fix them to have a
>> sensible prefix similar to above suggestion? /^APR_FILETYPE_/ as in
>> APR_FILETYPE_UREAD.
> 
> 
> 
> +1 again.  This is why 1.0 isn''t ready just yet, IMHO :)

Thanks. So what's the next step? How one performs this kind of rename? I have 
seen that done with functions, not sure how does it work for enums. I guess 
defines are the same as functions.

Should it be s/APR_/APR_FILETYPE_/ and s/APR_/APR_FINFO_/ or something else? 
Like so?

typedef enum {
     APR_FILETYPE_NOFILE = 0,     /**< no file type determined */
     APR_FILETYPE_REG,            /**< a regular file */
     APR_FILETYPE_DIR,            /**< a directory */
     APR_FILETYPE_CHR,            /**< a character device */
     APR_FILETYPE_BLK,            /**< a block device */
     APR_FILETYPE_PIPE,           /**< a FIFO / pipe */
     APR_FILETYPE_LNK,            /**< a symbolic link */
     APR_FILETYPE_SOCK,           /**< a [unix domain] socket */
     APR_FILETYPE_UNKFILE = 127   /**< a file of some other unknown type */
} apr_filetype_e;



#define APR_FINFO_UREAD       0x0400 /**< Read by user */
#define APR_FINFO_UWRITE      0x0200 /**< Write by user */
#define APR_FINFO_UEXECUTE    0x0100 /**< Execute by user */

#define APR_FINFO_GREAD       0x0040 /**< Read by group */
#define APR_FINFO_GWRITE      0x0020 /**< Write by group */
#define APR_FINFO_GEXECUTE    0x0010 /**< Execute by group */

#define APR_FINFO_WREAD       0x0004 /**< Read by others */
#define APR_FINFO_WWRITE      0x0002 /**< Write by others */
#define APR_FINFO_WEXECUTE    0x0001 /**< Execute by others */


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: enum and defines naming

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 08:02 PM 5/21/2004, Stas Bekman wrote:
>Before apr 1.0 is cast in stone any chance public enums and defines will get sensible names?
>It all looks nice in the declaration but in the code, one needs to scratch the head to figure out what APR_REG means. Why not have /^APR_FILETYPE_/ prefix? APR_FILETYPE_REG requires no head scratching when reading the code and won't collide with some other enum with a totally different functionality.

+1

>Same goes for defines, for example:
>There are all related to files, why pollute the namespace with such short names and not fix them to have a sensible prefix similar to above suggestion? /^APR_FILETYPE_/ as in APR_FILETYPE_UREAD.


+1 again.  This is why 1.0 isn''t ready just yet, IMHO :)