comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Ada 'hello world' for Android; success!
Date: Sun, 30 Oct 2011 07:32:59 -0400
Date: 2011-10-30T07:32:59-04:00	[thread overview]
Message-ID: <82mxciogt0.fsf@stephe-leake.org> (raw)
In-Reply-To: 4eac1ca1$0$7625$9b4e6d93@newsspool1.arcor-online.net

Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:

> On 29.10.11 15:37, Stephen Leake wrote:
>> Anatoly Chernyshev<achernyshev@gmail.com>  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



  parent reply	other threads:[~2011-10-30 11:34 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-27  1:18 Ada 'hello world' for Android; success! Stephen Leake
2011-10-27  7:12 ` Alex R.  Mosteo
2011-10-28 12:51   ` Stephen Leake
2011-10-27 10:50 ` Jeffrey Creem
2011-10-28 13:01   ` Stephen Leake
2011-10-27 10:58 ` Brian Drummond
2011-10-28  1:37 ` Shark8
2011-10-28 12:22 ` Anatoly Chernyshev
2011-10-29 13:37   ` Stephen Leake
2011-10-29 14:46     ` Anatoly Chernyshev
2011-10-29 20:47       ` Brad Moore
2011-10-29 21:59         ` Anatoly Chernyshev
2011-10-30  3:51           ` Brad Moore
2011-10-30  7:20             ` Anatoly Chernyshev
2011-10-30 10:56       ` Stephen Leake
2011-10-30 17:32         ` Brad Moore
2011-10-29 15:32     ` Georg Bauhaus
2011-10-29 16:09       ` Simon Wright
2011-10-29 17:32         ` tmoran
2011-10-30 11:38           ` Stephen Leake
2011-10-29 20:51         ` Brad Moore
2011-10-30 11:32       ` Stephen Leake [this message]
2011-10-31 22:34         ` Randy Brukardt
2011-11-01  8:41           ` Stephen Leake
2011-11-01  9:30         ` Georg Bauhaus
2011-11-02 15:55           ` Stephen Leake
2011-11-02 17:37             ` Robert A Duff
2011-11-08  3:56               ` Randy Brukardt
2011-11-03  0:37             ` Georg Bauhaus
2011-11-03 11:36               ` Stephen Leake
2011-11-03 15:24                 ` Robert A Duff
2011-11-03 18:43                   ` Pascal Obry
2011-11-03 22:14                 ` Georg Bauhaus
2011-11-04  8:48                   ` Dmitry A. Kazakov
2011-11-04 12:18                   ` Stephen Leake
2011-11-04 15:03                     ` Georg Bauhaus
2011-11-05 16:56                       ` Stephen Leake
2011-11-01  9:52         ` Dmitry A. Kazakov
2011-11-02 15:59           ` Stephen Leake
2011-11-02 16:27             ` Dmitry A. Kazakov
2011-11-02 17:38               ` Simon Wright
2011-11-10 17:25 ` Stephen Leake
2011-11-27 15:18 ` mockturtle
2011-11-28 22:35   ` Ada 'hello world' for Android; success! (but music player failure) Stephen Leake
2011-11-29 11:23     ` Georg Bauhaus
2011-11-30  3:33       ` Stephen Leake
2011-11-30 18:57         ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox