From: "Andrew Carroll" <andrew@carroll-tech.net>
To: <comp.lang.ada@ada-france.org>
Subject: Modes
Date: Tue, 14 Oct 2003 19:36:09 -0600
Date: 2003-10-14T19:36:09-06:00 [thread overview]
Message-ID: <mailman.86.1066194128.25614.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: 20031014202516.4999F4C40B9@lovelace.ada-france.org
> On 10 Oct 2003 11:18:28 -0400, Stephen Leake wrote:
> >"Andrew Carroll" wrote:
> ...
> >Tagged types and full limited types are always passed by reference,
> >because it almost always matters for them.
> ...
I wish I had writen that.
There's another Andrew here. Great name by the way!
I guess I'll start singing my emails different.
I did post some information about using pointers to strings and started the
Modes
topic.
So, to follow up. I revisited all the classes I am working on. Their not
really classes
now. Just records. I made them private and followed Cohen's form. All
that work wasn't
really that informative. It just re-highlighted some things that will take
some time to get used
to with Ada.
For instance if I had a record that contained a count (private record that
is) like
package x is
type x_type is private;
type xptr is access all x_type;
function getcount(this: x_type)return Integer;
private
type x_type is private record
count: Integer := 0;
end record;
end x;
If I want a method to get the count I have to pass in an instance of what I
want to
get the count from. Like:
...
var: xptr;
num: integer;
var := new x_type;
num := getcount(var);
...
I come from C++, Java so that looks more like linear programming to me.
That is, without the dot notation like var.getCount();
Just something to get used to.
I got the "modes" covered now as well. The only thing I noticed after I
changed some
stuff with modes and the records is that it seems to compile faster and run
slower. Didn't
expect that but...what can I say?
So I'm working on the string stuff now. I'm pretty sure you all knew this
but there is a
String_Access defined in Unbounded_String and in Gnat.OS_Lib. What a
coinkidink.
Something else I didn't know "For parameter types unconstrained types are
allowed,
similar to passing int array[] in C. " (Ada-95: A guide for C and C++
programmers
by Simon Johnston) So, if I have a function makeString(input: String)
return String then
I can pass in a string of most any size, then return it. Don't know if this
is really helpfull yet.
Ohhh, by the way. No one posted a list of the "rules of thumb" for Ada.
Here, I'll
repost my post:
>[snip]
>> The rule of thumb is: newer use pointers if there is an alternative.
>> So:
>[snip]
>>Thus another rule: if a pointer, then when possible anonymous:
>> procedure Add (This: access X; Token: Unbounded_String);
>> -- This will be a primitive subprogram of X
>>
>[snip]
>> The Ada way is not to create objects you do not need.
>Okay, so now we're getting to the information I want to know.
>The "rules of thumb" for the "Ada idiom". Anyone got a list of
>"standardized rules of thumb for the Ada idiom"?
Well, take care all.
Andrew C.
parent reply other threads:[~2003-10-15 1:36 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20031014202516.4999F4C40B9@lovelace.ada-france.org>]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox