Const support

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

Const support

David S. Rodrigues
Hello haxers!
See my suggestion: haxe.org/forum/thread/1595

Can you agree?

Bye.

--
David S. Rodrigues

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
David S. Rodrigues wrote:
> Hello haxers!
> See my suggestion: haxe.org/forum/thread/1595
> <http://haxe.org/forum/thread/1595>

Well, since I use a preprocessor I already have the "CONST" keyword. :)

I agree otherwise that it is too much typing. Though if the notiong of
const was introduced I would prefer to see a full OO concept of const
functions and classes. That'd be more useful to me at this point.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

François Rey
On Monday 19 April 2010 07:35:22 edA-qa mort-ora-y wrote:
> I agree otherwise that it is too much typing. Though if the notiong of
> const was introduced I would prefer to see a full OO concept of const
> functions and classes. That'd be more useful to me at this point.
Yes, and in that case I would prefer the "final" keyword like in java, which
applies to variables, functions and classes.
However for target languages that do not support final methods and classes,
you would not be able to prevent native function overriding/subclassing. So
you would not be able to always rely on such feature.
Instead of "const" I'd rather have a "final" keyword which only applies to
variables. It could even be applied to local variables, since it can be
enforced by haxe compiler and most languages treat function body as
indivisible and encapsulated.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
François Rey wrote:
> However for target languages that do not support final methods and classes,
> you would not be able to prevent native function overriding/subclassing. So

That's fine with me. I'm only interested in compile time errors anyway.
Besides, even languages with const support (like C++) can't guarantee
those values won't be changed at runtime.

"final" and "const" are two distinct concepts. And an important
distinction. "final" doesn't have nearly the same impact on variables as
does "const". Yet it has a stronger impact in terms of deriving classes.


--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

David S. Rodrigues
Well, I not sure if I understand. But in case, you are suggesting "const" and "final". In this case, I agree. "const var" and "final function", right?
Bye.

On Mon, Apr 19, 2010 at 7:40 AM, edA-qa mort-ora-y <[hidden email]> wrote:
François Rey wrote:
> However for target languages that do not support final methods and classes,
> you would not be able to prevent native function overriding/subclassing. So

That's fine with me. I'm only interested in compile time errors anyway.
Besides, even languages with const support (like C++) can't guarantee
those values won't be changed at runtime.

"final" and "const" are two distinct concepts. And an important
distinction. "final" doesn't have nearly the same impact on variables as
does "const". Yet it has a stronger impact in terms of deriving classes.


--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
       http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
       http://wiki.disemia.com/HaXe

A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org



--
David S. Rodrigues

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
David S. Rodrigues wrote:
> Well, I not sure if I understand. But in case, you are suggesting
> "const" and "final". In this case, I agree. "const var" and "final
> function", right?

"final" implies that a reference can no longer be changed. For a
function it means it can't be overridden in a derived class, for a
variable it means the initial assignment is the only assignment it will
ever have.

"const" on the other hand describes the nature of the object being
referred to. It says the object itself cannot be modified. It behaves
more of a caller contract than does final.

Both are useful constructs. In C/C++ you only need one since you can
explicitly define references, but in languages where references are
automatic (like haxe) you would need two distinct keywords.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

François Rey
On Monday 19 April 2010 17:48:55 edA-qa mort-ora-y wrote:

> "final" implies that a reference can no longer be changed. For a
> function it means it can't be overridden in a derived class, for a
> variable it means the initial assignment is the only assignment it will
> ever have.
>
> "const" on the other hand describes the nature of the object being
> referred to. It says the object itself cannot be modified. It behaves
> more of a caller contract than does final.
>
> Both are useful constructs. In C/C++ you only need one since you can
> explicitly define references, but in languages where references are
> automatic (like haxe) you would need two distinct keywords.

Then I'd prefer final as a keyword: it's the assignment/inheritance/overriding
which is final.
Const as you describe it refers to what I know as immutable objects: once
created/initialized, their state (i.e. class variables) cannot change. See
http://en.wikipedia.org/wiki/Immutable_object.
Is there any language that support immutable object explicitely?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

David S. Rodrigues
In the case, "const" is only a shortcut to "static public inline var" (ex: const x == static public inline var x).
The "final" is another thing, it's to prevent override. Both are valuable things.

Bye.

2010/4/19 François Rey <lists.motion-twin.com@francois.rey.name>
On Monday 19 April 2010 17:48:55 edA-qa mort-ora-y wrote:
> "final" implies that a reference can no longer be changed. For a
> function it means it can't be overridden in a derived class, for a
> variable it means the initial assignment is the only assignment it will
> ever have.
>
> "const" on the other hand describes the nature of the object being
> referred to. It says the object itself cannot be modified. It behaves
> more of a caller contract than does final.
>
> Both are useful constructs. In C/C++ you only need one since you can
> explicitly define references, but in languages where references are
> automatic (like haxe) you would need two distinct keywords.

