| 04-19-2007, 02:46 AM | #1 |
http://en.wikipedia.org/wiki/Property_%28programming%29 I like properties because they let you simplify code outside the class a lot, so I am adding them to vJass since they are also a vital requirement for xe . But I must first decide the syntax... ... what I currently got: Attempt A:struct some private real cx method setx takes real x returns nothing set this.cx=x*x endmethod method geta takes nothing returns real return x-1.0 endmethod property x set setx get cx property a get geta endstruct Attempt B:struct some private real cx method property x= takes real x returns nothing set this.cx=x*x endmethod method property x takes nothing returns real return this.cx endmethod method property a takes nothing returns real return this.cx-1.0 endmethod endstruct Attempt C:struct some private real cx method set property x takes real x returns nothing set this.cx=x*x endmethod property x method get takes nothing returns real return this.cx endmethod method set takes real x returns nothing set this.cx=x*x endmethod endproperty property a method get takes nothing returns real return this.cx - 1.0 endmethod endproperty endstruct If you got better suggestions please tell, if you actually like one of these also tell... It is possible that you don't get it, well the three examples would have the same effect: example:function tes takes some s returns nothing set s.x= 2.0 call BJDebugMsg(R2S(s.x)+" , "+R2S(s.a)) //"4.0 , 3.0" endfunction |
| 04-19-2007, 03:45 AM | #2 |
I propose attempt C, it's is easier to understand IMO, and it allows to define read only, write only and read/write properties. GOGOGO Vex!!! |
| 04-19-2007, 03:56 AM | #3 |
well, all of the attempts allow all of those. |
| 04-19-2007, 04:02 AM | #4 |
yes, but it's more readable and more logical, at least for me :) |
| 04-19-2007, 05:40 AM | #5 |
Option A seems shortest. One way you might make it even briefer for a class with many properties is to allow specifying multiple property links on one line, like JASS:readproperty x with getx, a with geta writeproperty x with setx accessproperty z with setz getz What about this: JASS:property getx reads x, setx writes x, geta reads a |
| 04-19-2007, 07:38 AM | #6 |
pipedream's method is the one i like most. Its easy to understand and still u cna add many properties in one line. |
| 04-19-2007, 01:11 PM | #7 |
I don't really think many properties in a line is good at all... I think that maybe pipedream's second example got the properties and members reversed? JASS:property x reads cx, writes setx property a reads geta |
| 04-19-2007, 01:19 PM | #8 |
We don't even know what scopes, methods and privates are and you're adding another one? >_> Anyways, I like Attempt B and PipeDream's version. They're easy to understand. |
| 04-19-2007, 01:32 PM | #9 |
After properties the remaining changes to the syntax are: - enums (but we need type safety before adding them) - Wrapers (maybe type safety would be a good idea) - defines (although I am still not sure) Then it is all done with vJass |
| 04-19-2007, 01:56 PM | #10 |
hmm i re read pipedreams syntax... and found it a bit confusing with readproperties ect... I like this form: JASS:
property x: set with setx get with cx
property a: get with geta
i like the "with" word, makes the thinking faster and easier, since its more logical for me to think like that. |
| 04-19-2007, 03:51 PM | #11 |
I'm all for Attempt C. It's the closest you can get to original JASS syntax. The other attempts obviously already caused confusion and mix-ups. |
| 04-19-2007, 04:59 PM | #12 |
I noticed that the C I submitted had some garbage code Attempt C:struct some private real cx method set property x takes real x returns nothing set this.cx=x*x endmethod property x method get takes nothing returns real return this.cx endmethod method set takes real x returns nothing set this.cx=x*x endmethod endproperty property a method get takes nothing returns real return this.cx - 1.0 endmethod endproperty endstruct |
| 04-19-2007, 10:25 PM | #13 |
Yeah, i figured as much. Which one do you like, Vex? |
| 08-04-2007, 09:30 AM | #14 |
B is the best one IMHO, A an C use the set keyword == big big problems EDIT: Also A and C separate property declaration in 2 phases == more problems B is definitely the best + it is the easiest to implement. |
| 08-04-2007, 01:07 PM | #15 |
I don't really see any "big big problems" with the things you mentioned, and none of these three is specially easier to implement .. I think I personally liked B more than the rest, have to mention that the three of them require 2 phases for the property declaration, which is unavoidable since properties need read and write, unless you make them read-only |
