Skip to contentSkip to conversation

BUFSIZ vs magic numbers and co.

DISCUSSION Alejandro Colomar 2 participants 4 messages Sep 7, 2020 – Sep 8, 2020 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

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 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).

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/
#2 lore raw
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.

#3 lore raw
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/