Then I'd prefer final as a keyword: it's the assignment/inheritance/overriding
which is final.
Const as you describe it refers to what I know as immutable objects: once
created/initialized, their state (i.e. class variables) cannot change. See
http://en.wikipedia.org/wiki/Immutable_object.
Is there any language that support immutable object explicitely?

--
haXe - an open source web programming language
http://haxe.org



--
David S. Rodrigues

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

François Rey
On Monday 19 April 2010 18:12:36 David S. Rodrigues wrote:
> In the case, "const" is only a shortcut to "static public inline var" (ex:
> const x == static public inline var x).
> The "final" is another thing, it's to prevent override. Both are valuable
> things.
>

Why do constant variable need to be public?
Default or private can be useful too.
Why do constant variable need to be static?
I may want nothing to be static in my class and make sure it works only with
instances, just like haXe has inlining for static and non-static methods.

Final and inlining are not the same features even if they overlap greatly:
inlining needs final for it to work, but the reverse does not have to be true.

I like the way Java defines final:
http://en.wikipedia.org/wiki/Final_%28Java%29

Java does not have an inline keyword, inlining is a compiler+runtime
optimization that cannot be explictly specified:
http://stackoverflow.com/questions/1159087/inlining-in-java

So I wonder how the Java target in the lab would handle haXe inline keyword
then....

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

Nicolas Cannasse
In reply to this post by David S. Rodrigues
David S. Rodrigues a écrit :
> Hello haxers!
> See my suggestion: haxe.org/forum/thread/1595

We are not planning to add additional keywords in the language,
especially if they are only meant to save typing and does not provide
additional features.

We are also no planning to add 'final' behavior which goes against haXe
philosophy of letting the developers do what they need to do with other
people classes ;)

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
In reply to this post by François Rey
François Rey wrote:
> Const as you describe it refers to what I know as immutable objects: once
> created/initialized, their state (i.e. class variables) cannot change. See
> http://en.wikipedia.org/wiki/Immutable_object.
> Is there any language that support immutable object explicitely?

There are some very domain specific langauges which have immutable
objects (something like Matlab/Octave, but that applies to all objects
then).

"const" in C++ is meant as a restriction on how an object can be used.
It doesn't indicate the object is immutable. Such immutable objects can
be constructed in C++ however, also in Java and many others, but I don't
know of an explicit keyword to indicate that.

That is, I don't mean that const is the same as immutable, I mean that
the particular reference to object is unable to modify the object. That
is, the reference is "read-only".

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
In reply to this post by Nicolas Cannasse
Nicolas Cannasse wrote:
> We are also no planning to add 'final' behavior which goes against haXe
> philosophy of letting the developers do what they need to do with other
> people classes ;)

"const" and "final" member functions add a level of safety, the same
type of thing that strict typing does.

I do understand your view that the developer should be able to do
whatever they want -- I have often encountered poor decisions as to what
is "final" in the Java stdlib.  But I like the idea of having extra
protection.

"final" applied to a method is a good way to indicate that the class was
not designed to have that method overridden. That is, if it is
overridden you could easily break the class unless very careful.

Similarly an "abstract" keyword would help me a lot. I have many classes
which have abstract functions which need to be overridden. It would be
great to know at compile time that I haven't done so.

So yes, none of these add new functional features, but at the same time
neither does static typing add functional features to a language. You
could do everything with dynamic, but having static indicators really
helps prevents unintended bugs.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

François Rey
In reply to this post by Nicolas Cannasse
On Monday 19 April 2010 18:38:20 Nicolas Cannasse wrote:
> We are not planning to add additional keywords in the language,
> especially if they are only meant to save typing and does not provide
> additional features.
I don't need any, although final vars would be nice not as a way to save
typing but as a way to enforce a design contract.
 
> We are also no planning to add 'final' behavior which goes against haXe
> philosophy of letting the developers do what they need to do with other
> people classes ;)
I agree that final methods/classes are annoying and rare is the need to have
them. In fact performance is probably the only reason for using final
methods/classes.
The thing is that haXe has inlining effectively makes the member final, so the
effect is the same anyway. It's just that the final keyword is clearer because
it clearly states what to expect from a programmers point of view.
Inline on the other hand is more a compiler-runtime-performance feature. It
certainly makes it clearer that performance is a concern. However not all
languages support inlining and I'd expect the more evolved a language is, the
less likely inlining is supported. Inlining even ends up being more of a
runtime optimization than a compile-time optimization. See this interesting
discussion:
http://www.discussweb.com/java-programming/3445-whats-use-final-method.html
 

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
François Rey wrote:
> I agree that final methods/classes are annoying and rare is the need to have
> them. In fact performance is probably the only reason for using final
> methods/classes.

