Your old code...

Discussion in 'Spigot Discussion' started by NavyDev, May 31, 2017.

  1. Anyone else look at their own code and shudder?

    I look at some of my early plugins that I haven't updated in a while and it actually makes me feel ill with how bad the quality is lol..
     
  2. Choco

    Junior Mod

    I actually hate myself for this... but this was the first commit I ever pushed to one of my older projects (I still maintain it to this day, but it's obviously a lot better now). I look back at this and think to myself, "What in the world was I doing... could I even program?"

    https://bitbucket.org/2008Choco/alchemicalarrows/commits/46125c3432c529eefb55fffbf80de6ffaaf88352

    My biggest pet peeve about the above code is that I closed EVERY... SINGLE... BRACKET... WITH A COMMENT... I actually want to just hide in a hole. I promise, my code habits are trillions of times better now.

    (I EVEN PUSHED UP THE .class FILES AND .classpath / .project!!!)
     
    • Agree Agree x 1
  3. A lot better now ;)

    You have to start from somewhere amirite. Besides that comment thing, apparently that's "good practice" according to the 'education' system over here. Not that I learned java from it. I learned python. Which about sums it all up lol

    I'm recoding my whole boxing plugin because... Well.. Its shit. How on earth it has 5 reviews with 5* i'll never know ¯\_(ツ)_/¯
     
  4. Oldest repository I could find: https://github.com/stefvanschie/poll/blob/master/Polls.java (it links to a file, the only file of that project...).
    There is so many stuff wrong in this file, I'm not even gonna count it.
    It does follow the 'one-exit point' principle and now I know why I hate that.
     
  5. well just take a look at the source for the older KillerRewards versions

    I rewrote the reward code for every mob in the game...
     
  6. It's a lot more interesting to look at bad code than I thought @antiPerson @Stef lol

    I guess I should give an example. This one is really simple but its much better code through principle. I picked this because it's what I have open at the moment,

    Code (Text):
     
                            if (target == PKiller){
                                String message = Files.getMessagesData().getString("Player-Win-Message").replaceAll("[winner]", target.getName()).replaceAll("[loser]", player.getName());
                                plugin.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&f[&4Boxing&f] " + message));
                                player.setHealth(20);
                                target.setHealth(20);
                                player.setMaxHealth(20);
                                target.setMaxHealth(20);
                                TargetUUID  = target.getUniqueId().toString();
                                PlayerUUID  = player.getUniqueId().toString();
                                TargetName = target.getName();
                                PlayerName = player.getName();
                                me.navy12333.boxing.BoxingMain.TargetWin();
                             
                            }
                            else if (player == TKiller){
                                String message = Files.getMessagesData().getString("Player-Win-Message").replaceAll("[winner]", target.getName()).replaceAll("[loser]", player.getName());
                                plugin.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&f[&4Boxing&f] " + message));
                             
                                player.setHealth(20);
                                target.setHealth(20);
                                player.setMaxHealth(20);
                                target.setMaxHealth(20);
                                TargetUUID  = target.getUniqueId().toString();
                                PlayerUUID  = player.getUniqueId().toString();
                                me.navy12333.boxing.BoxingMain.PlayerWin();
                            }
                            else if (player.getHealth() > target.getHealth()) {
                         
                                plugin.getServer().broadcastMessage((ChatColor.WHITE + "[" + ChatColor.RED + "Boxing" + ChatColor.WHITE + "] " + ChatColor.DARK_GREEN + player.getDisplayName() + ChatColor.BLUE + " just beat " + ChatColor.DARK_GREEN + target.getDisplayName() + ChatColor.BLUE + " in a boxing match!"));
                                player.setHealth(20);
                                target.setHealth(20);
                                player.setMaxHealth(20);
                                target.setMaxHealth(20);
                                TargetUUID  = target.getUniqueId().toString();
                                PlayerUUID  = player.getUniqueId().toString();
                                me.navy12333.boxing.BoxingMain.PlayerWin();
                            }
                            else {
                                plugin.getServer().broadcastMessage((ChatColor.WHITE + "[" + ChatColor.RED + "Boxing" + ChatColor.WHITE + "] " + ChatColor.DARK_GREEN + target.getDisplayName() + ChatColor.BLUE + " just beat " + ChatColor.DARK_GREEN + player.getDisplayName() + ChatColor.BLUE + " in a boxing match!"));
                                player.setHealth(20);
                                target.setHealth(20);
                                player.setMaxHealth(20);
                                target.setMaxHealth(20);
                                TargetUUID  = target.getUniqueId().toString();
                                PlayerUUID  = player.getUniqueId().toString();
                                me.navy12333.boxing.BoxingMain.TargetWin();
                         
                         
                                }

    Code (Text):
        public void decideWinner(Player playerOne, Player playerTwo) {
         
            if (diedDuringFight.contains(playerOne.getUniqueId().toString()) && diedDuringFight.contains(playerTwo.getUniqueId().toString()) ) {      
                //draw
                String message = Files.getMessagesData().getString("Players-Draw-Message").replaceAll("[playerOne]", playerOne.getName()).replaceAll("[playerTwo]", playerTwo.getName());
                Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&f[&4Boxing&f] " + message));  
            }
            else if (playerOne.getHealth() == playerTwo.getHealth()) {
                //draw
                String message = Files.getMessagesData().getString("Players-Draw-Message").replaceAll("[playerOne]", playerOne.getName()).replaceAll("[playerTwo]", playerTwo.getName());
                Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&f[&4Boxing&f] " + message));  
            }
            else if (playerOne.getHealth() > playerTwo.getHealth()) {
                //playerOne win
                String message = Files.getMessagesData().getString("Player-Win-Message").replaceAll("[winner]", playerOne.getName()).replaceAll("[loser]", playerTwo.getName());
                Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&f[&4Boxing&f] " + message));
            }
            else if (playerOne.getHealth() < playerTwo.getHealth()) {
                //playerTwo win
                String message = Files.getMessagesData().getString("Player-Win-Message").replaceAll("[winner]", playerTwo.getName()).replaceAll("[loser]", playerOne.getName());
                Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&f[&4Boxing&f] " + message));
            }
            else {
                Bukkit.getServer().getLogger().log(Level.WARNING, "Boxing could not work out who won. Report this to the Dev.");
            }
        }

    A lot cleaner, all that extra stuff went into its own public void. Plus I even have a warning. Sidenote, if you can see any mistakes in the new one. Let me know.
     
    #7 NavyDev, May 31, 2017
    Last edited: May 31, 2017
  7. Choco

    Junior Mod

    About 100 lines of that could be condensed down if you hadn't used Allman style ;-; I cri.
    (I'm kidding. Use what you want, but still..)
     
    • Agree Agree x 2
  8. K&R all day for me, although I really like the look of pico. Could start to look a bit messy though.
     
  9. Code (Text):
    //Close onEnable method
    [​IMG]

    Not to twist the knife in the wound, but I'd really like to know why :D
     
    • Funny Funny x 1
  10. Choco

    Junior Mod

    HONESTLY IDK. The way I was taught was to do that, and I always defended it. Now that I program a bit more professionally, I even question myself. Looks stupid, huh? Haha
     
  11. Meanwhile, I am just sitting here, looking at this stuff and thinking.
    "Hmmm, yeah, that's probably me right now"

    Although I have never felt the intention to }//Close thisComment
     
  12. Choco

    Junior Mod

    SHUT UP I WAS TAUGHT THAT WAY! Haha. I don't do that anymore, so it's all good. I'm not as bad as I was back then ;)
     
    • Funny Funny x 1
  13. I deleted or made my old projects from 2010-2014 private because they were written with less knowledge. Static abuse or singleton abuse filled my projects at this time.

    Now it seems that my codestyle is polished enough ATM. Let's see if I'm right with my guess.
     
  14. Hex

    Hex
    IRC Staff

    I'd bet whoever taught you that would've been an old-school C developer, because that's something you don't really see outside of end statements for C preprocessor blocks.
     
    • Like Like x 2
  15. His commenting was very strong, I rekon it would have taken at least 3
     
    • Funny Funny x 1
  16. Strahan

    Benefactor

    I once found a disk with some QuickBASIC code I wrote nearly thirty years ago, it was funny to look at how I was doing stuff. Really had me scratching my head, lol
     
  17. I would kill to have my first code again. Had a bit of c, c++, and basic from the mid 90s. Mostly game remakes like pong, block breaker, galaxian, and a few other popular stuff from the 80s. The basic code was made for robotics club. Sadly I lost it all more years ago than most users here are in age. :(

    Edit: for you IDE fanboys out there, this was my first IDE :p
    [​IMG]
     
    • Like Like x 3
  18. My first programming language was C#, then I started Java. So Allman was the first I every used and that's why I used that in my Java projects as well. Now I use K&R for Java, though.
     
    • Like Like x 1
    • Friendly Friendly x 1
  19. Wow, how things have changed. Not like the luxuries of what we have today. For anyone who argues about what IDE is better. I say we should throw them that and make them appreciate just how good most IDE's are today lol
     

Share This Page