1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. 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.

Prototypes in vJass?

Discussion in 'Off-Topic' started by Deuterium, Feb 2, 2010.

?

Do you think 'prototyping would be a nice and useful feature if implemented in vJass?

  1. Yes

    7 vote(s)
    77.8%
  2. No

    2 vote(s)
    22.2%
  1. Deuterium

    Deuterium

    Joined:
    Mar 17, 2009
    Messages:
    1,301
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Well, I don't know how many of you know C++. But one nice feature is the "prototype" feature. Although not an essential feature, but allows us to code in much neater and less restricted manner.

    What a prototype allows us to do is to announce a function - by defining it's name and parameter types - without actually defining the function in the first place.

    Then somewhere later in the code, one would define the function.

    Ex:
    Code (Text):
    struct example {

         void PrintString(string);

    };

    //then somwhere later in the code, even outside the struct
    void example::PrintString(string s)
    {
        cout << "The string is: " << s;
    }


    Anyways, the purpose of this thred:

    I wonder if you people think it would be a nice idea having prototypes in vJass. I think it'll make coding MUCH NEATER and codes easier to work with and edit.

    Maybe if you agree with me we could then let Vexorian know about this idea and hope he would implement it.​
     
  2. tagg1080

    tagg1080

    Joined:
    Nov 28, 2008
    Messages:
    632
    Resources:
    0
    Resources:
    0
    I have always loved the fact that in java we can put them all at the end. It helps keep the readability up by HUGE amounts.

    I think this would be a great feature, and should definitely be added. I am actually surprised that it isn't already in vJass. I have only played with Jass, not vJass, so I can't really speak too much about it.


    The more I look at Jass though, the more that I find that A LOT of the coders, at least that I have looked at, don't code very professionally. This would be one step to get them to clean up their freakin' code!

    +1 for the idea
     
  3. YourNameHere

    YourNameHere

    Joined:
    Apr 29, 2007
    Messages:
    745
    Resources:
    4
    Maps:
    1
    Spells:
    2
    JASS:
    1
    Resources:
    4
    With a bit of working around, interfaces can archieve nearly the same.

    Although the idea generally is ok, I don't think we would have any actual use of this.
    Maybe give us some examples to make your idea clear and how you would like to use it in the future. :)
     
  4. Deuterium

    Deuterium

    Joined:
    Mar 17, 2009
    Messages:
    1,301
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Exactly, neater and more professional code =)
    Plus it provides a more dynamic workspace. You don't need to keep jumping between functions to make ur code, instead u throw in the prototypes and then create the functions whenever u feel like it :p

    EDIT:
    Well YourName, prototypes don't have any "actual benefit" other than making coding neater by allowing you to announce function somewhere then defining them somewhere else. This is mostly useful for structs...

    Here's an example of a code I made some time ago:
    time.h
    Code (Text):
    #include "num2string.h"
    using namespace std;

    class time {

        // members
    protected:
        int hour,
            minute,
            second;

    public:
        // constructors
        time();
        time(int);
        time(int,int);
        time(int,int,int);
        time(time&);

        // accessors
        int getHour()   {return hour;}
        int getMinute() {return minute;}
        int getSecond() {return second;}

        // setters
        void setHour(int);
        void setMinute(int);
        void setSecond(int);

        //functions
        int getTimeInSeconds();
        int difference(time);
        bool isEqual(time);
        virtual string printTime();
    };


    // SETTERS (FUNCTIONS)
    void time::setHour(int h)
    {
        if(h >=0 && h <24)
            hour = h;
        else
        {
            cout << "Invalid hour value inserted. Hour will be set to 00." << endl;
            hour = 0;
        }
    }

    void time::setMinute(int m)
    {
        if(m >=0 && m <24)
            minute = m;
        else
        {
            cout << "Invalid minute value inserterd. Minute will be set to 00." << endl;
            minute = 0;
        }
    }

    void time::setSecond(int s)
    {
        if(s >=0 && s <24)
            second = s;
        else
        {
            cout << "Invalid second value inserterd. Second will be set to 00." << endl;
            second = 0;
        }
    }

    // CONSTRUCTORS (FUNCTIONS)
    time::time()
    {
        hour = 0;
        minute = 0;
        second = 0;
    }

    time::time(int h)
    {
        setHour(h);
        minute = 0;
        second = 0;
    }

    time::time(int h, int m)
    {
        setHour(h);
        setMinute(m);
        second = 0;
    }

    time::time(int h, int m, int s)
    {
        setHour(h);
        setMinute(m);
        setSecond(s);
    }

    time::time(time& t)
    {
        setHour(t.getHour());
        setMinute(t.getMinute());
        setSecond(t.getSecond());
    }


    // OTHER FUNCTIONS
    int time::getTimeInSeconds()
    {
        return hour * 3600 + minute * 60 + second;
    }

    int time::difference(time t)
    {
        return abs(getTimeInSeconds() - t.getTimeInSeconds());
    }

    bool time::isEqual(time t)
    {
        return (getTimeInSeconds() == t.getTimeInSeconds());
    }

    string time::printTime()
    {
        string h, m, s;

        if(hour <= 9)
            h = "0" + num2string(hour);
        else
            h = num2string(hour);

        if(minute <= 9)
            m = "0" + num2string(minute);
        else
            m = num2string(minute);

        if(second <= 9)
            s = "0" + num2string(second);
        else
            s = num2string(second);

        return h + ":" + m + ":" + s;
    }[/hidden]
    I don't know how much C++ you know, but you can see how the function are announced inside the 'class', but almost all are defined later outside the class.
    Also, you know how you can call a function only if it has been defined above - textwise - the line you're calling it from? Well when using prototypes, you only need to announce the prototypes at the top, and then define the functions wherever you are, even if below the lines where you call it.
     
  5. YourNameHere

    YourNameHere

    Joined:
    Apr 29, 2007
    Messages:
    745
    Resources:
    4
    Maps:
    1
    Spells:
    2
    JASS:
    1
    Resources:
    4
    Ok I've got to agree with you.
    Looking at the code, prototypes could simply be used as API definition for others - you have a easy overview of all functions that are available for you.

    And I can read most of C++ if it doesn't go deep to winapi functions or whatever.

    Anyway, if you feel like suggesting this, you should most likely do so in the official JassHelper thread on wc3c.net.
     
  6. Deuterium

    Deuterium

    Joined:
    Mar 17, 2009
    Messages:
    1,301
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Well yes I know this belongs in wc3c.net, but I thought I would want to know the opinion of the hivers before I go there and discuss this :)

    EDIT:
    Plus I don't have an account in wc3c.net :p
     
  7. The Reborn Devil

    The Reborn Devil

    Joined:
    Dec 31, 2006
    Messages:
    1,325
    Resources:
    0
    Resources:
    0
    Yes, I think it could be useful. I don't usually make systems/spells which require it, but sometimes I do and then I get annoyed because I must move some of my functions to other places to let some other function use it which makes my code ugly.
     
  8. Tleno

    Tleno

    Joined:
    Jul 6, 2008
    Messages:
    4,782
    Resources:
    2
    StarCraft II Resources:
    2
    Resources:
    2
    Sounds like a useful function to me, altough I'm not a programming expert.
     
  9. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,220
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Noo please. vJass is JASS and not a real OOP language. We are trying to reproduce, but really, we can't put everything into.
     
  10. tagg1080

    tagg1080

    Joined:
    Nov 28, 2008
    Messages:
    632
    Resources:
    0
    Resources:
    0
    The terminology and syntax may be aimed towards OOP, but this is definitly not an idea that is strictly held to OOP.

    C has the same functionality, well, similar in concept, and it can be quite useful.


    I don't see how this is a OOP only concept. It is universally useful, having functions all on one block is just a useful feature.

    If you have any ideas as to how this is not a useful feature, please explain, as I don't see any.
     
  11. Triggs

    Triggs

    Joined:
    Oct 6, 2009
    Messages:
    0
    Resources:
    0
    Resources:
    0
    If you think it's a good idea, why not just post in the JassHelper thread?
     
  12. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    actually, you can already use all methods in structs regardless of their placement. JassHelper automatically optimizes TriggerEvaluate usage by sorting the functions correctly.