A case where they come up is when inheritance chains through abstract or
partially specialized classes.

For instance, in my library, I have an interface called "Animation"
which defines a function called "animate". This is quite straight
forward. Then I have a class called "AnimatedSprite" which implements
this interface and is a Flash sprite object. Still fine.

But now I come along with a game and I have a common base class called
"GameSprite" which defines only partially how the item should be
animated. It defines then a new function called "gameAnimate" which the
derived class *must* implement. Further to that, the derived class *must
not* override the "animate" function -- as only GameSprite knows how to
do that correctly.

So what I have is the need for the final keyword and the abstract keyword.

I encounter this in a great number of projects, so I don't consider it a
rare scenario.

> Inline on the other hand is more a compiler-runtime-performance feature. It
> certainly makes it clearer that performance is a concern. However not all

I personally don't like having to specify "inline". It think it would
clearer to mark functions as "speed" or "size" to indicate which you'd
rather optimize for. I'm not sure how bad the situation is in haxe, but
I recall in C++ a lot of people would use "inline" since they wanted
faster code, but ended up making their code slower.


--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

François Rey
Just realized one thing: haxe may not be able to enforce final methods/classes
in target languages, but it's more able to enforce inline functions since it
can control what it generates. So afterall inline may be a better keyword
because it reflects an underlying reality!
For example java does not support inline, but haXe can still inline within the
generated .java file. Am I right?
If so I also favor no change: keep inline keyword and no const/final keyword.
It's just a matter of understanding haXe for what it is, a multi-target
compiler.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Const support

edA-qa mort-ora-y
François Rey wrote:
> Just realized one thing: haxe may not be able to enforce final methods/classes
> in target languages, but it's more able to enforce inline functions since it
>..
> It's just a matter of understanding haXe for what it is, a multi-target
> compiler.

But I treat haXe's final output as opaque, as I suspect many people is.
That is, I treat the output as essentially binary code, the fact that is
actually PHP or JavaScript doesn't matter to me.

From that view I have no belief that the keywords I use will be enforced
at runtime. All I want is for them to be enforced at compile time. This
is much what happens with C++ keywords, once compiled the notions are lost.

This is already what happens with the static typing. Once compiled to JS
or PHP all that type information is gone. The assurances you had at
compile time can no longer be guaranteed. The situation with final/const
would be no different.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

Armén
In reply to this post by edA-qa mort-ora-y
Which preprocessor do you use? I am looking into using one :-)

On Mon, Apr 19, 2010 at 07:35, edA-qa mort-ora-y <[hidden email]> wrote:
David S. Rodrigues wrote:
> Hello haxers!
> See my suggestion: haxe.org/forum/thread/1595
> <http://haxe.org/forum/thread/1595>

Well, since I use a preprocessor I already have the "CONST" keyword. :)

I agree otherwise that it is too much typing. Though if the notiong of
const was introduced I would prefer to see a full OO concept of const
functions and classes. That'd be more useful to me at this point.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
       http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
       http://wiki.disemia.com/HaXe

A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Preprocessor (Re: [haXe] Const support)

edA-qa mort-ora-y
[hidden email] wrote:
> Which preprocessor do you use? I am looking into using one :-)

I'm using m4. The dhlib project has a nice bash wrapper which adds all
sorts of common options -- as well as some common include files.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Const support

Cauê W.
In reply to this post by Armén
the cool thing about the const keyword is that it would enable all kinds of optimizations in haXe, as the value is considered immutable, even if it is a temp var

2010/4/21 [hidden email] <[hidden email]>
Which preprocessor do you use? I am looking into using one :-)

On Mon, Apr 19, 2010 at 07:35, edA-qa mort-ora-y <[hidden email]> wrote:
David S. Rodrigues wrote:
> Hello haxers!
> See my suggestion: haxe.org/forum/thread/1595
> <http://haxe.org/forum/thread/1595>

Well, since I use a preprocessor I already have the "CONST" keyword. :)

I agree otherwise that it is too much typing. Though if the notiong of
const was introduced I would prefer to see a full OO concept of const
functions and classes. That'd be more useful to me at this point.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
       http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
       http://wiki.disemia.com/HaXe

A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--

haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org