comp.lang.ada
 help / color / mirror / Atom feed
From: randhol@bacchus.pvv.ntnu.no (Preben Randhol)
Subject: Re: Thick vs. Thin bindings
Date: Wed, 1 Dec 2004 17:14:20 +0000 (UTC)
Date: 2004-12-01T17:14:20+00:00	[thread overview]
Message-ID: <slrncqruvc.1d82.randhol@bacchus.pvv.ntnu.no> (raw)
In-Reply-To: 41a746a0@x-privat.org

In article <41a746a0@x-privat.org>, Jeff Houck wrote:
>As I continue to evaluate Ada in the role of a game dev language, I've 
>run across references to "thick" and "thin" bindings and I'm a bit 
>confused.
>My initial design goals are to keep the number of external dependancies 
>to a minimum with most of the support code written in Ada. I would like 
>the code interfaces to be as simple as possible to implement for a 
>designer. I believe this would necessitate a "thick" binding. Is that 
>correct? Would anyone like to elaborate on the pros and cons of these 
>two binding methodologies? Further reading material? Tutorials? Thx!

One way of thinking is:

   Thin binding (if it is a C library) then you use only Integer type
   for more or less everything. Or you use C char arrays in stead of Ada
   strings etc...

   Thick binding you add more layer to the binding so that you can use
   the powers of Ada when you use your library. I mean you don't need to
   convert from a Integer type to your type for height/speed/distance
   for example...

Thin binding is faster to make and then you can make it more thick if
you like, but this involves API changes...

Even thicker binding is if you can do standard operations in one
procedure call in stead of 10 function/procedure calls.

I think I would have done a one-to-one binding to a C library as long as
this makes sense and used Ada types so you do any necessary conversion
in the binding.

Here is an example for GtkAda:

   function Get_Resizable
     (Window : access Gtk_Window_Record) return Boolean
   is
      function Internal (Window : System.Address) return Gboolean;
      pragma Import (C, Internal, "gtk_window_get_resizable");

   begin
      return Internal (Get_Object (Window)) /= 0;
   end Get_Resizable;

The C library returns a type Gboolean (which in fact is basically an
int) as you can see, but the binding returns an Ada boolean. This means
that the user of the library can use Ada's Boolean types without having
to convert the Gboolean/integer to boolean after every call to the
function.

This is perhaps a very thin thick binding, but it should give you an
idea. Another thing to remember is that if the original library uses a
function it sometimes is better (ex. when returning more than one value)
to use a procedure in Ada due to that you cannot have in out variables
in functions.

Preben



      parent reply	other threads:[~2004-12-01 17:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-26 15:07 Thick vs. Thin bindings Jeff Houck
2004-11-26 16:55 ` Marius Amado Alves
2004-11-27 18:13   ` Jeff Houck
2004-11-27 22:16     ` Marius Amado Alves
2004-11-26 19:32 ` David Botton
2004-11-27  7:25 ` Martin Krischik
2004-11-29  7:50 ` tmoran
2004-12-01 17:14 ` Preben Randhol [this message]
replies disabled

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