Hi Dmitry and Joe,

On Mon, Feb 9, 2015 at 6:01 PM, Dmitry Stogov <dmi...@zend.com> wrote:

> Usage of "return" is a good idea.
> The more heads the better result :)
>

Less additional reserved word :)
So I'll use "require" and "return" for D like RFC.
We haven't talk much about invariants. I'll write my idea.

Current RFC is large enough already, I'll prepare new one.
We may decide what to do with 2 RFCs.

We have choices for with block or without block. I prefer with block
version, since
assert expression could be messy. With block, IDE may do it's jobs. i.e.
Hide blocks.

==============================================
Function/Method

[With block]
function foo()
require {
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
}
return {
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
}
invariant {
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
}
{
   // body
}

_OR_

[Without block]
function foo() {
  require(assert-expr, 'msg');
  require(assert-expr, 'msg');
  require(assert-expr, 'msg');
  invariant(assert-expr, 'msg');
  invariant(assert-expr, 'msg');
  invariant(assert-expr, 'msg');
  return(assert-expr, 'msg');
  return(assert-expr, 'msg');
  return(assert-expr, 'msg');

  // function body
}


Currently, following code wouldn't work (PHP 7.0.0-dev)
----------
assert(function() {return FALSE;}, 'AAAAA');
----------

For block version, which do you prefer, allow any PHP syntax or assert
only?
People may use anonymous function  to do fancy jobs anyway if it's
supported.

No block version only accepts EXPR obviously, but anonymous function may
be used with this as well.


==============================================
Class invariants

[With block]
class Foo {
  __invariants() {
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  }
}

_OR_

[Without block]
class Foo {
  __construct() {
    invariant(assert-expr, 'msg'); // Only allow in __construct()? Allowing
invariant.
    invariant(assert-expr, 'msg');
    invariant(assert-expr, 'msg');
  }
}


==============================================
Global invariant

I'm not sure if we should have

function __invariants() {
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
}

_OR_

invariant {
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
  assert(assert-expr, 'msg');
}

to assert global vars, whole app state, etc. It may be useful for unit
tests as well as app development.


I'll start working after I get comment from you.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net

Reply via email to