What's a "magic value"?

Discussion in 'Bukkit Discussion' started by Matthew Broomfield, Sep 5, 2013.

Thread Status:
Not open for further replies.
  1. In one of the recent Development Builds for Bukkit, all "magic values" have become deprecated.

    So, what exactly is a "magic value"?
     
  2. Offline

    Lolmewn

    Where did you find this? There should be a link next to it, either pointing to an issue or to a commit. Those will probably explain.
     
  3. Offline

    Rocoty

    So, basically, what the wiki is saying, is that the Bukkit team has deprecated methods with the reason "Magic Number" while Item IDs clearly are NOT magic numbers. F**k this.

    EDIT: And why would they deprecate magic numbers anyway?
     
    mine-care likes this.
  4. Offline

    Me4502

    Magic values are values that do not clearly demonstrate what they represent, eg, an item ID. They have deprecated these as minecraft changes could easily break the ID system, and they wish for people to use the bukkit API Enum equivalents that currently exist. For example, using the Material type instead of block ids.

    Edit: The wiki explains it as this meaning,
    Note: I believe they should still have the option to get a Material from an ID, but not vice versa - Allows for easy conversions or players using IDs in commands/configs.
     
  5. Offline

    deltahat

    Part of the problem with "magic value" ids is that they are typeless numbers, so the compiler can't help you catch mistakes. You could easily read a material id and assign it to a crop state id. Additionally, Mojang could change all the id values in the next release and your code would still compile, but subtly break because all your hard coded ids don't line up with what you expected anymore. Changing ids pose a serious problem for your plugin's users because the plugin will still "work" (no exceptions) after an Minecraft upgrade but will behave unexpectedly and possibly destructively. Using named constants wherever possible solves both of these problems.
     
    Wolvereness likes this.
  6. Offline

    lol768

    Pretty sure the id system is completely changing with 1.7 anyway
     
Thread Status:
Not open for further replies.

Share This Page