Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 96B1B200BB7 for ; Wed, 9 Nov 2016 16:38:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9540B160AFA; Wed, 9 Nov 2016 15:38:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B2B63160AEB for ; Wed, 9 Nov 2016 16:38:00 +0100 (CET) Received: (qmail 69444 invoked by uid 500); 9 Nov 2016 15:37:59 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 69428 invoked by uid 99); 9 Nov 2016 15:37:59 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Nov 2016 15:37:59 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id E9903C0D8D for ; Wed, 9 Nov 2016 15:37:58 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.379 X-Spam-Level: ** X-Spam-Status: No, score=2.379 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 0Q1HwCdVsvbK for ; Wed, 9 Nov 2016 15:37:56 +0000 (UTC) Received: from mail-oi0-f51.google.com (mail-oi0-f51.google.com [209.85.218.51]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id C106D5F1B8 for ; Wed, 9 Nov 2016 15:37:55 +0000 (UTC) Received: by mail-oi0-f51.google.com with SMTP id 128so240250053oih.0 for ; Wed, 09 Nov 2016 07:37:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0DYcwD3oMOlWkPvKV2qKW/gdqn6f9JxuXu1rBmxxxRQ=; b=Fdora2vbHdaEHCqqPRla9rrd4c2riWr9qzBvBqi8gbbTgGyRk3Il+6KeIwwfzSl1dH MTOiQaVpL+syS68kSCqL/NpuJSe8K9LXTzakKSKQT7CXHQghqcxmI/sIWDJt0sDqSI3f t9xLIyBFymvDtAs+5yNCdxbzYyvGu3ZZyCtyKwBapdHDFjLlQtnq/uD9Qr5hxmi+nOQS sqQ/GimM2hWaqpvKj6stokRIFlFFFX495fwLigWq2DnQN/p2VTjV1iDAMc9eoFB4Jcrz P25jCG15468GeCoA/cDZIyEcQemh6kDVCXsX3NVA86N+6cZE2ikhHAENcjPcrQ7x0o/y +cOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0DYcwD3oMOlWkPvKV2qKW/gdqn6f9JxuXu1rBmxxxRQ=; b=N1+AB4xCw/ICJnFlijzEzcoXzubut4ECwQ9UXiOjPEi0VHs49IQAlQG9VGvGNWqxJN 9z1o//uZCwTA19FOwkZMNk6yXG2qKlITQk99SOAG62VpkFk/OJLlQcg3GKNJ/MWQqb1v NWoZjmgRGiRjeFOpvtUVt0E05Av2360gvNqShKS4sISP7n1bidwXqF5bymr8Ex5+FFOY 3nHNljSwV+dMV36e+SMt98+Nuq02uZjYlIAvkNnx7yH0uCFKZMh14HCTjc3H3t797hyL 2bURaIHmxhoJaj4WMvGWsyxuQv5PlGaI/GbjEnVYx/qESLUQtskV3V5uYCH55qT4eEEb O4XA== X-Gm-Message-State: ABUngvcvwvG40iV6kTykdooGn+nM0cXEoFoK8Nx0gKxHDVa2+JJ8WETkZjir1H9qGc68EKbqEiq1jR4gyYsrjQ== X-Received: by 10.157.29.8 with SMTP id m8mr192849otm.18.1478705871464; Wed, 09 Nov 2016 07:37:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.202.102.96 with HTTP; Wed, 9 Nov 2016 07:37:50 -0800 (PST) In-Reply-To: <6636D008-F782-4AAC-B4A7-0AE86F7C271E@ocs.cz> References: <1478621298812-5736558.post@n5.nabble.com> <8F0E7347-05E3-48A1-A4D4-8E4873305C11@ocs.cz> <1478702991495-5736597.post@n5.nabble.com> <6636D008-F782-4AAC-B4A7-0AE86F7C271E@ocs.cz> From: =?UTF-8?Q?C=C3=A9dric_Champeau?= Date: Wed, 9 Nov 2016 16:37:50 +0100 Message-ID: Subject: Re: Safe index for Groovy 3 To: dev@groovy.apache.org Cc: Daniel Sun , dev@groovy.incubator.apache.org Content-Type: multipart/alternative; boundary=001a11376f92322d8c0540e00a82 archived-at: Wed, 09 Nov 2016 15:38:01 -0000 --001a11376f92322d8c0540e00a82 Content-Type: text/plain; charset=UTF-8 Not throwing an NPE doesn't mean you are safe. It means it doesn't throw errors, but you gave away on semantics. NPEs are often blamed, but they correspond to developer errors. Only the developer knows if null is relevant or not. I'm totally -1 on this. 2016-11-09 16:33 GMT+01:00 OC : > Daniel, > > On 9. 11. 2016, at 15:49, Daniel Sun wrote: > > > IMHO, 'full safe' switch will change the semantic of existing '.' > > Absolutely. > > > which may reduce the maintainability and readability of program > > Quite the contrary. > > As always, I might be overlooking something of importance, but it seems to > be whomever whose code relies on NPE would never use that switch [*]. > > On the other hand, for us who *NEVER* want to see *ANY* NPE, and at the > moment, are thus forced to an ugly mess of special null metaclasses and > ASTTs, it would help tremendously, making the code considerably more stable > and safer (e.g., since those ASTTs tend to clash with traits, and who know > with what else in future). > > Now, [*] I have (just again!) forgot the terrible Java-induced approach of > building whole project, instead of compiling each source file separately, > as it always used to be with decent languages. Dang. This means my > suggested approach of a compiler switch would indeed get dangerous with > sources, added to project, but maintained by another party -- which sources > might depend on the NPE, and the compiler switch would cause precisely the > problems you mention. Therefore, a compiler switch is actually out of > question. > > Hmmm.... what about a class-level annotation, which would direct the > compiler (and possibly runtime) to behave appropriately? Something like > > @AlwaysSafe class foo { > def bar(a,b,c,d) { // this method never NPEs; if any argument is null, > it simply returns null > a.foo+b+c[d] // and so forth with any other operation > } > } > > That would be, in my personal opinion, completely safe, and would help a > lot? > > Thanks and all the best, > OC > > > --001a11376f92322d8c0540e00a82 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Not throwing an NPE doesn't mean you are safe. It mean= s it doesn't throw errors, but you gave away on semantics. NPEs are oft= en blamed, but they correspond to developer errors. Only the developer know= s if null is relevant or not. I'm totally -1 on this.

2016-11-09 16:33 GMT+01:00 = OC <oc= s@ocs.cz>:
Daniel,

On 9. 11. 2016, at 15:49, Daniel Sun <realbluesun@hotmail.com> wrote:

>=C2=A0 =C2=A0 =C2=A0 =C2=A0IMHO, 'full safe' switch=C2=A0 will = change the semantic of existing '.'

Absolutely.

> which may reduce the maintainability and readability of program

Quite the contrary.

As always, I might be overlooking something of importance, but it seems to = be whomever whose code relies on NPE would never use that switch [*].

On the other hand, for us who *NEVER* want to see *ANY* NPE, and at the mom= ent, are thus forced to an ugly mess of special null metaclasses and ASTTs,= it would help tremendously, making the code considerably more stable and s= afer (e.g., since those ASTTs tend to clash with traits, and who know with = what else in future).

Now, [*] I have (just again!) forgot the terrible Java-induced approach of = building whole project, instead of compiling each source file separately, a= s it always used to be with decent languages. Dang. This means my suggested= approach of a compiler switch would indeed get dangerous with sources, add= ed to project, but maintained by another party -- which sources might depen= d on the NPE, and the compiler switch would cause precisely the problems yo= u mention. Therefore, a compiler switch is actually out of question.

Hmmm.... what about a class-level annotation, which would direct the compil= er (and possibly runtime) to behave appropriately? Something like

@AlwaysSafe class foo {
=C2=A0 def bar(a,b,c,d) { // this method never NPEs; if any argument is nul= l, it simply returns null
=C2=A0 =C2=A0 a.foo+b+c[d] // and so forth with any other operation
=C2=A0 }
}

That would be, in my personal opinion, completely safe, and would help a lo= t?

Thanks and all the best,
OC



--001a11376f92322d8c0540e00a82--