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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4cb1f8d1c17d39a8 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.146.17 with SMTP id f17mr1219213bkv.5.1319974476710; Sun, 30 Oct 2011 04:34:36 -0700 (PDT) Path: l23ni24145bkv.0!nntp.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Ada 'hello world' for Android; success! References: <8239efcjuw.fsf@stephe-leake.org> <98ca5430-aa52-4e39-b789-70d0dd6adb46@d33g2000prb.googlegroups.com> <824nyrq5p6.fsf@stephe-leake.org> <4eac1ca1$0$7625$9b4e6d93@newsspool1.arcor-online.net> Date: Sun, 30 Oct 2011 07:32:59 -0400 Message-ID: <82mxciogt0.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (windows-nt) Cancel-Lock: sha1:GzmT5yhvjG3QRNovJ/FcsvaQ47g= MIME-Version: 1.0 X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 005f34ead35e5e26b0fa624966 Xref: news1.google.com comp.lang.ada:18762 Content-Type: text/plain; charset=us-ascii Date: 2011-10-30T07:32:59-04:00 List-Id: Georg Bauhaus writes: > On 29.10.11 15:37, Stephen Leake wrote: >> Anatoly Chernyshev writes: >> >>> Looks like a Pyrrhic victory to me. All elegance of Ada is suddenly >>> dissipated. >> >> I gather you feel that Android is inelegant in some way; can you be more >> specific? > > The example is a little non-Ada, IMHO. In one sense, any trivial program is non-Ada, since Ada is meant for complexity :). > I don't know Anatoly's reasons, but to me the example has an air of > "Fortran in any language", except that one has to replace Fortran with > pointers or Java-with-covers-removed, viz. explicit access A.B.C.Typ > all over the place. Part of that is style. In examples like this, I tend to not use 'use', to make it very clear what is going on. But most of the "non-Ada" feel comes from the fact that it is a GUI program. Interestingly, I could not find a true GUI hello world example for Gtk; 'hello world' in the Gtk tutorial uses Ada.Text_IO.Put_Line! Here's Qt: with Qt_Ada.Application; with Qt4.Push_Buttons.Constructors; with Qt4.Strings; procedure Main is begin Qt_Ada.Application.Initialize; declare Hello : constant not null access Qt4.Push_Buttons.Q_Push_Button'Class := Qt4.Push_Buttons.Constructors.Create (Qt4.Strings.From_Utf_16 ("Hello world!")); begin Hello.Resize (100, 30); Hello.Show; Qt_Ada.Application.Execute; end; end Main; The string 'hello world' is actually present in this source; it is not in my example. As I said, that's because I plan to use the 'resource' features of Android; that's how internationalization is implemented. I'm not clear how Qt does internationalization. > FWIW, the programs I have once written using SofCheck's version > of Ada on JVMs looked and felt more like Ada and a less > like explicit anonymous pointer to A.B.C.Typ everywhere. > Note that the thorny appearance of the HelloWorld example > isn't present in Java, which allows O-O without forcing > the programmers to write pointers, pointers, pointers. Here's the Java source for 'hello world': package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } And here is the Ada version (just the package body): package body Hello is overriding procedure OnCreate (This : access Typ; savedInstanceState : access Standard.Android.Os.Bundle.Typ'class) is type Super_Ref is access all Android.App.Activity.Typ; begin Android.App.Activity.Oncreate (Super_Ref (This), savedInstanceState); Android.App.Activity.SetContentView (Android.App.Activity.Ref (This), 16#7f030000#); end OnCreate; end Hello; By defintion, every non-scalar type in Java _is_ a pointer; Bundle and 'this' are pointers. The fact that the code doesn't say 'access' just hides that fact. Java also hides the existence of 'this'. Making those features explicit is definitely the Ada way. So I don't think the Ada version is "non-Ada" because it uses pointers! We could try to define "Typ" to be an access type, so the words "access" would be replaced by "in" above. That issue has been discussed elsewhere (for my take on it, see http://www.stephe-leake.org/ada/access_vs_object.html). In brief, _any_ framework that uses dispatching on class-wide objects needs reference semantics. In Ada, that is indicated by the explicit word 'access'. In Java, it is implicit. I prefer explicit. > BTW, is it possible in the Android model to have an > equivalent of Ada's > > procedure Op (This : access constant Typ); > > where a programmer can state the intent of read-only > access? Certainly, as long as all uses of This treat it that way. However, since Java lacks this feature, none of the imported Android APIs will have the 'constant' keyword. It would be possible (but error-prone and tedious) to add 'constant' in appropriate places in the generated API; that would make the system better. It might even be worth adding a feature to jvm2ada to automate that, given a hand-generated list of subprogram args that should be labeled 'constant'. The hard part would be figuring out if a particular argument is in fact treated as a constant. > Is the traditional O-O model of Ada impossible to support > in a compiler for Android devices or is it just that no one > is paying for such a compiler? I don't know what you mean. The Ada I'm using is fully Ada 2005 compliant. Any 'non-OO'ness you see is because of the Android design, not because of the compiler. > So that the best we can do is juggle the pointers that the other > languages can hide? Yes. And as I said above, that's a Good Thing. -- -- Stephe