• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Inlining constants?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,342
Hi,

Suppose I'm using constants to represent raw codes so I can do high level coding (e.g. instead of writing 'Hpal', I can write something like HUMAN_PALADIN).

In my case I've already got almost 2000 thousand such constants.

So will the compiler inline all these constants, and then delete the libraries which hold them to save map space? Or would this be something I would have to do myself?
 
Level 15
Joined
Aug 7, 2013
Messages
1,342
Well suppose I'm making item spawn tables or creep spawn tables.

Would you work with the raw codes by themselves and hope to memorize them all?

Or using constants that have descriptive names, e.g. GNOLL_OVERSEER? Perhaps if in the midst of the project you can memorize all your raw codes. But if you ever want to go back and look at the tables, you'd be lost.

I would say it's a higher level coding than using the raw codes directly, because it's abstracting away from the internals of how objects are named in WC3. And it adds readability, which is usually a property of higher level code--tradeoff is usually efficiency, which it seems is taken care of in the final product by Vexorian's optimizer.
 
Hm yeah didn't see code.. but 2k just has sound too much for me for a wc3 map.

Actually you also could inline all number you use, but nobody does so...

Also never seen something like this:
JASS:
globals
    constant integer NULL = 0
    constant integer ONE  = 1
    constant integer TWO = 2
    ...
    ...
endglobals

function foo
    local integer i = NULL
    loop
        exitwhen i > TWENTY
        i = i + ONE
    endloop
endfunction
Of course it may be useful for some rawcodes, but just meant I would not use it for everey pettiness just to optimize it where it's possible ++
 
Level 23
Joined
Jan 1, 2009
Messages
1,617
Also never seen something like this:
JASS:
    constant integer NULL = 0

Because that would be the biggest fail ever?
At least name it ZERO.

In cJass there are defines which are just a search & replace directive,
vex' optimizer does some var inlining and
WurstScript has built-in constant inlining, folding and propagation
 
Level 23
Joined
Jan 1, 2009
Messages
1,617
Biggest fail ever? I don't see it's not more or less fail as the other constants. And it's not even important in that example.

It is. Because null != 0. That's one of the first things in programming you should learn.
(and it's capital in other languages like C, sql)

The other constants are fine, just like ZERO would be, but useless nonetheless.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
its sometimes not really great, mainly if you are concerned by map size. Imagine code like this:

constant integer a = 'abcd'

then it is only worth to change a to 'abcd' if it only occurs 4.5 times, because after that it will take more space to write 'abcd' every time rather than to use the global.

About performance: dude, dont become second Nestharus, this is so trivial that you will NOT notice anything at all if you use global variable or constant integer

Its always better to have stuff like constant integers that mark some abilities by name(SPELL_MYSPELL) for instance, rather than just 'abcd'. It is easier to change if you change the rawcode of the ability(better maintainablitily), and the code is a little bit easier to read and understand(call UnitAddAbility(u, SpellSteal) is self-explanatory while call UnitAddAbility(u, 'abcd') is not unless you really open up the editor every time

It is. Because null != 0. That's one of the first things in programming you should learn.
(and it's capital in other languages like C, sql)

The other constants are fine, just like ZERO would be, but useless nonetheless.

I must!

C++:
/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

so it is in fact 0 in some languages(at least 1 :D)
 
Status
Not open for further replies.
Top