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 1C7D1200D00 for ; Sun, 27 Aug 2017 04:41:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1B13C164864; Sun, 27 Aug 2017 02:41:24 +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 5EE77164863 for ; Sun, 27 Aug 2017 04:41:23 +0200 (CEST) Received: (qmail 86648 invoked by uid 500); 27 Aug 2017 02:41:22 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 86638 invoked by uid 99); 27 Aug 2017 02:41:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2017 02:41:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id AAE9C1A26D8 for ; Sun, 27 Aug 2017 02:41:21 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.701 X-Spam-Level: X-Spam-Status: No, score=-0.701 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id b3IhaL-c2Mpn for ; Sun, 27 Aug 2017 02:41:20 +0000 (UTC) Received: from mx14lb.world4you.com (mx14lb.world4you.com [81.19.149.124]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id CF0E15FD41 for ; Sun, 27 Aug 2017 02:41:19 +0000 (UTC) Received: from [84.112.214.51] (helo=[192.168.0.18]) by mx14lb.world4you.com with esmtpsa (TLSv1.2:DHE-RSA-AES256-SHA:256) (Exim 4.84_2) (envelope-from ) id 1dlnVf-0006fc-RU; Sun, 27 Aug 2017 04:41:11 +0200 Subject: Re: Possible New Groovy Features... - var Keyword To: users@groovy.apache.org, Jochen Theodorou References: <6f1d6eea-3c73-1e04-61f2-7444c8fd0ce2@arscreat.com> <9ef02e12-bff6-c132-f3ac-ce19a884e217@gmx.org> From: MG Message-ID: <33309536-027c-56be-993b-c53844d58a99@arscreat.com> Date: Sun, 27 Aug 2017 04:41:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <9ef02e12-bff6-c132-f3ac-ce19a884e217@gmx.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-SA-Do-Not-Run: Yes X-AV-Do-Run: Yes X-SA-Exim-Connect-IP: 84.112.214.51 X-SA-Exim-Mail-From: mgbiz@arscreat.com X-SA-Exim-Scanned: No (on mx14lb.world4you.com); SAEximRunCond expanded to false archived-at: Sun, 27 Aug 2017 02:41:24 -0000 Hi Jochen, On 25.08.2017 10:05, Jochen Theodorou wrote: > > > On 23.08.2017 00:52, MG wrote: >> Hi Paul, >> >> On 21.08.2017 04:30, Paul King wrote: >>> >>>     Introduce a "var" (o.s.) keyword that allows deduction of type >>>     through assignment: >>>     var device = new PrinterDevice(...) // device variable will have >>>     type PrinterDevice without the need to explictely state that >>>     Rationale: This is a well known feature of other languages, that >>>     reduces the need to explictely define the type of variables. >>> >> >>> How is this different to the current type inferencing? >> >> The variable/field will have the type of the initally assigned value >> (instead of Object when using def), therefore one cannot accidentially >> assign any other type to it. > > > Didn't see a further comment on this so... If you have the static > compilation mode we use flow typing to determine the type of the > variables. That means: > > def x = "" > > will make x have the type compile time type String, so that x.foo() > will be marked as compilation error. Flow typing means you can do this: > > def x = "" > x = 1 Flow typing is cool, and I would gather much harder to implement than a "var" keyword (btw, I actually just used the name used by C#, even though picking a different name might be a better choice, to avoid confusion with e.g. Javascript). I would however argue that in the majority of cases one will not want to assign an integer value to a "String variable", but will want to keep the type assigned at declaration time, so a var keyword to me is an orthogonal feature to flow typing. > without getting an error. Basically you loose compile time checks on > assignment and gain more flexibility on the usage of the variable. But > since you seem to want to make everything final if possible, that > should not bother you too much. Emphasis on "if possible"... :-) Var would be for the remaining cases where variable reassignment is the most sensible approach. > > The bottom line is: var kind of the default in static compilation mode see under "orthogonal feature" above; var would work in dynamically as well as statically compiled code, so it is also orthogonal in that sense. Cheers, Markus