• 🏆 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!

[vJASS] Question about Interfaces

Status
Not open for further replies.

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
It behaves the same for an end user, but is not the same (it's more of a definition since vjass is a preprocessed language).

This is the best reference for vjass, no exceptions: http://www.wc3c.net/vexorian/jasshelpermanual.html#interfs

Don't be fooled by the way it looks. Vexorian keeps things simple and you can learn interfaces in vjass in 30 seconds.
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
how is it not the same?

The oop concept of an interface is simply a definition of common signatures of methods for different objects. And thats exactly what vjass interfaces do.

In a proper OO language, interfaces are used as a way to classify an object in more than one way. In vJass, they behave like a definition, since only jasshelper will check if the end user isn't doing anything illegal with their interface definitions.

In reality structs are just symbolic groups of variables and functions with some pseudo-encapsulation - and although it might sound pedantic to say it's not the same, it can sometimes be important to understand that struct instances are just integers.

Edit - the obvious example and very common pitfall is that there is a strict limit in the number of struct objects the user can instantiate, and that number falls rapidly if the user defines a struct member as an array.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
I disagree (call it pettifoggery if you want).

The oop concept of an interface is simply a definition of common signatures of methods for different objects. And thats exactly what vjass interfaces do.
This is pretty much the definition of a oop interface. vJass follows it -> vjass interfaces are "real" interfaces. Of course the implementation is not the exact same as in c#, but definitions are (by definition) usually just the least common denominators of the examples.

In a proper OO language, interfaces are used as a way to classify an object in more than one way. In vJass, they behave like a definition, since only jasshelper will check if the end user isn't doing anything illegal with their interface definitions.
- vjass ensures that the classes implementing the interface have the common methods
- vjass enables subtyping with interfaces
Yes, its all on a very high level since jasshelper is only a precompiler, but for the user its the exact same thing.

Edit - the obvious example and very common pitfall is that there is a strict limit in the number of struct objects the user can instantiate, and that number falls rapidly if the user defines a struct member as an array.
o_O how is that related to interfaces?

Maybe you wanted to bring the example that different structs that implement the same interface share the same address space and therefore also the maximum number of possible instances?
Cause thats something one should keep in mind when using interfaces, but it doesnt mean vjass interfaces are no real interfaces.
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
I disagree (call it pettifoggery if you want).


This is pretty much the definition of a oop interface. vJass follows it -> vjass interfaces are "real" interfaces. Of course the implementation is not the exact same as in c#, but definitions are (by definition) usually just the least common denominators of the examples.


- vjass ensures that the classes implementing the interface have the common methods
- vjass enables subtyping with interfaces
Yes, its all on a very high level since jasshelper is only a precompiler, but for the user its the exact same thing.


o_O how is that related to interfaces?

Maybe you wanted to bring the example that different structs that implement the same interface share the same address space and therefore also the maximum number of possible instances?
Cause thats something one should keep in mind when using interfaces, but it doesnt mean vjass interfaces are no real interfaces.

Yes, you're right in many ways. I suppose my explanations are in disarray.

By definition, interfaces in vJass work with the same concepts as in other languages like C# - that answers Starquizer's question.

But - I wanted to make it very clear that structs in vJass are inherently different and one has to be careful when working with them.

Take for example:

JASS:
scope example initializer i
    struct slop
        integer a=5
    endstruct
    
    struct soup
        integer a=6
    endstruct
    
    globals
        private integer bap=0
    endglobals
    
    private function e takes nothing returns nothing
        local soup so=bap
        call DisplayTextToPlayer(GetLocalPlayer(),0.,0.,I2S(so.a))
    endfunction
    
    private function i takes nothing returns nothing
        local slop sl=slop.create()
        set bap=sl
        call e()
    endfunction
endscope

What does this script output?

The naive answer is 'syntax error' since set bap=sl doesn't technically make sense.

The answer by inspection is '0'

The correct answer is 'impossible to know' since soup[bap].a depends on how many and in what order were soup and slop instantiated, modified, and destroyed.

Again, this has little to do with the implementation of interfaces in vJass but my warnings were meant to be a bit beyond that.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
In reality structs are just symbolic groups of variables and functions with some pseudo-encapsulation - and although it might sound pedantic to say it's not the same, it can sometimes be important to understand that struct instances are just integers..

As far as I know, structs in C# reserves from the stack as they are most likely to be ints, bytes, longs ,doubles, etc and unlike classes, that reserves memory addresses in the heap.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Structs are different from language to language. One common definition is "a composition of objects or datatypes". However lots of languages dont stick to that definition, so its hard to say what "real structs" are.
In c++ structs may contain methods, c doesnt support that.

vjass structs behave pretty much like "normal structs", but you could also just call them classes as the discrimination of classes and structs is quite blurry. If you want to know how vjass structs behave, dont try to compare them to other languages and just read the documentation.
 
Status
Not open for further replies.
Top