Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have had an interview where both the (x * 8) and (x << 3) would have been frowned upon, for using a "magic number".


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.


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.


I think you mean

    static const int days_per_week = 8;
:-).




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: