Discussion:
[perl #57634] [RFC] Remove ".globalconst" from PIR
(too old to reply)
Klaas-Jan Stol
2008-08-05 17:47:28 UTC
Permalink
# New Ticket Created by Klaas-Jan Stol
# Please include the string: [perl #57634]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=57634 >


hi,

in PIR you can use the .globalconst directive in a sub to define a constant
that is globally accessible.
Likewise, you can use the .const directive in a sub that is local to that
sub.

.sub foo
.globalconst int answer = 42
.const num PI = 3.14

.end

answer in this case is globally accessible (in any other sub, that is parsed
AFTER the foo subroutine, I should note)
PI in this case is only accessible in this subroutine foo.


However, I question the need for .globalconst, as the .const directive can
also be used /outside/ of a subroutine, like so:

.const int answer = 42


Therefore, the .globalconst directive seems to be superfluous; why have 2
directives that do the same thing; if a .globalconst is accessible globally
anyway, there's no need to define it WITHIN a sub.

Therefore, my proposal is to remove the .globalconst directive;
whenever you need to have a global const, use .const outside of a
subroutine.
whenever you need to have a local const (in a sub), use .const inside a
subroutine.

comments welcome,
kjs
Klaas-Jan Stol
2008-08-14 11:16:32 UTC
Permalink
What's the general feeling about this proposal?
Any thoughts of the architect?

kjs

On Tue, Aug 5, 2008 at 6:47 PM, via RT Klaas-Jan Stol <
Post by Klaas-Jan Stol
# New Ticket Created by Klaas-Jan Stol
# Please include the string: [perl #57634]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=57634 >
hi,
in PIR you can use the .globalconst directive in a sub to define a constant
that is globally accessible.
Likewise, you can use the .const directive in a sub that is local to that
sub.
.sub foo
.globalconst int answer = 42
.const num PI = 3.14
.end
answer in this case is globally accessible (in any other sub, that is parsed
AFTER the foo subroutine, I should note)
PI in this case is only accessible in this subroutine foo.
However, I question the need for .globalconst, as the .const directive can
.const int answer = 42
Therefore, the .globalconst directive seems to be superfluous; why have 2
directives that do the same thing; if a .globalconst is accessible globally
anyway, there's no need to define it WITHIN a sub.
Therefore, my proposal is to remove the .globalconst directive;
whenever you need to have a global const, use .const outside of a
subroutine.
whenever you need to have a local const (in a sub), use .const inside a
subroutine.
comments welcome,
kjs
Allison Randal
2008-08-16 08:14:16 UTC
Permalink
Post by Klaas-Jan Stol
Therefore, my proposal is to remove the .globalconst directive;
whenever you need to have a global const, use .const outside of a
subroutine.
whenever you need to have a local const (in a sub), use .const inside a
subroutine.
If we're going to remove one, let's deprecate .const outside of sub
blocks, and make .globalconst mean a global constant everywhere.
Consistency is a good thing, but so are clear distinctions between
similar-but-different things.

Allison
Patrick R. Michaud
2008-12-27 16:28:32 UTC
Permalink
Post by Allison Randal
If we're going to remove one, let's deprecate .const outside of sub
blocks, and make .globalconst mean a global constant everywhere.
Consistency is a good thing, but so are clear distinctions between
similar-but-different things.
I thought a bit more on this, and global .consts are more common than
sub-local consts (I think). Following the Huffman principle, I think it
would be nicer then to use '.localconst' for a local const, only
available in a sub, and .const for global constants. (and thus removing
.globalconst).
+1

Pm

Loading...