Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92658 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21118 invoked from network); 23 Apr 2016 16:21:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Apr 2016 16:21:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.162 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.162 mx206.easyname.com Received: from [212.232.25.162] ([212.232.25.162:41904] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/B1-07837-A01AB175 for ; Sat, 23 Apr 2016 12:21:31 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1au0JD-0001rM-OM; Sat, 23 Apr 2016 16:21:28 +0000 Reply-To: internals@lists.php.net References: To: Sara Golemon , internals , "dmitry@zend.com >> Dmitry Stogov" Message-ID: <571BA0F0.2030400@fleshgrinder.com> Date: Sat, 23 Apr 2016 18:21:04 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="W60ChiNPxcP5FCSP9FcwKNHov8nB1gX9K" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC] PHP Attributes From: php@fleshgrinder.com (Fleshgrinder) --W60ChiNPxcP5FCSP9FcwKNHov8nB1gX9K Content-Type: multipart/mixed; boundary="rSLeut9M0lVNQHkbmhavEHMSM7UeVfbIa" From: Fleshgrinder Reply-To: internals@lists.php.net To: Sara Golemon , internals , "dmitry@zend.com >> Dmitry Stogov" Message-ID: <571BA0F0.2030400@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC] PHP Attributes References: In-Reply-To: --rSLeut9M0lVNQHkbmhavEHMSM7UeVfbIa Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/22/2016 4:15 AM, Sara Golemon wrote: > All that said, I love the proposal overall, and I can't wait to > propose builtin annotations like <<__Memoize>>, <<__Mock>>, and > similar. >=20 I'd rather see these two functionalities added as modifiers at the language level instead since they change the code behavior rather dramatically. Not sure if knowledge of them is of interest in stages where annotations might not be readily available; this was a driving factor in Kotlin's decision what becomes a modifier or annotation.[1] I know that this is true for `@invariant`, `@require`, and `@ensure` as well, they are fully-fledged assertions after all. Especially the `@invariant` could be easily added as a magic method. [assert] assert.invariants =3D 1 Both `@require` and `@ensure` are a bit harder to implement at language level. The following is the best I can come up with and is inspired by the Eiffel syntax.[2] [assert] assert.preconditions =3D 1 assert.postconditions =3D 1 balance -=3D $this->balance - $sum; } require { $sum >=3D 0; $sum <=3D ($this->balance - self::MIN_BALANCE); } ensure { $this->balance =3D=3D=3D (old::$balance - $sum); } } $account =3D new Account; $account->withdraw(-10); /* Uncaught PreconditionError: $sum >=3D 0 */ $account->withdraw(10); /* Uncaught PreconditionError: $sum <=3D ($this->balance - self::MIN_BALANCE= ) */ $account->deposit(10); $account->withdraw(5); /* Uncaught PostconditionError: $this->balance =3D=3D=3D (old::$balance - $s= um) */ ?> I actually think now that it would be better to go for this than for annotations. [1] http://blog.jetbrains.com/kotlin/2015/08/modifiers-vs-annotations/ [2] https://archive.eiffel.com/doc/online/eiffel50/intro/language/invitation-= 07.html --=20 Richard "Fleshgrinder" Fussenegger --rSLeut9M0lVNQHkbmhavEHMSM7UeVfbIa-- --W60ChiNPxcP5FCSP9FcwKNHov8nB1gX9K Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXG6D0AAoJEOKkKcqFPVVrzIIP/02GV1MvBRUgCxrkrOYjLCYB PcY6CcV6dqw84lUyf9M3LWbDFtf/heIbxMW+SIKAYoPIZ0tEk+qryciouTmnmtUJ 27n+BbDlfx8zTDH89jceFJBgQNCylVPuvg9cASxRfIYXDommTpb15PChppohz4Ir j+RY0w9/6N9STzPOvLzOeZpoeqr7BbRYJwhIc+yc9fUqBhTjVqgkPx1TOzKxByTL S1f+0xthCowQC5AhvuqV+eRPRGkQElCUhaL2WxrM8lnzqPttw5Sy0fd2EACuOS5T /4IlW04GsJE2rAethBX9VyrhhaDTv2PxRhYITrIXmKhUY+8d6TG/8KvVc1N7UflH aPtkgHrI0vMvinX26bpFoq5m5TPkt9VCG9BnD06J9FXxwoJSFSutA6s3UxGGfQgc UkzCvy7U760UzVWzyET9daFY7e5vy20xPCr75rHO8GEq2ZRUYEuHdT1yDwbToacb plBt07l4a8ASIGqGFbiclWbaLyZflNR4wp60fAYNkBzNSFJQLckkTdcjfftrnmel vD8I9sTlxFle7jxS8NsuAYflukwHl9lM1g/KmdIcnxDmA6sWMRRrT3qK3lqDtPU1 r12q8XGrWnOSXcpbSdy9gM4W6yDkbu7P/YSONsNrWroayOoTP3ZCHzGB8964mRk5 cpFMa+LMYevlFIQPOs+0 =JkwZ -----END PGP SIGNATURE----- --W60ChiNPxcP5FCSP9FcwKNHov8nB1gX9K--