Need feedback #16
Replies: 12 comments 33 replies
-
I don't really have any strong preference for case as long as a consistent policy is adopted. Lowercase is slightly more aesthetically pleasing, but using uppercase has the advantage that it's consistent with
|
Beta Was this translation helpful? Give feedback.
-
Pros of KIM syntax:
extrapolating (using
or even multiline attributes, eg (with some other modifiers):
Personally I consider post-declaration better as far as it allows more complex expressions. Technicalities: as far as you want to put checks into non-conflicting symbol space, writing (switching) parser/tokenizer is easier following known token after it happen instead of doing some predictions where expression (check) may or may not happen Consistency: what about subs?
vs
or another syntax like
|
Beta Was this translation helpful? Give feedback.
-
In short, I'd prefer all uppercase types, and the already existing syntax in favor of the my INT $count = 0 ; True to the years old documentation (that's finally being implemented):
I think, technically, there should be some foundation already set up in the source code to implement this more easily. |
Beta Was this translation helpful? Give feedback.
-
On 2023-06-14 10:15, Ovid wrote:
built-in (e.g., not user-defined) checks, are currently all
|UPPERCASE|. Some might want them title-cased and others want all
lower-case reserved for built-in checks.
All UPPERCASE for built-in, LGTM.
Title-case (strongly suggested) for User-defined.
checks use KIM syntax
<https://ovid.github.io/articles/language-design-consistency.html#who-the-hell-is-kim>:
|KEYWORD IDENTIFIER MODIFIERS SETUP|.
# KEYWORD IDENTIFIER MODIFIERS SETUP
my $count :of(INT) = 0;
Also goes fine with me,
because I think one can use
T_Int my ($c1, $c2) = (0, 0);
as sugar for
my ($c1, $c2) :of(INT) = (0, 0);
…-- Ruud
|
Beta Was this translation helpful? Give feedback.
-
I'm also fine with fully uppercase builtin check names I was strongly in favor of the existing syntax I would rather have I'd started a project to see if could port Hemidall's tests over to the current syntax using Lexical::Type and Variable::Magic and I ran into the fact that we simply do not have enough hooks to make it work in any useful way at all. Maybe rather than dropping a the full check system PRC … maybe a smaller PRC to expand or remove the current syntax hooks? That'll inform what's actually possible … and make some of this conversation moot. |
Beta Was this translation helpful? Give feedback.
-
Some initial feedback, here for want of a better place to put it: I don't like attributes here. It needs to be much more "embedded" in the syntax, because these things need to be able to occur at a lot more places than just the entry/exit points of subs. They need to go on object fields, multi sub and multi method, match/case, etc... subtype PositiveInt as INT where { $_ > 0 };
my PositiveInt $z;
sub f(PositiveInt $y) { ... }
class C {
field PositiveInt $x;
method PositiveInt($w) { ... }
}
multi sub g(PositiveInt $v) { ... }
multi sub g(NegativeInt $v) { ... }
match($u : is) {
case(PositiveInt) { ... }
}
if($t is PositiveInt) { ... } So far I haven't seen any consideration of any of theabove around these discussions. |
Beta Was this translation helpful? Give feedback.
-
After giving this a lot of thought, I think I'm ready to start writing a proposal. Though I like attributes, the fact that using a more standard syntax will make checks more accessible to most programmers seems like a good thing. Further, I want to encourage the use of checks rather than have built-in disaffordances to use native checks. Thus, I am proposing the following.
my int ($foo, $bar) = (0,0); # points 1, 2, and 5
state PositiveInt $limit = 3; # points 1 and 3
our int|undef $total; # points 1, 2, 5
sub fibonacci (int $nth) UInt { # points 3 and 4
...
}
sub customers (str['active', 'inactive'] $status) array[obj[Customer]] { # points 3 and 4
...
}
check CustomerStatus :isa(str['active', 'inactive']);
sub customers (CustomerStatus $status) array[obj[Customer]] { # points 3 and 4
...
} These are compromises. I don't know if they're great ones, but they give us declarative runtime data checks, with the caveat that not everyone will be thrilled. Where and how the user-defined checks will be defined is an open issue. Currently, I get tired of dealing with this: use WebService::NASA::Moose types => [
qw(
Bool
Enum
HashRef
InstanceOf
Latitude
Longitude
)
]; For the above, I have to manually curate that list of types and leaving one in which is unused pollutes the namespace (hopefully not a problem for this proposal). However, what really bites me is doing this: param openapi => ( isa => Maybe [NonEmptyStr], required => 0 ); And that fails at compile time because I again forgot to include use checks 'WebService::NASA::Types'; And with that, I automatically get all relevant checks (including defaults), but without the namespace pollution I would get now. |
Beta Was this translation helpful? Give feedback.
-
If we have multiple variables returned from a sub, we have sub foo ($bar) list[int, str] {
...
return ( $count, $name );
} |
Beta Was this translation helpful? Give feedback.
-
The following doesn't quite fit with the above: my @scores :of(100 => NUM) = (0) x 100; # Must store exactly 100 elements; each must be a number
my @data :of(0..9 => DEF); # Must store no more than nine elements; each must be defined
my @events :of(1..inf => OBJ) = get_events(); # Must store one or more elements; each must be an object I am imaging that a naïve rewrite fails: my 100[num]@scores = (0) x 100; # Must store exactly 100 elements; each must be a number
my 0..9[def] @data ; # Must store no more than nine elements; each must be defined
my 1..inf[obj] @events = get_events(); # Must store one or more elements; each must be an object So unless we can think of a clever inline syntax, those might need to be user defined checks, but here's a first pass at an inline syntax: my num[length[100]] @scores = (0) x 100; # Must store exactly 100 elements; each must be a number
my def[length[0..9]] @data ; # Must store no more than nine elements; each must be defined
my obj[length[1..inf]] @events = get_events(); # Must store one or more elements; each must be an object But that feels wrong because |
Beta Was this translation helpful? Give feedback.
-
Just another usecase - will it be supported (not necessarily in mvp) ?
|
Beta Was this translation helpful? Give feedback.
-
OK, we have the following (with item five reworded per @perigrin's suggestion):
I thought people would object to the case change in two and three, but no one seems to be objecting. Regarding @leonerd's concerns:
The above is covered in user-defined checks, with the caveat that the syntax might change:
The above are covered in the proposal (with the caveat that they use attributes).
Check names are not in the namespace, so naming a method
I think multisubs are awesome, but well out of the scope of what we're currently doing. In particular, user-defined checks make this a nightmare:
I don't know how to specify that since we don't yet have
I would love to see that, but
|
Beta Was this translation helpful? Give feedback.
-
There's been some great discussion here, but I realize it's hard to follow the key points because a lot of extra chatter has been here. I'll try to get some clarity by posting a polls regarding the ideas. Hopefully a simple vote will make things easier for those items we have better clarity on. |
Beta Was this translation helpful? Give feedback.
-
Tagging you in hopes you'll see this.
@druud @happy-barney @perigrin @rabbiveesh @rwp0 @SysPete @tobyink @demerphq
Hi all,
In its current state, the
Data::Checks
module should not be on the CPAN. Despite having almost 200K tests, it's not ready for prime time. The full specification lays down the rationale for semantics, but I can't rewrite that as a PPC unless we can agree on at least two things.Casing
I discuss a bit of this here.
In short, built-in (e.g., not user-defined) checks, are currently all
UPPERCASE
. Some might want them title-cased and others want all lower-case reserved for built-in checks.Syntax
Currently, checks use KIM syntax:
KEYWORD IDENTIFIER MODIFIERS SETUP
.However, there's been considerable annoyance over that from a few people. It's been suggested we use the
TYPE
syntax we currently have. Fromperldoc -f my
:Thus, we get this:
If we switch to lower-case reserved for built in checks, we get this:
That has the advantage of looking like most other programming languages, though for complex checks, are there going to be cases where we have parsing errors? If we go this route, these must not be in the namespace. We don't want Perl trying to parse the above as
my int($count) = 0;
because if someone declares a subroutine with the same name as a check, it breaks.Feedback Needed!
I am not making and recommendations on any of this. I want to hear feedback from you before we open this up to the wider Perl community.
Considerations:
Beta Was this translation helpful? Give feedback.
All reactions