About String
  Home FAQ Contact Sign in
comp.lang.ada only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.ada Profile…
 Up
About String         


Author: Sébastien Morand
Date: Jun 6, 2008 10:29

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm curious about how you are using string. I think string are quite
useful, but how they are fixed size, I'm often defining them in the
declare part.

I don't know if it's a good practice, but I got code like this:

urio: constant AWS.URL.Object := AWS.Status.URI(request);
host_raw: constant String := AWS.Status.Host(request);
host: constant String := host_raw(host_raw'First ..
First_Index(host_raw, ':'));
www: constant String := SCMAL.Httpd.Servers.GetWWW(host);
Filename: constant String := AWS.URL.Abs_Path(urio);

and so on.

So the main problem is error management. If one function raise
exception, the exception can't be catch except with the following trick:
Show full article (1.30Kb)
25 Comments
Re: About String         


Author: Niklas Holsti
Date: Jun 8, 2008 10:17

Dmitry A. Kazakov wrote:
> On Sun, 08 Jun 2008 14:14:04 +0300, Niklas Holsti wrote:
>
>>Dmitry A. Kazakov wrote:
>>
>>>On Sun, 08 Jun 2008 09:47:30 +0300, Niklas Holsti wrote:
>>> [ About the fact that exceptions raised in a declarative
>>> part cannot be handled by the handler in the following
>>> handled_sequence_of_statements, and it is an error
>>> to try. ]
>>>...
Show full article (5.38Kb)
no comments
Re: About String         


Author: Chris Moore
Date: Jun 8, 2008 11:26

> On Sun, 08 Jun 2008 09:47:30 +0300, Niklas Holsti wrote:
>
>> That said, I admit that I, too, have made this mistake once or
>> twice. But not lately.

Me too. I think it's one of those mistakes that sticks in the mind.

Dmitry A. Kazakov wrote:
> But then, for regularity sake, you would need to add exception handling to
> all declarative parts:
>
> package A is
>
> exception
> (:-))
> end A;
>

It might make tracing elaboration errors easier. :)
Show full article (0.89Kb)
no comments
Re: About String         


Author: Robert A Duff
Date: Jun 8, 2008 11:32

Niklas Holsti writes:
> Chris Moore wrote:
>> I have to say this is an entirely non-intuitive "feature" of the language.
>
> I beg to differ. The program should be read as
>
> declare
> begin end;
>
> The exception handler is within the "begin..end" block, not on the
> "declare".

Sure, that's right, but the syntax doesn't make it clear.
We have ample proof that this syntax is confusing:
More than one person in this thread has admitted to
being confused -- QED. ;-)

I think it was a mistake to attach exception handlers
to declare blocks and procedures and so forth. Instead,
there should be a single statement for handling exceptions,
as in Java and other languages. Something like:
Show full article (1.42Kb)
no comments
Re: About String         


Author: Sebastien Morand
Date: Jun 8, 2008 12:03

> I meant to say
>
> procedure Patati_Patata is
> begin
> begin
> declare
> S : String := A_Function_Raising_Constraint_Error;
> begin
> -- some code
> end;
> exception
> when Constraint_Error =>
> -- deal with the problem ..
> end;
> -- .. and carry on
> end;

And it's what exactly I don't think pretty nice and easy to maintain. Other
solution proposed by previous post is to separate the code with nested function:

procedure Patati_Patata is
Show full article (1.67Kb)
no comments
Re: About String         


Author: Maciej Sobczak
Date: Jun 8, 2008 13:51

On 8 Cze, 20:32, Robert A Duff shell01.TheWorld.com> wrote:
> I think it was a mistake to attach exception handlers
> to declare blocks and procedures and so forth. Instead,
> there should be a single statement for handling exceptions,
> as in Java and other languages. Something like:
>
> handle
> ... statements ...
> exception
> when ... =>
> ...
> end;

You did not state it explicitly, but I presume that you allow mixing
declarations with executable code ("as in Java and other languages")?
After all, with the possibility to initialize the new variable with
arbitrarily complex expression (including function call), this is
already the case and the whole declare-begin-end block is just
reflecting some artificial separation.
Show full article (0.93Kb)
no comments
Re: About String         


Author: Robert A Duff
Date: Jun 8, 2008 14:19

Maciej Sobczak gmail.com> writes:
> You did not state it explicitly, but I presume that you allow mixing
> declarations with executable code ("as in Java and other languages")?

Yes, if I ran the circus, I would allow that. I really find it annoying
that I have to add 3 useless lines of code (declare/begin/end) and an
extra level of indentation, when all I wanted to do was declare
a very-local object.

I also find it annoying that I can't add a statement at the beginning of
a procedure, without moving everything into a local block. E.g. I have:

procedure P (X : Integer) is
Local : constant String := ...;
begin
...

and I want add:

if X = 0 then
raise Blah;
end if;

and I want that to come first.
Show full article (1.22Kb)
no comments
Re: About String         


Author: Dmitry A. Kazakov
Date: Jun 9, 2008 00:14

On Sun, 08 Jun 2008 17:19:11 -0400, Robert A Duff wrote:
> Maciej Sobczak gmail.com> writes:
>
>> After all, with the possibility to initialize the new variable with
>> arbitrarily complex expression (including function call), this is
>> already the case and the whole declare-begin-end block is just
>> reflecting some artificial separation.
>
> I agree. I suppose it comes from Pascal, where declarations and
> executable code are completely separated. It makes no sense in
> Ada, where declarations are just as executable as statements.

I disagree. I think it does make sense because it clearly defines the scope
of the declared variable. Expression (result) /= named object. And
reversely, if you don't need the variable, you are free to put expressions
anywhere outside the declaration part.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
no comments
Re: About String         


Author: Dmitry A. Kazakov
Date: Jun 9, 2008 00:26

On Sun, 08 Jun 2008 20:17:33 +0300, Niklas Holsti wrote:
> I agree that exception contracts would work in this example. Ok,
> exception contracts would reveal some -- perhaps most -- of these
> errors at compile time, but not all.

Nothing can reveal all errors.

But errors in exceptions became painful in Ada. I permanently run into the
stuff, like when an unhandled exception winds up controlled objects,
causing secondary exceptions in Finalizes (which may not happen if the
primary exception were handled). It is very difficult to trace back.

[...]
> I agree that an application could not *recover* from failures in
> package elaboration. But the application could possibly fail more
> gracefully, perhaps even continue operating in a degraded mode.

I think that partitions could be a better candidate for such things.

Maybe it is a "philosophy" again, but to me failed declarations is a
correctness problem, rather than an exceptional state. As such it should
not be handled inside itself.
Show full article (1.07Kb)
no comments
Re: About String         


Author: Georg Bauhaus
Date: Jun 9, 2008 02:43

Dmitry A. Kazakov schrieb:
> On Sun, 08 Jun 2008 17:19:11 -0400, Robert A Duff wrote:
>
>> Maciej Sobczak gmail.com> writes:
>>
>>> After all, with the possibility to initialize the new variable with
>>> arbitrarily complex expression (including function call), this is
>>> already the case and the whole declare-begin-end block is just
>>> reflecting some artificial separation.
>> I agree. I suppose it comes from Pascal, where declarations and
>> executable code are completely separated. It makes no sense in
>> Ada, where declarations are just as executable as statements.
>
> I disagree. I think it does make sense because it clearly defines the scope
> of the declared variable.

Still, a somewhat *new* kind kind of handling exceptions in single
declarations looks interesting?
Show full article (1.28Kb)
no comments
1 2 3