1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  4. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

JPAG - JASS Proper Application Guide

Discussion in 'JASS/AI Scripts Tutorials' started by Bribe, Sep 27, 2011.

  1. Tastingo

    Tastingo

    Joined:
    Oct 25, 2010
    Messages:
    8
    Resources:
    0
    Resources:
    0
    I'm sorry I read only the first couple pages of this topic. I very rarely post on this forum, but this topic is total BS. Honestly it's like arguing toe ma toe or toe may toe. I don't care how Blizzard wrote their code, and I'm sure a bunch of others don't care either. Just looking at the first few pages of my C Programming Book, it says there are multiple ways to write code. Blizzard never said this, nor did it say we had to write code a certain way. So that means its up to us? Your not us, neither am I.

    However, I think it's probably best that the writer of the code just keeps consistency. As long as he/she does not make some globals all caps and some all lower case. Same for constants and functions. People are smart enough to figure code out, and it will even help them if they are going into a Computer Science related field.
     
  2. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Well if you had kept reading that is pretty much the compromise I landed on.
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    While this has been subject to a lot of controversy/debate, I think that it being renamed to a "guide" rather than a "standard" should relieve everyone's complaints. It is useful to those who do not know of the standard jass conventions. I remember when I first started coding in JASS--I would write as I pleased and toyed with several styles, trying to find one that looked good. If only this guide had been there before.

    Approved.

    (It is true that the initializer part is a bit dated since cohadar's release, but I'll wait until it becomes a bit more public before requiring an update)
     
  4. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Suggested addition

    1 space between addition/subtraction and no spaces between multiplication/division. This clearly shows the operations done ; ).

    Compare
    1 + 1*3 + 6 - 2/1*6

    1+1 * 3+6-2 / 1 * 6

    1+1*3+6-2/1*6


    And tell me which one is the easiest to read/understand ;p
     
  5. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    I usually put spaces in between all those operators :eek:

    1 + 1*3 + 6 - 2/1*6

    vs.
    1 + 1 * 3 + 6 - 2 / 1 * 6


    Wow, the first /does/ look better =o
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Yeah the first one is more visually logical due to math precedence, I may add this as a suggested format then.
     
  7. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Looks even better with brackets. Although I also put spaces, it feels somehow annoying to smash the spacebar, especially frequently in such math calculations. May be corrected by editor instead when the line is finished.
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I have added a math-operator section as well as made a note in the initializer-section for users of Cohadar's JassHelper.

    If there is more anyone believes I should add please let me know and let me know why you think it's important to have a standard for it. Thanks.
     
  9. 1)ark_NiTe

    1)ark_NiTe

    Joined:
    Nov 1, 2006
    Messages:
    1,680
    Resources:
    5
    Maps:
    1
    Spells:
    3
    Tutorials:
    1
    Resources:
    5
    I know this is super late to jump in on the conversation but why are we not using parentheses to make the order of operations easier to follow?


    1 + (1*3) + (6 - ((2/1)*6)) //Correct
     
     
  10. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I only use parentheses when required (like this).

    Do you know how annoying it is to lose track of parenthesis while coding? Better to just rely on precedence.

    OFC you can use parentheses if you feel it helps.
     
  11. 1)ark_NiTe

    1)ark_NiTe

    Joined:
    Nov 1, 2006
    Messages:
    1,680
    Resources:
    5
    Maps:
    1
    Spells:
    3
    Tutorials:
    1
    Resources:
    5
    This is less of a problem when you're using an IDE that highlights corresponding parentheses. Your point is taken though. I think this one may just be a matter of preference. Personally, I find calculations inside parentheses to be easier to follow. Thanks for the response.
     
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    This whole guide is just preference. There are more people coding WC3 these days than there are people playing it. I gave up on coding once everything blew up with the Nestharus rules and people leaving and these new programming syntaxes coming out, making everything much more obfuscated than it should be.
     
  13. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    AMENDMENT:

    Creation and destruction of artificial types should match the naming conventions set by Blizzard and Vexorian. Struct methods should be named "create" or "destroy". Other functions which try to serve the same purpose should begin with Create or Destroy.

    There is another naming convention which should be encouraged: adding and removing. These should be reserved for container-type syntax. In JASS, you have GroupAddUnit, GroupRemoveUnit, ForceAddPlayer, ForceRemovePlayer and others. The naming convention should contain the words add and/or remove when you are working with structures like linked list, linear stacks, Tables and any other "containing" element which may be utilized or invented.
     
  14. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    From an IM sent to Bribe concerning the add/remove bit

     
  15. Is there stance on inverse comparison logic:
    exitwhen null == FoG
    vs
    exitwhen FoG == null
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,154
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Nes thinks the first one is faster. I homestly never would read that much into it. Personal preference reigns supreme on that one.
     
  17. Then I will use the first one, thanks for answering.