BUFSIZ vs magic numbers and co.
Hi Michael,
There are a lot of EXAMPLES where buffers are created. In those examples, usually there is either a magic random number (e.g., 100, 500, 1000) or a custom macro such as #define BUF_SIZE 500.
Those examples could all use BUFSIZ from <stdio.h>, which would reduce code (not having to define the macro), and be more consistent (not having a random magic number in each example).
However, I see a slightly good point in having magic numbers in the examples section: a novice reader could infer that you are focrced to use BUFSIZ if it's written all over the place, while if there is a random magic number, the reader probably will deduce that he can use any number.
What do you think about it? Would it be better to consistently use BUFSIZ, or just keep the magic numbers?
Regards,
Alex.
Hi Alex,
Quoted 11 lines · Alejandro Colomar
Hi Michael,
There are a lot of EXAMPLES where buffers are created. In those examples, usually there is either a magic random number (e.g., 100, 500, 1000) or a custom macro such as
#define BUF_SIZE 500.Those examples could all use
BUFSIZfrom <stdio.h>, which would reduce code (not having to define the macro), and be more consistent (not having a random magic number in each example).
Quoted 5 lines
However, I see a slightly good point in having magic numbers in the examples section: a novice reader could infer that you are focrced to use BUFSIZ if it's written all over the place, while if there is a random magic number, the reader probably will deduce that he can use any number.
Yes, I think that's a good point. There's nothing magical about BUFSIZ; it relates just to stdio.
Quoted 2 lines
What do you think about it? Would it be better to consistently use BUFSIZ, or just keep the magic numbers?
Keep the magic numbers, I would say.
Cheers,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 3 lines · Michael Kerrisk (man-pages)
Yes, I think that's a good point. There's nothing magical about BUFSIZ; it relates just to stdio.
Yes, I meant about stdio related examples such as fopencookie.3, but still it might be better to keep the magic numbers in those cases.
Cheers,
Alex.
Quoted 8 lines · Alejandro Colomar
Quoted 3 lines · Michael Kerrisk (man-pages)
Yes, I think that's a good point. There's nothing magical about BUFSIZ; it relates just to stdio.
Yes, I meant about stdio related examples such as fopencookie.3, but still it might be better to keep the magic numbers in those cases.
Yes.
Thanks,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/