Solved Any disadvantages of using §?

Discussion in 'Plugin Development' started by KingFaris11, Jun 27, 2015.

Thread Status:
Not open for further replies.
  1. I've always been using, whenever sending a player a message, ChatColor.translateAlternateColorCodes('&', "&4Hi!"); but I'd prefer to start using "§" as I usually forget to type ChatColor.translateBlahBlah and then I only realise once I test the plugin. I've never used this before and I know it works, but are there any disadvantages of using this?
     
  2. Offline

    Konato_K

    @KingFaris11 Well, as far I know if your java compiles with a different encoding (or the default encoding in the system is different from the one in the file) it can cause weird characters to appear before the color code, I'm not sure how to explain it.

    I believe there are threads that talk about this, but I'm currently unable to find any.
     
  3. Offline

    1Rogue

    Instead of using the ChatColor method every time, have a method which retrieves the string from the config for you, and automatically converts it.

    Don't put unicode directly into files.
     
  4. Offline

    xTrollxDudex

    Someone who doesn't understand minecraft chat colors may not realize that the section symbol represents a color, whereas if you used ChatColor, it is apparent the usage of the section symbol.
     
  5. Offline

    justin_393

    Off topic: What exactly is Trident? Like what advantages does it have over Spigot/CraftBukkit?
     
  6. Offline

    MCMatters

  7. Yeah I think I know what you're talking about, 'aight thanks.

    True, thanks.

    Hmm, soo... Using ChatColor would do the same thing, just not make my java SRC file encode in a different format?
     
    Last edited: Jun 28, 2015
  8. Taking a look at the decompiled craftbukkit ChatColor class:
    Code:
    toString = new String(new char[] { '§', code });
      }
    
      public char getChar()
      {
        return code;
      }
    
      public String toString()
      {
        return toString;
      }
    where code is 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,k,l,m,n,o or r
    and the toString() method is called when you try to use a object in a string.
    It is actually more efficient if you just use § instead of the confusing ChatColor.translateAlternateColorCodes
     
  9. Offline

    xTrollxDudex

    Hardcoding color strings = magic numbers and letters.
     
    timtower and ferrybig like this.
  10. Offline

    mythbusterma

    @FisheyLP

    Please, show me one, just one, usage case where the difference in performance matters.


    @KingFaris11

    Also, if you're hard coding the string anyway, use ChatColor.RED or ChatColor.BLUE (for example) instead of "translateAlternateColorCodes(..)," it's much more readable that way.
     
    AdamQpzm likes this.
  11. Yeah I'm hard coding the string to send to a player, and yeah, I do that currently but even that is longer to type than "§" which does apparently the same thing, but less characters. I guess it comes down to my laziness, I just sometimes forget to use ChatColor.<x> when sending a message to a player and instead use &1 &2 etc. and only realise this when I test the plugin. It'd be easier for me to use § as I'd never make a mistake this way, but I was just avoiding it if it has any problems compared to using the ChatColor class.
     
    Last edited: Jun 28, 2015
  12. With efficient I didn't mean performance. I meant that you just need to press 3 keys instead of 15+.
    Also you can memorize the few color codes very quickly
     
  13. I typed that in my comment myself at the top (saying that you meant that you only need to press a few keys), but I thought I was making a big assumption so I edited it out xD
     
  14. I always use § lol. Much more efficient, less keys and a lot easier to create and edit.
     
    KingFaris11 and FisheyLP like this.
  15. Offline

    teej107

    And let's see how many keys get pressed after the color code changes :p
     
    Konato_K, nverdier and AdamQpzm like this.
  16. This is a very good example of how to do programming wrong. Don't decide on using something purely because of the number of key presses... Also, remembering them is only part of the problem with magic numbers anyway. They don't really mean anything, so it's not readily apparent unless you've memorised it, and there's nothing to guarantee it won't change. Maybe one day 5 will represent red instead, but RED will always represent red.

    Using ChatColour.RED + "Hello!" is more readable, and is safer against changes, should they decide to change the colour symbol, or the characters that represent the colours. Sure, you might say ChatColor.RED + "Hello!" isn't that much more readable, but the more colours you use the more it's noticeable. For example, this:

    Code:
    ChatColor.BLACK+ "H" + ChatColor.DARK_BLUE + "e" + ChatColor.DARK_GREEN + "l" + ChatColor.DARK_AQUA + "l" + ChatColor.DARK_RED + "o"
    (or with static imports: )

    Code:
    BLACK+ "H" + DARK_BLUE + "e" + DARK_GREEN + "l" + DARK_AQUA + "l" + DARK_RED + "o"
    is definitely more readable than this:

    Code:
    §0H§1e§2l§3l§4o
     
  17. Offline

    Konato_K

  18. I still don't see what's wrong with §. All ChatColor does is add a § and a letter or number to your string. It's no different at all.

    Also, if they change the symbol..

    Ctrl + F: §
    Replace All: [New Symbol]

    lol
     
    FisheyLP likes this.
  19. Offline

    1Rogue

    slight misconception, it adds this:

    Code:java
    1. String example = '\u00A7' + "8" + "your string";


    If you want to type that every time, be my guest.
     
  20. @Sulphate It becomes more effort depending on how many projects you have, though. And that still doesn't change my point about readability.
     
  21. I agree with your point on readability, I opened someone's project yesterday and he was using that symbol and I almost died internally when I saw the item name since I couldn't read it.
     
    AdamQpzm likes this.
  22. Argh. Can we stop that discussion? Everyone should use the way he likes at most. Personally I memorized all color-codes and can read them pretty good but the ChatColor.XXXX are more confusing for me. A pretty good argument is:
    • When you are on a server where you can chat in colors, you don't type ChatColor.BLAAAAA you type &*code*
     
  23. This thread is solved, so I don't think people should be commenting anymore, but here's my reply to that:

    Yes, you type it like that in chat, but once you've typed it and you look back at it, it's more confusing to read than when you typed it. You also know what colour codes you want and so you understand it more quickly, but if you don't remember the colour you're using (e.g. looking at code after a month), then it isn't. I also know all the colour codes, it's just the fact that something like the following looks hideous:
    Also, I still don't agree with Adam on the character changing thing, but that's a different thing.

    Anyway, end of discussion.
     
  24. Offline

    1Rogue

    & is not the same as §, especially when put directly into source code.
     
    Konato_K and KingFaris11 like this.
  25. You use & directly in the minecraft chat. I never had problems with putting § directly into source code
     
  26. As people have said, just use whatever method you want. It makes basically no difference. Pls no more arguments. kthxbai
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page