-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert with body #1434
Comments
I still think it’s much clearer with assert (exists length, nonempty sequence, length>0) else {
return null;
} |
So the difference with |
Well the really big difference is that to write the above with if (!exists length) {
return null;
}
if (!nonempty sequence) {
return null;
}
if (length<=0) {
return null;
} Which is significantly worse. |
I can't help but intensely dislike this, but I don't see any other option since we decided a long time ago to have this |
Honestly, I agree with @quintesse. I think a better aproach would be to allow people to put if!(exists bar, foo())
{
assert(false);
}
bar.baz(); Same for But also, I agree with @gavinking that these "guard" thingles are not very ceylonic. If you end up with a bunch of if(!exists foo) { return(null); }
if(!exists bar) { return(null); }
if(!exists baz) { return(null); }
// actual code becomes if!(exists foo, exists bar, exists baz)
{
// actual code
}
else
{
return(null);
} |
Oh so now I could rewrite this Java code:
to a nice
instead of the ugly
I like that 👍 |
I agree with @lucaswerkmeister, the |
I somewhat dislike the Although, I can see how it makes the it more explicit when the block is being invoked... I would however add an additional condition to the assertion failure block that it has to definitely return. Otherwise it is indistinguishable from |
Yes, of course, I'm assuming that. |
I'd also put an |
+1 for the |
+1 for else. |
+1 for else |
I thought I had posted this already, but apparently not: besides my distaste for this feature (and my preference for |
I really like the idea, but I'm not sure about the syntax. The If if any (!exists length, !nonempty sequence, length <= zero) {
return;
} perhaps subtle, but another idea would be to use if (!exists length; !nonempty sequence; length <= zero) {
return;
} |
The if!(foo, bar, baz)
{
print("hi");
} is equivalent to if(!(foo && bar && baz))
{
print("hi");
} Of course, that substituition wouldn't work for |
In #891 it was proposed that we could support stuff like this:
Even though #891 is now implemented, there may still be value in that. I personally find it to be a more pleasing and more powerful way to write "guards".
The text was updated successfully, but these errors were encountered: