Return-Path: X-Original-To: apmail-cloudstack-dev-archive@www.apache.org Delivered-To: apmail-cloudstack-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 722F91837B for ; Sat, 16 Jan 2016 12:56:58 +0000 (UTC) Received: (qmail 53553 invoked by uid 500); 16 Jan 2016 12:56:58 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 53490 invoked by uid 500); 16 Jan 2016 12:56:58 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 53477 invoked by uid 99); 16 Jan 2016 12:56:57 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jan 2016 12:56:57 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 08634C118F for ; Sat, 16 Jan 2016 12:56:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=3, SPF_HELO_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=shapeblue.onmicrosoft.com header.b=LxPyT4h9; dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=shapeblue.onmicrosoft.com header.b=F3yPEv4v Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id aEKzskYRWDC3 for ; Sat, 16 Jan 2016 12:56:43 +0000 (UTC) Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1on0145.outbound.protection.outlook.com [157.56.112.145]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 8122A31AD1 for ; Sat, 16 Jan 2016 12:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shapeblue.onmicrosoft.com; s=selector1-shapeblue-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=iSs23k/DjSz00ekwTrrL449NzL2XBKIwoW8mR6buabk=; b=LxPyT4h9yhl1NaBoGkTL5gbW3lW6H/Oek1FyxWJnLn5wc3tNUTKTiChcwQn9WHc5GH6JUDEzJlcW1V7z3ttf9MU9ljEbAD5zvQGPE7ElQG6BieAWgSK6zulSmO30Iu92n8/UqNSZwYh59q+5RiiXz786tOVKDn9kr8mkkHn2PE0= Received: from VI1PR07CA0055.eurprd07.prod.outlook.com (10.164.94.151) by AM4PR07MB1489.eurprd07.prod.outlook.com (10.165.248.141) with Microsoft SMTP Server (TLS) id 15.1.365.19; Sat, 16 Jan 2016 12:56:34 +0000 Received: from AM1FFO11FD002.protection.gbl (2a01:111:f400:7e00::128) by VI1PR07CA0055.outlook.office365.com (2a01:111:e400:5967::23) with Microsoft SMTP Server (TLS) id 15.1.365.19 via Frontend Transport; Sat, 16 Jan 2016 12:56:33 +0000 Authentication-Results: spf=fail (sender IP is 104.40.229.156) smtp.mailfrom=shapeblue.com; cloudstack.apache.org; dkim=fail (signature did not verify) header.d=shapeblue.onmicrosoft.com;cloudstack.apache.org; dmarc=none action=none header.from=shapeblue.com; Received-SPF: Fail (protection.outlook.com: domain of shapeblue.com does not designate 104.40.229.156 as permitted sender) receiver=protection.outlook.com; client-ip=104.40.229.156; helo=smtp.eu1.exclaimer.net; Received: from smtp.eu1.exclaimer.net (104.40.229.156) by AM1FFO11FD002.mail.protection.outlook.com (10.174.64.84) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Sat, 16 Jan 2016 12:56:32 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (213.199.154.207) by smtp.eu1.exclaimer.net (104.40.229.156) with Exclaimer Signature Manager ESMTP Proxy smtp.eu1.exclaimer.net; Sat, 16 Jan 2016 12:56:32 +0000 X-ExclaimerHostedSignatures-MessageProcessed: true Content-Type: multipart/related; boundary="----_=_NextPart_1474dbf8-a6de-40c6-b7f0-9edd64c473bb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shapeblue.onmicrosoft.com; s=selector1-shapeblue-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=iChXM9jDvP9NZLqLPCWL/Z01MUkAV+3TR+PHiqkI134=; b=F3yPEv4vAVpLJDyCH9ZtOmM8nL5UjJZLdnoFGefN4v6yAzzhIwGQQx0Aw7XfyDCy8B70lzZJpvAabszJ8gJW/4FGhW3f8kFM3U2nnOdXJGgOCBELIlXgw21cKP6LfW+1zch4EPrrVvYKEh180uibPUXTvfRFZ1m3+FeBHyawOqo= Received: from DB5PR07MB0774.eurprd07.prod.outlook.com (10.161.195.22) by DB5PR07MB0776.eurprd07.prod.outlook.com (10.161.195.24) with Microsoft SMTP Server (TLS) id 15.1.365.19; Sat, 16 Jan 2016 12:56:29 +0000 Received: from DB5PR07MB0774.eurprd07.prod.outlook.com ([10.161.195.22]) by DB5PR07MB0774.eurprd07.prod.outlook.com ([10.161.195.22]) with mapi id 15.01.0365.023; Sat, 16 Jan 2016 12:56:29 +0000 From: John Burwell To: "dev@cloudstack.apache.org" Subject: Re: [DISCUSS][PROPOSE] use of optional instead of null Thread-Topic: [DISCUSS][PROPOSE] use of optional instead of null Thread-Index: AQHRIVNZgk4YknrZxUW/jRT1YPNxK57+d/iA Date: Sat, 16 Jan 2016 12:56:28 +0000 Message-ID: <6B16B76C-F2F6-4A07-A614-9FAC27CE5CB9@shapeblue.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.2104) authentication-results: spf=none (sender IP is ) smtp.mailfrom=john.burwell@shapeblue.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [98.218.146.14] X-Microsoft-Exchange-Diagnostics-untrusted: 1;DB5PR07MB0776;5:9fbbVoLjiLc5M1r3ZrcvxRI0WycSp/+I8RwGjQgDBD54KTS7ekdZrgvlqLNu34mGX55X17jj9wkLJS8T1SDiXhnbgJx/HpwqNECUb4hCmwVUXPZazyViXo+e4N83Vm13Lmqy3XeSO3ED61cz9Tl2KQ==;24:cKHn55n39qJqemTytYA115nx9j51VTns4jek+MEMR+S4Pf2UqwShLgwYJEKD5Aj0lvVR2iT/OOOiaR3dzHMPjGN1yyOh0hd4VtCWDjHZaFs= X-Microsoft-Antispam-Untrusted: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR07MB0776; X-MS-Office365-Filtering-Correlation-Id: 221743cb-393a-47d1-16b5-08d31e7475d8 X-Microsoft-Antispam-PRVS: x-exchange-antispam-report-test: UriScan:;UriScan:(121084725601253); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(3002001)(10201501046);SRVR:DB5PR07MB0776;BCL:0;PCL:0;RULEID:;SRVR:DB5PR07MB0776;BCL:0;PCL:0;RULEID:(102615245)(601004)(2401047)(520078)(5005006)(13021025)(13013025)(8121501046)(13016025)(13018025)(3002001)(10201501046);SRVR:AM4PR07MB1489;BCL:0;PCL:0;RULEID:;SRVR:AM4PR07MB1489; x-forefront-prvs: 0823A5777B X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10019020)(6009001)(199003)(189002)(164054003)(377454003)(24454002)(76176999)(83716003)(122556002)(87936001)(189998001)(5004730100002)(2351001)(33656002)(50226001)(107886002)(6116002)(77096005)(450100001)(5002640100001)(92566002)(2900100001)(15975445007)(11100500001)(102836003)(101416001)(110136002)(5001960100002)(2950100001)(40100003)(3846002)(2501003)(586003)(10400500002)(97736004)(50986999)(19580395003)(66066001)(19580405001)(57306001)(1096002)(86362001)(1220700001)(2906002)(81156007)(106116001)(106356001)(82746002)(36756003)(5008740100001)(105586002)(104396002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5PR07MB0776;H:DB5PR07MB0774.eurprd07.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: shapeblue.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR07MB0776 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM1FFO11FD002.protection.gbl X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD002;1:G9Qrb6FuM51YARWJQze5pHX32MHLt/zIUIRXQrybAoMpLMoVVVNSfAa5opLN3O4U7K8Bm+ouR3B0YoY6meBJXQ0bDeW1Ykolqs6Ny94FwJNOd01BCJcEnoyJESYKhCO0xHFCiL0DPPa7DBOk483lW+q/Dvmqeb/0X//2UGYt5298FJMctVVdXu3LfCK4pLZJgheANN2uRUJZDPoVbODMgSgE71Kdyw+BaZNL6rKzIrWcTkrtvXsK0/POY4y9E+skvtuXv167n5xsqBXybZzt4OhLIhGSTvCGd6HXIEphL25ja+pgHlrM1g3H2yA6i1vCIA+hNv0r3Xtj5ZfCsU4u2g== X-Forefront-Antispam-Report: CIP:104.40.229.156;CTRY:;IPV:CAL;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(13734003)(164054003)(24454002)(377454003)(19618635001)(6070500001)(1096002)(36756003)(107886002)(6116002)(92566002)(450100001)(2950100001)(586003)(18206015028)(2900100001)(956001)(5890100001)(10400500002)(5008740100001)(2501003)(40100003)(102836003)(11100500001)(2906002)(3846002)(1220700001)(189998001)(110136002)(77096005)(15974865002)(16601075003)(5004730100002)(5001970100001)(122556002)(512874002)(84326002)(19617315012)(6806005)(50986999)(87936001)(15975445007)(50226001)(76176999)(19580405001)(83716003)(2351001)(85426001)(26826002)(106466001)(16236675004)(19580395003)(15395725005)(575784001)(86362001)(57306001)(19627595001)(105606002)(17760045003)(33656002)(106116001)(82746002)(66066001)(104396002)(562774006);DIR:OUT;SFP:1102;SCL:1;SRVR:AM4PR07MB1489;H:smtp.eu1.exclaimer.net;FPR:;SPF:Fail;PTR:smtp.eu1.exclaimer.net;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM4PR07MB1489;2:8C1MkJRV2DRrgptuX3rub2+I1fPUtr01Ik67zpmVpMVPX9iBebRl2DxJA99jx+HrWdhcd43UFn3d0ooLloXdDz8+JuQ8hMke9q5PXs1sApqaOiQNzMhXHT9feqdllQePxCQgEPg656shR37OZtIyFQ==;3:NMUK6TwGEtGba0yUNNuzoYQZ86pyV+X/gjavEN6uX0sTnVJ/LC8rXFdGCgdg5sbI2EGurLp9nPow5pc/QRJVaHM+c0UrXjczf9Iyv+7z5gq39G5P5+uatEOAnPyxGsx29fF43JExPGBZzdcHC6w02BE9qC+t5Dr8II/FM0tdEpHwQSNpQEw0BsEsxZ8xwMOK24girlYjxxb1ojCBo/rhqqrarVMfF8F8E2q6hWMQWlhaIOmkccf1KBdpudujF+Gd;25:7e8fkj0Bk4e6tMMt4WHrn6pmDp0AkKTIo0GE34WldVUN/Zhn7yqPtf0SeBvuyTFkKsoz0gVHjEETNVi3qJCNIMJemo8V6qMiEp6YURysTZmIV2VSDsNLPilCc9KdycY+E4CUpyfJt8jn/5l85FJPSLckNN6Aied4KZWUEgEjxY/a/NZ3ETBzilsufS5awY3Mo/l7Zig8FdHjw8Zve+BMisuKi4pwDsgY11HzMYeGd/453y48r+r7UMbJcJj/BGlz;20:Lfhjfs2ZF/WkOoFmdNWUKuL+haMDNXQUF28NmuELMn68UsLqKWoqHHQ0v8q1+LMU/XFSJYMVybaPhyh8XXNfIRNpurMGz1mPZfiFuV8WOhwncCzN2ZknhrYHOszbNKnvbxrl8eP9fqBoQvthp6jQL9UKmyWZJrU8wOv6Y6HKHushiV6cjBR4e0EbtskIjSpX7e8qSh6+4gzSg95ge24r6yYAcYedyC8VDmyf9JUU4k0pL6pJNg9doLh5q4fTXe8C X-DkimResult-Test: Failed X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(3002015);SRVR:AM4PR07MB1489; X-Microsoft-Exchange-Diagnostics: 1;AM4PR07MB1489;4:JvY6SkC63WYp8EbqH+FCCt90tzgkyvnbYfZ+lWU2BHUNsK467JRtKO1uN5IL+eGNE0gMvUY793ASkY1dQobepeZqGKaA7YHXKeYWGiZCn/2vCsw5+aKRliLD3WITto3fRE/u9QCtkqmw2n1N+JpZA+y2OdqXj0CskOVT5MXNX7Ip+UZFYGMz+qrlnn1Duhmh1l2NenWWx8lJOrVt0IfJr+qNLg4jXv7jUI6Q+1hniU6ew2JnqZ4Iy98DIAL9AQcGCvaJdICSyXwV8h7+2ulxfC+mIvDkp6pnWCTWmUYyFkog4SzFBqF8+AGXmi+rQvRD6U6AFtCc6kWig02o8jsqQQAR2WgBb0Hls0fWGQ4twEcxpMRE+TQDQxbz8nWpiO+YIoAh5pW/Vw7iEbDjwN0SFEKj79ZliAGojCiPWruweluLl7/tpqYKNVdMrjx3HrTw9uVPJDLDAFycg7znnxXaxRYwXGkzKBASG8MafINSzCZvIA8vwdm/GaBj33hC0LaaCfhO3dtCA6oqxNtlwdEctA== X-Forefront-PRVS: 0823A5777B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM4PR07MB1489;23:S2QsSUcsM0vn3jAHAp/Kzhbs31hrkb6yUq4Tt2EBf?= =?us-ascii?Q?QKqnspP42IVS+yen/s+dzXbXIEv4R9bxE+Ru4pmBnNVZFRoy/B0pVlyVeomn?= =?us-ascii?Q?DHOLiqHbOUN2arflA5u1qsPfOBj4pTqiE7EpOF/Ba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MgJyZWnPvr9w5jSPBf8divOKZGm5RsnPunXAwhSFD2R0PrsER3vbThiW0Q7AmQPdAUsbO/wl1iXg/Ua7gSmZ6CbeWdOB4UIJiAQ==;24:LDrTq1R4XxzMDIXsUvG4Pj+PUwI+yQ14E2UAAMCuvF2Rltr0IGUOzGglrOq9JxTWOtghajG+VkRyedwXQpnRkcRbE0Uh3NQCh0E9MJuQumQ= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: shapeblue.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2016 12:56:32.3707 (UTC) X-MS-Exchange-CrossTenant-Id: fc8906f6-e50e-4dad-98a0-ec2e3abe14f5 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fc8906f6-e50e-4dad-98a0-ec2e3abe14f5;Ip=[104.40.229.156];Helo=[smtp.eu1.exclaimer.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR07MB1489 ------_=_NextPart_1474dbf8-a6de-40c6-b7f0-9edd64c473bb Content-Type: multipart/alternative; boundary="----_=_NextPart_3eb0ec31-7614-4bd7-b23e-117f74272f15" ------_=_NextPart_3eb0ec31-7614-4bd7-b23e-117f74272f15 Content-Language: en-US Content-Type: text/plain; charset="utf-8" Content-ID: <3CD38F68C989D348A7B954F6D7C3DA89@eurprd07.prod.outlook.com> Content-Transfer-Encoding: quoted-printable Daan, I completely agree that returning null is bad. Not only does it yield a ton= of useless null checks, it creates leaky abstractions by spreading the han= dling of the missing case out beyond the boundary of the class/subsystem. As a big proponent of the Null Object Pattern [1], I really wanted to like = Optional. It is a great concept in functional languages. So, I tried using = it in three (3) different projects since 2011. In all three systems, I woul= d say that, at best, it was no better than returning null, and, in other ca= ses, worse. Since Optional.get throws an exception when the wrapped value i= s null, all optional accesses must be defensively checked so the code base = is littered with code like the following: if (value.isPresent()) { return value.get(); } So, basically, you end up replacing null checks and NPEs with isPresent che= cks and a Guava exception. As a bonus, when exceptions occurred in producti= on, we had explain the meaning of them. The quickest explanation =E2=80=94 = =E2=80=9CThey are the new NPE=E2=80=9D. For all new developers on the proje= cts, we had one more thing to explain to them which, again, was asking them= to do something differently with no added value. Based on these experience= s, I prefer null checks to optional. While it is more effort (i.e. more code), I have gone back to using the Nul= l Object Pattern implemented in this manner [2]. Not only does this approac= h avoid NPEs, it also explicitly defines the behavior for the missing case.= For more complex examples, it can be unit tested to ensure the missing cas= e behaves as expected. Thanks, -John [1]: https://en.wikipedia.org/wiki/Null_Object_pattern [2]: https://gist.github.com/jburwell/f5162ad2d2de32c842b3 > [ShapeBlue] John Burwell ShapeBlue d: +44 (20) 3603 0542 | s: +1 (571) 403-2411 e: john.burwell@shapeblue.com | t: | w: www.shapeblue.com a: 53 Chandos Place, Covent Garden London WC2N 4HS UK [cid:image6e2aab.png@2caaed35.4cb517dd] Shape Blue Ltd is a company incorporated in England & Wales. ShapeBlue Serv= ices India LLP is a company incorporated in India and is operated under lic= ense from Shape Blue Ltd. Shape Blue Brasil Consultoria Ltda is a company i= ncorporated in Brasil and is operated under license from Shape Blue Ltd. Sh= apeBlue SA Pty Ltd is a company registered by The Republic of South Africa = and is traded under license from Shape Blue Ltd. ShapeBlue is a registered = trademark. This email and any attachments to it may be confidential and are intended s= olely for the use of the individual to whom it is addressed. Any views or o= pinions expressed are solely those of the author and do not necessarily rep= resent those of Shape Blue Ltd or related companies. If you are not the int= ended recipient of this email, you must neither take any action based upon = its contents, nor copy or show it to anyone. Please contact the sender if y= ou believe you have received this email in error. On Nov 17, 2015, at 11:16 AM, Daan Hoogland wrote= : > > LS, > > As a spin off from a discussion in a PR where it is no longer relevant I > made another PR to show the principle of the use of Optionals[1] > > > Miguel from Schuberg Philis has been proposing this as replacement of the > bad practice of returning null in methods and I agree. In seldom cases it > might be more expedient to throw an exception, most notably when a null i= s > returned but no check against is done in the calling method. In those cas= es > throwing a CloudRuntimeException would be an easier way to go then the > pattern in this PR. This is a runtime exception however so maybe creating > an explicit one is more appropriate in those places. > > Anyway I want to propose to move to using the pattern from the PR from no= w > on. > > =E2=80=8B[1] https://github.com/apache/cloudstack/pull/1060=E2=80=8B > > =E2=80=8Bthoughts?=E2=80=8B > -- > Daan Find out more about ShapeBlue and our range of CloudStack related services: IaaS Cloud Design & Build | CSForge =E2=80=93 rapid IaaS deployment framework CloudStack Consulting | Cloud= Stack Software Engineering CloudStack Infrastructure Support | CloudStack Bootcamp Training Courses ------_=_NextPart_3eb0ec31-7614-4bd7-b23e-117f74272f15 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Daan,

I completely agree that returning null is bad. Not only does it yield a ton= of useless null checks, it creates leaky abstractions by spreading the han= dling of the missing case out beyond the boundary of the class/subsystem.
As a big proponent of the Null Object Pattern [1], I really wanted to like = Optional. It is a great concept in functional languages. So, I tried using = it in three (3) different projects since 2011. In all three systems, I woul= d say that, at best, it was no better than returning null, and, in other cases, worse. Since Optional.get throws= an exception when the wrapped value is null, all optional accesses must be= defensively checked so the code base is littered with code like the follow= ing:

if (value.isPresent()) {
return value.get();
}

So, basically, you end up replacing null checks and NPEs with isPresent che= cks and a Guava exception. As a bonus, when exceptions occurred in producti= on, we had explain the meaning of them. The quickest explanation =E2=80=94 = =E2=80=9CThey are the new NPE=E2=80=9D. For all new developers on the projects, we had one more thing to explain to them which, again, wa= s asking them to do something differently with no added value. Based on the= se experiences, I prefer null checks to optional.

While it is more effort (i.e. more code), I have gone back to using the Nul= l Object Pattern implemented in this manner [2]. Not only does this approac= h avoid NPEs, it also explicitly defines the behavior for the missing case.= For more complex examples, it can be unit tested to ensure the missing case behaves as expected.

Thanks,
-John

[1]: https://en.wikipedia.org/wiki/Null_Object_pattern
[2]: https://gist.github.com/jburwell/f5162ad2d2de32c842b3

>

3D"=
John Burwell
ShapeBlue
d:  +44 (20) = ;3603 0542 | s: +1 (571) 403-2411 
e:  john.burwell@shapeblue.com | t:   |  w:  www.shapeblue.com
a:  53 Chandos Place, Covent Garden London WC2N&n= bsp;4HS UK
3D"Twitter"3D""
Shape Blue Ltd is a company incorporated in England & Wales. ShapeBlue = Services India LLP is a company incorporated in India and is operated under= license from Shape Blue Ltd. Shape Blue Brasil Consultoria Ltda is a compa= ny incorporated in Brasil and is operated under license from Shape Blue Ltd. ShapeBlue SA Pty Ltd is a company regis= tered by The Republic of South Africa and is traded under license from Shap= e Blue Ltd. ShapeBlue is a registered trademark.
This email and any attachments to it may be confidential and are intended s= olely for the use of the individual to whom it is addressed. Any views or o= pinions expressed are solely those of the author and do not necessarily rep= resent those of Shape Blue Ltd or related companies. If you are not the intended recipient of this email, yo= u must neither take any action based upon its contents, nor copy or show it= to anyone. Please contact the sender if you believe you have received this= email in error.


On Nov 17, 2015, at 11:16 AM, Daan Hoogland <daan.hoogland@gmail.com>= wrote:
>
> LS,
>
> As a spin off from a discussion in a PR where it is no longer relevant= I
> made another PR to show the principle of the use of Optionals[1]
> <https://github.com/apache/cloudstack/pull/1060>
>
> Miguel from Schuberg Philis has been proposing this as replacement of = the
> bad practice of returning null in methods and I agree. In seldom cases= it
> might be more expedient to throw an exception, most notably when a nul= l is
> returned but no check against is done in the calling method. In those = cases
> throwing a CloudRuntimeException would be an easier way to go then the=
> pattern in this PR. This is a runtime exception however so maybe creat= ing
> an explicit one is more appropriate in those places.
>
> Anyway I want to propose to move to using the pattern from the PR from= now
> on.
>
> =E2=80=8B[1] https://github.com/apache/cloudstack/pull/1060=E2=80=8B >
> =E2=80=8Bthoughts?=E2=80=8B
> --
> Daan

------_=_NextPart_3eb0ec31-7614-4bd7-b23e-117f74272f15-- ------_=_NextPart_1474dbf8-a6de-40c6-b7f0-9edd64c473bb--