3 ms·
I have had an interview where both the (x * 8) and (x << 3) would have been frowned upon, for using a "magic number".
by bbcbasic 11y ago
I have had an interview where both the (x * 8) and (x << 3) would have been frowned upon, for using a "magic number".
- mjfisher 11y agoGood, I think? It wouldn't be a deal breaker at interview for me (or even something we test for, come to think of it), but they were right in that it is a magic number. Unless you are doing something where the context is so perfectly obvious that number should be an 8, it's better off tagged as a constant so the next dev to come along has a better chance of understanding your code.
- NickPollard 11y agoIndeed: static const int eight = 8; x * eight; Sometimes magic numbers are just that - numbers. Adding constant definitions is often a good thing, but sometimes just adds noise.
- deleted 11y ago[deleted]
- nickzoic 11y agoI think you mean static const int days_per_week = 8; :-).