![]() |
Difference Java/C++ <-> GS2
Hey,
Iam thinking of learning GS2. I had Java and C++ in School and already some in University, so I just wanted to ask where the main differences lie. - Lux |
My C/C++ and Java are both quite scratchy, so forgive me if this is not totally accurate, but from what I remember:
C/C++ is statically typed (in terms of variable data types), GScript uses variant types which adapt to the type of data automatically. Classes are very different in GScript to Java. Obviously in C classes do not exist, and I cannot say about C++ since I don't know enough about it. In GScript typically you implement class-like functionality using object joins, which are dynamic. You can "invent" class-like functionality in GScript by using these joinable class scripts, and also by using function prototyping and such. You don't think about allocation in GScript, since that is all done by the engine, whereas C/C++ (and maybe Java to an extent), you must set aside space to work with before you work with it. GScript uses built-in event-handling functions quite heavily to handle user/player interaction, whereas this functionality would not usually be implemented by default in C/C++. Scripts in GScript work quite heavily on an instance basis, i.e. an NPC, weapon script, GANI script, etc, which means that extra functionality like trigger and such are added to allow communication between these instances. Similar to Java's object instances, I guess. Flow control is pretty much identical (break, continue, return), as are many of the syntax structures (for, while, do, if), functions are defined in much the same way (with the function keyword instead of the expected datatype), and functions are called in the same way. Variable scoping isn't really vastly different to Java, not sure about C/C++ though without checking. GScript is quite a lot more like ECMAScript/JavaScript in terms of structure though. |
One thing I like about GS2 that Java doesn't have (but I would not want Java to have; would makes things incredibly complicated.
You can do something like this in GS2: PHP Code:
PHP Code:
Also, when comparing strings you CAN use ==. PHP Code:
PHP Code:
Just a few things that are different in Java vs GS2 |
C/C++ struct functionality can be replicated.
PHP Code:
PHP Code:
Classes in GS2 can be thought of as a mixture of #include and a class declaration. Joining a class gives access to its code and in ambiguous situations, should be called like class::func();. I know jack about java, though. Sorry if this isn't a good explanation, it's very hard to type on an iPod. |
Quote:
I couldn't type that much in a day on my iPhone >_< |
Why do we need C++ classes again?
|
Quote:
@ cbkbud... My plane home was delayed; I had nothing better to do. :p |
Quote:
I posted it on the forums some time ago: http://forums.graalonline.com/forums...ad.php?t=77835 ( Java class system doesn't include multiple inheritance, although that is little unimportant with the advent of join's. ) Additionally, GS2 isn't type-casted in the traditional sense... I find that non-typed languages are harder to work with: They force us to follow good coding practices. |
Quote:
|
Maybe private variables in Graal should be done like in Python where if the variable name starts with _ then its private.
this._varname == private this.varname == public That seems like the most painless way to me. |
Quote:
|
thisr. will not happen considering you would need thisor. and stuff like that and it would just become a giant pain. Something like this.private. might be better however having subvariables for variables that aren't objects is kinda weird and I don't think it would be good to go into that.
I still think my suggestion is best. |
Quote:
|
I think the best solution for private variables is just treating them as private. The convention you use for denoting a private variable could help you.
I basically treat all variables as private / local, and use clearly-defined functions to modify them. |
My solution was similar to some method in actionscript (I'd guess addmember). You provide the variable's name and the names of the get/set functions.
PHP Code:
Anyway, that's enough for derailing this thread, methinks. |
Quote:
Quote:
|
Quote:
im in ur scope accezzin ur private variablez. |
Quote:
I remember Stefan saying quite along time ago that something like thisr. would not be such a good idea so any argument is pointless. |
Quote:
e: I think you may have misunderstood Stefan, too. The last post wasn't meant to single you out, but after I posted, I realized how much of a pain it would have been to get my point understood. |
I never said anything about using thisr. in the with block, which obviously wouldn't be allowed. I think thats bad form anyhow. It would be better to use Twinny's suggestion and have the this.private. section of the object for private variables.
|
Quote:
PHP Code:
|
And with that, you have proven that you don't keep up with the future improvement subforum. *slaps*
|
Quote:
Just like at the beginning something like PHP Code:
|
Quote:
http://forums.graalonline.com/forums...ad.php?t=71199 |
Quote:
|
Quote:
PHP Code:
EDIT: And I really would think something like this would work PHP Code:
|
Quote:
Quote:
PHP Code:
|
Quote:
PHP Code:
|
Quote:
|
I don't believe doing things like declaring variables private/public/protected with keywords will work in GS2.
This is because GS2 has no support for such things. const is not real value type because the compiler is merely reading it and replacing instances of it in the script with its value on compile time. After the script is compiled it no longer exists. Its about the same thing as C++'s #define. As I said, GS2 has no support for such things for it would not be possible to do it without lots of changes that are unnecessary. That is why I suggested the Python method where variables (or functions) that have a name starting with _ are private: PHP Code:
|
I like this.private.foo, but maybe it could be accessed within the script with just this.foo?
The idea of _var and _func sounds really bad to me, would make code look messy in my opinion. |
Quote:
|
Quote:
PHP Code:
|
| All times are GMT +2. The time now is 07:58 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.