News for hackers. Stuff that matters.
Re:Three hundred programming interviews in thirty days by bbcbasic on Tuesday June 23, 2015 @11:11PM (#9769315)
I have had an interview where both the (x * 8) and (x << 3) would have been frowned upon, for using a "magic number".
Re:Three hundred programming interviews in thirty days by mjfisher on Wednesday June 24, 2015 @02:50AM (#9770051)
Good, 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.
Re:Three hundred programming interviews in thirty days by NickPollard on Wednesday June 24, 2015 @05:04AM (#9770456)
Indeed:

  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.
Re:Three hundred programming interviews in thirty days by nickzoic on Wednesday June 24, 2015 @07:47AM (#9770922)
I think you mean

    static const int days_per_week = 8;
:-).