04.07.2016, 12:26
In my opinion, keep functions as functions. You're not really saving anything by using a macro. The advantage of a function is sanity checks and a more useful stack trace when you're using it multiple places. Example:
You'll catch errors safely and much earlier on in development. Macros act weird sometimes and you might find yourself in a position where you can't find the reason for a bug and debugging is made difficult with the use of a macro instead of a standard function call.
Q: When are macro functions useful?
They are more useful for building libraries and creating new syntax (look at y_iterate, y_timers, modio for examples).
Sure, you can save time typing when writing regular code but it might cost you in the long run. And with modern text editors (like Sublime), writing code is faster than ever anyway.
pawn Код:
stock HasInsurance(vehicleid)
{
if(!(0 < vehicleid < MAX_VEHICLE)) // checks if the ID is out of bounds
{
print("ERROR: ..."); // catch bad vehicle IDs
// PrintStackTrace(); // find out where HasInsurance was called from so you can fix the bug
return 1;
}
if(!IsValidVehicle(vehicleid)) // checks if the vehicle actually exists
{
print("ERROR: ...");
// PrintStackTrace();
return 1;
}
// perform your actual function
}
Q: When are macro functions useful?
They are more useful for building libraries and creating new syntax (look at y_iterate, y_timers, modio for examples).
Sure, you can save time typing when writing regular code but it might cost you in the long run. And with modern text editors (like Sublime), writing code is faster than ever anyway.