Why developers use config to save data, and not java serializable?

Discussion in 'Spigot Discussion' started by Erezbiox1, May 18, 2017.

  1. Apart from readability ( Which is almost never important in data files ), what advantages does config add over serializable?
    You literally can just import \ export objects in their current state, with all of their data...
  2. I've created this gist, to make it easier:
    It's pretty simple.
    in onEnable ( if you want to load that data in the server start )
    You put your object reference, for example ranks: if the object doesn't exist in the system, the serializable would use the object that you gave him, otherwise it would ignore it ( mind that if your object registers something in the constructor ), for example:
    Code (Text):
    ranks = serializable.loadOrAdd("ranks", new Ranks());
    then, in the end of the server ( onDisable ),
    Code (Text):

    also, your object must implement Serializable ( java.util )
  3. Config file is not nearly a replacement for serialization. You can use both.
    Serialization is a process of translating objects to a state which they can be safely stored and loaded from.
    • Like Like x 1
  4. You are not answering the question, I know all of that, the question, once again, is why do developers use config file to store internal data?
  5. It seems like you are not reading my answer.
    Where should they store it if not on a file? (Assuming that DB are not count)
  6. Obviously there's better ways to store data, but It's mostly used by devs here because preference perhaps and it is what's mostly taught on this forum to use.
  7. They should store it in a file ( or a db ), just saying why store it as a bukkit config, when they can use java serialized byte file?
  8. Someone needs to change that 0.0
  9. The question is what objects are you talking about? Many configurations need to readable by human and they need to edit them in most cases.
  10. - easier to pick up
    - easier to debug (by simply checking whats being written to the file, instead of having to read and print it again)
    - adds the option for users to manually alter some data
    - no significant noticable performance penalty (maybe if youre talking about reading data on login on busy servers, but then a db is usually better anyways...)
  11. I have only 1 for you.
    - Easier to develop.
    in some plugins there is hundreds of lines dedicated to turn an object to a string, when you can literally do
    save(object, fileName);

    What??? How is that easier to understand???
    What is the problem with printing it out of the object?
    As I said before, serialization for internal data. also, why would a user want to change something like this?:
  12. ..
  13. WAS


    I use serialization for anything that I do not feel the user needs to be tampering with. For example WeChat caches it's user map and room map to keep it persistent with server restarts. From the get go I had this in mind. I knew I could easily do this in a config, but I thought "Why?" It's a lot more work parsing the data to YAML, and back. If I were to use a read-able state, I'd use JSON Objects over a YAML Config. That imo is for... configuration. :p Assigning user-definable fields, etc.

    He means data, not configuration. In that instance the user should not be editing the data. Pretty much all plugins I've seen in the past that do use data make it clear you should not be editing the data files, and even in some cases the config. For example, it's discourage to edit PEX permission file directly.
    • Like Like x 1
  14. - using configs/fileconfigurations is taught in basic bukkit development, as its needed for the config (duh). Basic java isnt (understand that a lot of plugin devs never take java courses or anything), thus its more complicated to develop for this audience.
    Also theres a shocking amount of plugin developers that dont learn how to make their own objects for a shockingly long time...
    - see above
    - Its a step extra in debugging...
    - fair point.

    I honestly dont care if someone uses the one or the other, theres pros and cons to both. Just giving reasons why I can see a lot of devs on here using FileConfigurations more :)
  15. I'm using serializable. Its so much easier and quicker to use, and I don't have to keep updating some stupid configuration files. It's all done automaticly. I cannot think of a single reason why configuration is better than serializing.
    • Like Like x 2
  16. agreed :)
  17. WAS


    Its literal only purpose is when I have something the user must define. What color is the sky? Haha
  18. then my question is, why de hek, developers, professional developers, use this to save stuff?
  19. TheJavaHacker


    they do it because people on here, whom aren't developers need a way to edit and modify the plugin configuration, in which a config flatfile is the best option.
    • Agree Agree x 1
  20. WAS


    Again this is not the case. We are talking about data. Not configuration.

    There is no reason a person should be editing data. In a lot of case you'll see error reports because they manually try editing something rather than doing it how it's documented or with commands provided, etc.

    For example some loot systems use their loot table and double it as the chest data store. This could be two separate systems. The loot configuration with identifying markers to chest types, and a cache where the actual data from active chests.
    • Like Like x 1
    • Agree Agree x 1