From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.231.68 with SMTP id te4mr8073204pac.29.1405351543258; Mon, 14 Jul 2014 08:25:43 -0700 (PDT) X-Received: by 10.50.222.44 with SMTP id qj12mr499765igc.13.1405351543154; Mon, 14 Jul 2014 08:25:43 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!h18no1435746igc.0!news-out.google.com!bp9ni28igb.0!nntp.google.com!h18no1435737igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 14 Jul 2014 08:25:42 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: why Ada type casting is different from other languages? newType(value) vs. (newType)value From: Adam Beneschan Injection-Date: Mon, 14 Jul 2014 15:25:43 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:20930 Date: 2014-07-14T08:25:42-07:00 List-Id: On Saturday, July 12, 2014 6:55:24 PM UTC-7, Nasser M. Abbasi wrote: > I am just wondering what is the rational of Ada choosing to use >=20 > type(value) >=20 > vs > > (type)value > > to do typecasting. does not type(value) appear as a function call? >=20 > as in=20 >=20 > i :=3D float(9); >=20 > vs. >=20 > i :=3D (float) 9; >=20 > Just wondering on this choice and its advantage over the more > common syntax. The only reason the latter is "more common" is because a lot of languages h= ave based their syntax on C's, and that's the syntax Ritchie decided to use= . I don't know of any language that isn't based on C syntax that uses this= syntax for a cast. As for the languages that do use that syntax, I don't = think the designers made a conscious choice to use the (type)expression syn= tax--i.e. they didn't look at the possibilities and decide that (type)expre= ssion was better. Rather, they just decided at the beginning to use C synt= ax, copied most of the syntax, and then perhaps made a few tweaks here and = there. Ironically, C++ now allows the type(expression) syntax for type conversion.= Technically, it's not a type conversion, but rather a one-argument constr= uctor for an object of type "type" with "expression" as the argument. But = the language definition has defined implicit one-argument constructors for = primitive types, so that the effect is the same. Sometimes. Actually, I t= hink the semantics are subtly different, and there are times when (type)exp= ression is legal where type(expression) is not, and sometimes you need to u= se dynamic_cast(expression) or static_cast(expression). In fac= t, I think the (type)expression syntax isn't supposed to be used any more, = and static_cast(expression) is preferred, at least according to some = authorities. As someone I know likes to say, "If you're not confused, you'= re not paying attention."=20 I don't like the (type)expression syntax because I can never remember what = the precedence is. This is especially a problem for (type)object.method(ar= gs), because I have to look up whether the type conversion applies to just = the object or to the result of the function call. In general, questions such as this are meaningless, because for the most pa= rt they come down someone's style preference. -- Adam