-
Notifications
You must be signed in to change notification settings - Fork 62
assert with body #4540
Comments
[@lucaswerkmeister] I still think it’s much clearer with assert (exists length, nonempty sequence, length>0) else {
return null;
} |
[@FroMage] So the difference with |
[@gavinking] 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. |
[@quintesse] 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 |
[@Zambonifofex] 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);
} |
[@bjansen] Oh so now I could rewrite this Java code:
to a nice
instead of the ugly
I like that 👍 |
[@RossTate] I agree with @lucaswerkmeister, the |
[@luolong] 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. |
[@FroMage] I'd also put an |
[@davidfestal] +1 for the |
[@lukedegruchy] +1 for else. |
[@ncorai] +1 for else |
[@Zambonifofex] I thought I had posted this already, but apparently not: besides my distaste for this feature (and my preference for |
[@jvasileff] 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 |
Can't help but think of unless(exists a, exists b) {
return null;
} The proposed if (exists a, exists b) else {
return null;
} .. but I guess that Extending I guess assert would also require that the block always terminates the containing function call somehow - otherwise it would not be an assertion? Unless and if! would not have this requirement I guess. |
@xkr47 I suggested |
I like the if !(exists length, nonempty sequence, length > 0) {
return null;
} |
@Zambonifofex true.. if (!(exists length, nonempty sequence, length > 0)) { |
[@gavinking] In #3997 it was proposed that we could support stuff like this:
Even though #3997 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".
[Migrated from ceylon/ceylon-spec#1434]
The text was updated successfully, but these errors were encountered: