• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Prototypes in vJass?

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

  • Yes

    Votes: 7 77.8%
  • No

    Votes: 2 22.2%

  • Total voters
    9
Status
Not open for further replies.
Level 17
Joined
Mar 17, 2009
Messages
1,349
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:
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.​
 
Level 10
Joined
Nov 28, 2008
Messages
655
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
 
Level 17
Joined
Mar 17, 2009
Messages
1,349
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:
Code:
#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.
 
Level 11
Joined
Apr 29, 2007
Messages
826
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.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
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.
 
Level 10
Joined
Nov 28, 2008
Messages
655
Noo please. vJass is JASS and not a real OOP language. We are trying to reproduce, but really, we can't put everything into.

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.
 
Status
Not open for further replies.
Top