comp.lang.ada
 help / color / mirror / Atom feed
* A new notion: stronglly-typed-by-user language
@ 2010-04-15  8:59 J-P. Rosen
  2010-04-15  9:19 ` Martin Krischik
                   ` (5 more replies)
  0 siblings, 6 replies; 31+ messages in thread
From: J-P. Rosen @ 2010-04-15  8:59 UTC (permalink / raw)


While preparing the upcomming "Using Object Oriented Technologies in
Secure Systems" tutorial for Ada-Europe (plug, plug...), I came across
this beautiful statement (OOTiA, B.1.1.6):

"C++ is a strongly typed language, if conversions between logically
unrelated types are avoided".

Ain't that cute?
-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
@ 2010-04-15  9:19 ` Martin Krischik
  2010-04-16  0:22   ` BrianG
  2010-04-15  9:59 ` Dmitry A. Kazakov
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 31+ messages in thread
From: Martin Krischik @ 2010-04-15  9:19 UTC (permalink / raw)


Am 15.04.2010, 10:59 Uhr, schrieb J-P. Rosen <rosen@adalog.fr>:

> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".

Driving without seatbelts is perfectly save if accidents are avoided.

Martin
-- 
Martin Krischik



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
  2010-04-15  9:19 ` Martin Krischik
@ 2010-04-15  9:59 ` Dmitry A. Kazakov
  2010-04-15 10:49 ` Georg Bauhaus
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-15  9:59 UTC (permalink / raw)


On Thu, 15 Apr 2010 10:59:37 +0200, J-P. Rosen wrote:

> While preparing the upcomming "Using Object Oriented Technologies in
> Secure Systems" tutorial for Ada-Europe (plug, plug...), I came across
> this beautiful statement (OOTiA, B.1.1.6):
> 
> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".
> 
> Ain't that cute?

Well, strong typing is unrelated to type conversions, so the sentence above
is nonsense. Actually, *logically* (meaning semantically) unrelated types
can be mixed without any conversions:

   int ArrayIndex;
   int EmployeeID;

   Employee_ID = Arraj_Index:

The question is whether a strongly typed language is designed in order to
support and encourage mapping logically unrelated entities onto physically
unrelated types or not. Ada more or less is, C++ more or less is not.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
  2010-04-15  9:19 ` Martin Krischik
  2010-04-15  9:59 ` Dmitry A. Kazakov
@ 2010-04-15 10:49 ` Georg Bauhaus
  2010-04-15 21:31 ` Maciej Sobczak
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Georg Bauhaus @ 2010-04-15 10:49 UTC (permalink / raw)


J-P. Rosen schrieb:
> While preparing the upcomming "Using Object Oriented Technologies in
> Secure Systems" tutorial for Ada-Europe (plug, plug...), I came across
> this beautiful statement (OOTiA, B.1.1.6):
> 
> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".
> 
> Ain't that cute?


The argument is brilliant, I think.
(At least outside its specific context, which is the weak types
of C still underlying C++, where weak refers to the definitions
of the cited document.)  I'm serious.

"if you avoid doing stupid things" brings the sane programmer
into focus who wouldn't actually convert between logically
unrelated types, anyway. You want sane programmers.

Add this argument to your marketing speech repertoir.

If a type system is needed to avoid stupid conversions,
then what does this tell us about Ada programmers, huh?



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
                   ` (2 preceding siblings ...)
  2010-04-15 10:49 ` Georg Bauhaus
@ 2010-04-15 21:31 ` Maciej Sobczak
  2010-04-16  7:28   ` J-P. Rosen
                     ` (2 more replies)
  2010-04-18  0:27 ` Gene
  2010-04-18 20:38 ` Gautier write-only
  5 siblings, 3 replies; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-15 21:31 UTC (permalink / raw)


On 15 Kwi, 10:59, "J-P. Rosen" <ro...@adalog.fr> wrote:

> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".
>
> Ain't that cute?

http://en.wikipedia.org/wiki/Strong_typing

"these terms have been given such a wide variety of meanings over the
short history of computing that it is often difficult to know, out of
context, what an individual author means when using them."

Indeed, if I cherry-pick bits of this page on Wikipedia, C++ seems to
be strongly typed. If I cherry-pick some other bits, Ada seems to be
weakly typed.

The statement that you cited is therefore not very convincing.

In particular, what are "conversions between logically unrelated
types"?
Is Integer'Image such a conversion? What about arbitrary casts between
numeric types? What about unchecked casts?

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  9:19 ` Martin Krischik
@ 2010-04-16  0:22   ` BrianG
  2010-04-16  6:26     ` Martin Krischik
  0 siblings, 1 reply; 31+ messages in thread
From: BrianG @ 2010-04-16  0:22 UTC (permalink / raw)


Martin Krischik wrote:
> Am 15.04.2010, 10:59 Uhr, schrieb J-P. Rosen <rosen@adalog.fr>:
> 
>> "C++ is a strongly typed language, if conversions between logically
>> unrelated types are avoided".
> 
> Driving without seatbelts is perfectly save if accidents are avoided.
> 
> Martin


"English is an unambiguous language, if ambiguous statements are avoided."

"<The programming language of your choice> creates bug-free software,
if bugs are avoided."

--BrianG
	--The cosmic is largely comic



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16  0:22   ` BrianG
@ 2010-04-16  6:26     ` Martin Krischik
  0 siblings, 0 replies; 31+ messages in thread
From: Martin Krischik @ 2010-04-16  6:26 UTC (permalink / raw)


Am 16.04.2010, 02:22 Uhr, schrieb BrianG <briang000@gmail.com>:

> "<The programming language of your choice> creates bug-free software,
> if bugs are avoided."

The C / C++ community actually uses this as a  serious argument in favour  
of there language.

Martin
-- 
Martin Krischik



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15 21:31 ` Maciej Sobczak
@ 2010-04-16  7:28   ` J-P. Rosen
  2010-04-16  7:48     ` Dmitry A. Kazakov
  2010-04-16 15:32     ` Maciej Sobczak
  2010-04-16  7:29   ` Dmitry A. Kazakov
  2010-04-16 10:34   ` xavier grave
  2 siblings, 2 replies; 31+ messages in thread
From: J-P. Rosen @ 2010-04-16  7:28 UTC (permalink / raw)


Maciej Sobczak a �crit :
> On 15 Kwi, 10:59, "J-P. Rosen" <ro...@adalog.fr> wrote:
> 
>> "C++ is a strongly typed language, if conversions between logically
>> unrelated types are avoided".
>>
>> Ain't that cute?
> 
> http://en.wikipedia.org/wiki/Strong_typing
> 
> "these terms have been given such a wide variety of meanings over the
> short history of computing that it is often difficult to know, out of
> context, what an individual author means when using them."
Of course, there is obviously no clear-cut

[...]
> The statement that you cited is therefore not very convincing.
> 
> In particular, what are "conversions between logically unrelated
> types"?
> Is Integer'Image such a conversion? What about arbitrary casts between
> numeric types? What about unchecked casts?
I was expecting someone to come up with Unchecked_Conversion, so you win :-)

Do not confuse "weakly type" and "strongly type with a mean to disable
it in a controlled way when absolutely necessary". Having no safety
belts in a car is not the same thing as having belts and not putting
them (as far as the car design is concerned).

What I find amusing (or characteristic of the C/C++ spirit) is the idea
that "if you are careful, it is good enough".

I generally conclude my presentations of Ada with two quotes. The first
one is from K&R, in one of the first books about C:

"C has been designed under the hypothesis that the programmes is
reasonable and knows what he's doing"

The other one from ARM's introduction:
"Concern for the human programmer was also stressed during the design"

C is not for humans...
-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15 21:31 ` Maciej Sobczak
  2010-04-16  7:28   ` J-P. Rosen
@ 2010-04-16  7:29   ` Dmitry A. Kazakov
  2010-04-16 10:34   ` xavier grave
  2 siblings, 0 replies; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-16  7:29 UTC (permalink / raw)


On Thu, 15 Apr 2010 14:31:48 -0700 (PDT), Maciej Sobczak wrote:

> In particular, what are "conversions between logically unrelated
> types"?
> Is Integer'Image such a conversion?

Yes, if you include String into the algebra of the Integer type, no
otherwise. No different to:

   function ">" (Left, Right : Integer) return Boolean;

What does Boolean here? Is it a type logically unrelated to Integer?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16  7:28   ` J-P. Rosen
@ 2010-04-16  7:48     ` Dmitry A. Kazakov
  2010-04-16 15:32     ` Maciej Sobczak
  1 sibling, 0 replies; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-16  7:48 UTC (permalink / raw)


On Fri, 16 Apr 2010 09:28:06 +0200, J-P. Rosen wrote:

> Do not confuse "weakly type" and "strongly type with a mean to disable
> it in a controlled way when absolutely necessary". Having no safety
> belts in a car is not the same thing as having belts and not putting
> them (as far as the car design is concerned).

I like this analogy. C++ has safety belts coiled under the spare tyre in
the luggage boot.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15 21:31 ` Maciej Sobczak
  2010-04-16  7:28   ` J-P. Rosen
  2010-04-16  7:29   ` Dmitry A. Kazakov
@ 2010-04-16 10:34   ` xavier grave
  2010-04-16 19:26     ` Gautier write-only
  2 siblings, 1 reply; 31+ messages in thread
From: xavier grave @ 2010-04-16 10:34 UTC (permalink / raw)
  To: Maciej Sobczak

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

Maciej Sobczak a �crit :
> On 15 Kwi, 10:59, "J-P. Rosen" <ro...@adalog.fr> wrote:
> 
>> "C++ is a strongly typed language, if conversions between logically
>> unrelated types are avoided".
>>
>> Ain't that cute?
> 
> http://en.wikipedia.org/wiki/Strong_typing

May be I'm wrong, but I didn't find any reference of Ada in this page.
I bet we can't count Ada as a Pascal family language in this case ? :)

- --
xavier


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkvIPUEACgkQVIZi0A5BZF4GqACbBPUTJpzpFnaFmNtcl00j4jqv
Gi8AoLs58B4TNahB7PbHBUSn3NdAIA1C
=LKqi
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16  7:28   ` J-P. Rosen
  2010-04-16  7:48     ` Dmitry A. Kazakov
@ 2010-04-16 15:32     ` Maciej Sobczak
  2010-04-16 16:52       ` Georg Bauhaus
  2010-04-16 20:20       ` J-P. Rosen
  1 sibling, 2 replies; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-16 15:32 UTC (permalink / raw)


On 16 Kwi, 09:28, "J-P. Rosen" <ro...@adalog.fr> wrote:

> Do not confuse "weakly type" and "strongly type with a mean to disable
> it in a controlled way when absolutely necessary". Having no safety
> belts in a car is not the same thing as having belts and not putting
> them (as far as the car design is concerned).
>
> What I find amusing (or characteristic of the C/C++ spirit) is the idea
> that "if you are careful, it is good enough".

So which C++ language features exactly make it not strongly typed?

I agree that the C++ programmer has to be careful, but here I'm
interested in the strong type safety aspect.
Which constructs violate the strong type safety in C++?

(Of course, I expect that such or analogous constructs do not exist in
Ada.)

> I generally conclude my presentations of Ada with two quotes. The first
> one is from K&R, in one of the first books about C:

Let's focus on recent C++ standard instead of early versions of C.

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 15:32     ` Maciej Sobczak
@ 2010-04-16 16:52       ` Georg Bauhaus
  2010-04-16 17:24         ` Dmitry A. Kazakov
  2010-04-16 20:20       ` J-P. Rosen
  1 sibling, 1 reply; 31+ messages in thread
From: Georg Bauhaus @ 2010-04-16 16:52 UTC (permalink / raw)


Maciej Sobczak schrieb:

>> I generally conclude my presentations of Ada with two quotes. The first
>> one is from K&R, in one of the first books about C:
> 
> Let's focus on recent C++ standard instead of early versions of C.

The necessity to use C types is what the cited article defines as
"weak", I think. There is a glossary.
IIUC, a C(++) int and another C(++) int might be logically unrelated,
yet they tend to be of the same type.  A Current and a Count might
be logically unrelated, and they tend to be of different types in Ada,
though both are integer types.

If backwards compatibility could be made an option instead
of a drag,  int<...> made a template, how much of the trouble
might this remove, how well can it be integrated with the STL, ...



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 16:52       ` Georg Bauhaus
@ 2010-04-16 17:24         ` Dmitry A. Kazakov
  2010-04-16 20:53           ` Pascal Obry
  0 siblings, 1 reply; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-16 17:24 UTC (permalink / raw)


On Fri, 16 Apr 2010 18:52:24 +0200, Georg Bauhaus wrote:

> A Current and a Count might
> be logically unrelated, and they tend to be of different types in Ada,
> though both are integer types.

BTW, the Ada's OO kernel has this same design flaw. You can clone all
types, but tagged:

   type Count is new Current; -- This is OK only if Current is not tagged!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 10:34   ` xavier grave
@ 2010-04-16 19:26     ` Gautier write-only
  0 siblings, 0 replies; 31+ messages in thread
From: Gautier write-only @ 2010-04-16 19:26 UTC (permalink / raw)


On Apr 16, 12:34 pm, xavier grave <xavier.gr...@ipno.in2p3.fr> wrote:

> >http://en.wikipedia.org/wiki/Strong_typing
>
> May be I'm wrong, but I didn't find any reference of Ada in this page.

That's easily fixed: click on "edit this page" and you can add a
reference :-).
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 15:32     ` Maciej Sobczak
  2010-04-16 16:52       ` Georg Bauhaus
@ 2010-04-16 20:20       ` J-P. Rosen
  2010-04-16 20:50         ` Maciej Sobczak
  1 sibling, 1 reply; 31+ messages in thread
From: J-P. Rosen @ 2010-04-16 20:20 UTC (permalink / raw)


Maciej Sobczak a �crit :
> So which C++ language features exactly make it not strongly typed?
> 
1) Lack of user-defined elementary types
2) Type promotion

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 20:20       ` J-P. Rosen
@ 2010-04-16 20:50         ` Maciej Sobczak
  2010-04-17  5:25           ` J-P. Rosen
  0 siblings, 1 reply; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-16 20:50 UTC (permalink / raw)


On 16 Kwi, 22:20, "J-P. Rosen" <ro...@adalog.fr> wrote:
> Maciej Sobczak a écrit :> So which C++ language features exactly make it not strongly typed?
>
> 1) Lack of user-defined elementary types

This is addressed by:

http://www.msobczak.com/prog/typegen/

Alternative solutions involve templates or preprocessor or even hand-
written classes with appropriate operations - all of them are purely C+
+-based.

> 2) Type promotion

I don't see how type promotion violates the strong type safety.
In particular, type promotions are used in read-only operations (that
is, type is promoted when the value is read, not when it is written),
so they do not modify the state of the object that is subject to
promotion - as such, they do not subvert the type system in any way.

What about promoting integer values to Type'Base in arithmetic
operations?
Isn't it a form of type promotion?

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 17:24         ` Dmitry A. Kazakov
@ 2010-04-16 20:53           ` Pascal Obry
  2010-04-16 21:51             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 31+ messages in thread
From: Pascal Obry @ 2010-04-16 20:53 UTC (permalink / raw)


Le 16/04/2010 19:24, Dmitry A. Kazakov a �crit :
> BTW, the Ada's OO kernel has this same design flaw. You can clone all
> types, but tagged:
> 
>    type Count is new Current; -- This is OK only if Current is not tagged!

type Count is new Current with null record;

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|    http://www.obry.net  -  http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 20:53           ` Pascal Obry
@ 2010-04-16 21:51             ` Dmitry A. Kazakov
  0 siblings, 0 replies; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-16 21:51 UTC (permalink / raw)


On Fri, 16 Apr 2010 22:53:04 +0200, Pascal Obry wrote:

> Le 16/04/2010 19:24, Dmitry A. Kazakov a �crit :
>> BTW, the Ada's OO kernel has this same design flaw. You can clone all
>> types, but tagged:
>> 
>>    type Count is new Current; -- This is OK only if Current is not tagged!
> 
> type Count is new Current with null record;

That would not create an unrelated type, the class is same.

   function "+" (Left : Current; Right : Current'Class) return Current;

   X : Current;
   Y : Count;
begin
   X := X + Y; -- No type error

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-16 20:50         ` Maciej Sobczak
@ 2010-04-17  5:25           ` J-P. Rosen
  2010-04-17  7:00             ` Dmitry A. Kazakov
  2010-04-17 14:33             ` Maciej Sobczak
  0 siblings, 2 replies; 31+ messages in thread
From: J-P. Rosen @ 2010-04-17  5:25 UTC (permalink / raw)


Maciej Sobczak a �crit :
> On 16 Kwi, 22:20, "J-P. Rosen" <ro...@adalog.fr> wrote:
>> Maciej Sobczak a �crit :> So which C++ language features exactly make it not strongly typed?
>>
>> 1) Lack of user-defined elementary types
> 
> This is addressed by:
> 
> http://www.msobczak.com/prog/typegen/
This shows that an educated Ada programmer, well aware of the issues of
strong typing, can mimmic the same behaviour in C++. But how many C++
programmers use that?

>> 2) Type promotion
> 
> I don't see how type promotion violates the strong type safety.
Type promotion is based on the underlying representation, not on
abstract types. And it is a form of automatic type case - which is
always a bad idea IMHO.

Note that T'Base is the same type as T, so there is no issue here.
-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17  5:25           ` J-P. Rosen
@ 2010-04-17  7:00             ` Dmitry A. Kazakov
  2010-04-17 11:40               ` J-P. Rosen
  2010-04-17 14:33             ` Maciej Sobczak
  1 sibling, 1 reply; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-17  7:00 UTC (permalink / raw)


On Sat, 17 Apr 2010 07:25:25 +0200, J-P. Rosen wrote:

> Note that T'Base is the same type as T, so there is no issue here.

But it is not all same. The behavior of T'Base may differ, so it might be
unsafe to use one as an equivalent of another in certain contexts
(substitutability violation).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17  7:00             ` Dmitry A. Kazakov
@ 2010-04-17 11:40               ` J-P. Rosen
  2010-04-17 14:09                 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 31+ messages in thread
From: J-P. Rosen @ 2010-04-17 11:40 UTC (permalink / raw)


Dmitry A. Kazakov a �crit :
> On Sat, 17 Apr 2010 07:25:25 +0200, J-P. Rosen wrote:
> 
>> Note that T'Base is the same type as T, so there is no issue here.
> 
> But it is not all same. The behavior of T'Base may differ, so it might be
> unsafe to use one as an equivalent of another in certain contexts
> (substitutability violation).
> 
T is a subtype (the first named subtype) of T'Base. This is not
different from any issue of type vs. subtype.

My point is that two objects are of the same type if they represent the
same abstraction. This is true of T and T'Base. Almost any language
behaves as if there were only one integer type (represented on various
number of bits depending on the constraints). This is somehow the
mathematical view. But since we are modelling real world object, it is
better to adopt a physicist point of view: objects have dimensions, and
it makes no sense to add apples and oranges. That's what I would call
strong typing.

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17 11:40               ` J-P. Rosen
@ 2010-04-17 14:09                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 31+ messages in thread
From: Dmitry A. Kazakov @ 2010-04-17 14:09 UTC (permalink / raw)


On Sat, 17 Apr 2010 13:40:23 +0200, J-P. Rosen wrote:

> My point is that two objects are of the same type if they represent the
> same abstraction. This is true of T and T'Base.

No, this is certainly untrue. T'Base rather represents a quite arbitrary
machine-dependent type chosen by the compiler. It may or may not fir the
abstraction of T. Consider:

   type Angle is digits 5 range 0.0..360.0;
   X : Angle'Base := -10.0;

Putting or lifting a constraint can break abstraction.

> Almost any language
> behaves as if there were only one integer type (represented on various
> number of bits depending on the constraints). This is somehow the
> mathematical view. But since we are modelling real world object, it is
> better to adopt a physicist point of view: objects have dimensions, and
> it makes no sense to add apples and oranges. That's what I would call
> strong typing.

I would call it mere typing. Strength of typing to me rather indicates how
often you get a chance to add apples and orange. It is more frequent in C++
than in Ada.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17  5:25           ` J-P. Rosen
  2010-04-17  7:00             ` Dmitry A. Kazakov
@ 2010-04-17 14:33             ` Maciej Sobczak
  2010-04-17 18:57               ` J-P. Rosen
  1 sibling, 1 reply; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-17 14:33 UTC (permalink / raw)


On 17 Kwi, 07:25, "J-P. Rosen" <ro...@adalog.fr> wrote:

> >http://www.msobczak.com/prog/typegen/
>
> This shows that an educated Ada programmer, well aware of the issues of
> strong typing, can mimmic the same behaviour in C++. But how many C++
> programmers use that?

Not many, but that does not matter in this discussion - we are
discussing the language, not programmers.

> > I don't see how type promotion violates the strong type safety.
>
> Type promotion is based on the underlying representation, not on
> abstract types.

No. Type promotions in C++ are defined in terms of values, not in
terms bit patterns. There is nothing that forces char and int to have
similar underlying representation, yet promotion from char to int is
well-defined.

> And it is a form of automatic type case - which is
> always a bad idea IMHO.

There are many bad ideas in C++. I don't see how this one affects
strong type safety.

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17 14:33             ` Maciej Sobczak
@ 2010-04-17 18:57               ` J-P. Rosen
  2010-04-17 22:02                 ` Maciej Sobczak
  0 siblings, 1 reply; 31+ messages in thread
From: J-P. Rosen @ 2010-04-17 18:57 UTC (permalink / raw)


Maciej Sobczak a �crit :
> On 17 Kwi, 07:25, "J-P. Rosen" <ro...@adalog.fr> wrote:
> 
>>> http://www.msobczak.com/prog/typegen/
>> This shows that an educated Ada programmer, well aware of the issues of
>> strong typing, can mimmic the same behaviour in C++. But how many C++
>> programmers use that?
> 
> Not many, but that does not matter in this discussion - we are
> discussing the language, not programmers.
Precisely. You showed you can add type safety to the language - which
means that there is not built-in type safety.

>>> I don't see how type promotion violates the strong type safety.
>> Type promotion is based on the underlying representation, not on
>> abstract types.
> 
> No. Type promotions in C++ are defined in terms of values, not in
> terms bit patterns. There is nothing that forces char and int to have
> similar underlying representation, yet promotion from char to int is
> well-defined.
Here is what I had in mind. If you have:
void p (short S);
void p (long L);
and you call p (I) where I is an int, it will resolve to the first one
if short and int are the same, and to the second one if long and int are
the same. This is logical in terms of machine types, but the idea that
overloading resolution (and the associated promotion) depends on the
implementation will make any Ada lawyer faint ;-)

> 
>> And it is a form of automatic type case - which is
                                      cast - typo!
>> always a bad idea IMHO.
> 
> There are many bad ideas in C++. I don't see how this one affects
> strong type safety.
See above
-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17 18:57               ` J-P. Rosen
@ 2010-04-17 22:02                 ` Maciej Sobczak
  2010-04-18  8:04                   ` J-P. Rosen
  0 siblings, 1 reply; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-17 22:02 UTC (permalink / raw)


On 17 Kwi, 20:57, "J-P. Rosen" <ro...@adalog.fr> wrote:

> Precisely. You showed you can add type safety to the language - which
> means that there is not built-in type safety.

No. I have shown that the language is capable of supporting user-
defined integer types. There is nothing *added* to the language -
everything is plain vanilla standard C++.

That is, there was nothing missing in there.

> Here is what I had in mind. If you have:
> void p (short S);
> void p (long L);
> and you call p (I) where I is an int, it will resolve to the first one
> if short and int are the same, and to the second one if long and int are
> the same. This is logical

No. Not only it is not logical - it will not even compile.

First of all, type int is never subject to promotion. "Lower" types
can be promoted to int if necessary and this is promotion. Apart from
this, integer types can be converted between each other.
Promotion has higher rank than conversion in overload resolution and
this is basically the only place where the distinction between them is
relevant.
That is:

void foo(char) {}
void foo(int) {}

short s = 42;
foo(s); // this calls foo(int),
        // because promotion short->int is possible
        // and has a higher rank
        // than conversion short->char.

Your example above cannot compile, because the actual parameter int
cannot be promoted to long (int is never promoted, only "lower" types
are) and its conversion to either short or long has equal rank -
therefore the call is ambiguous.

This has *nothing* to do with representation - these types are all
different even if they have the same representation.

> the idea that
> overloading resolution (and the associated promotion) depends on the
> implementation will make any Ada lawyer faint ;-)

Overload resolution does *not* depend on implementation in C++, it is
precisely defined with no relation to representation.

> > There are many bad ideas in C++. I don't see how this one affects
> > strong type safety.
>
> See above

I still don't see how this or anything else that was mentioned since
the beginning of this thread affects strong type safety. Especially
when the presented arguments are incorrect.


OK. I'm a C++ programmer and I know how to answer my question. I'm
actually surprised that nobody came up with valid explanation of why C+
+ sucks for so long, yet many people were ready to make fun of C++ as
a language that obviously must suck. This shows that there is a
significant bias component in your argumentation and that makes it
(the argumentation) much less effective.
In other words, you can use it to "preach to the choir", but you
cannot use it to reach to an audience that might actually benefit from
what you want to say.

Just imagine - what would happen if there was a C++ programmer on your
tutorial and you presented these arguments? ;-) ;-) ;-)


Here is a valid argument that you can use:

1. C++ as a language has a *subset* that supports strong type safety
in the sense that it is not possible to modify the value of any type
by bypassing the interface of that type. If you stick to that language
subset, you are safe.

2. C++ also has some features that allow to undermine the type safety
by means of untyped or loosely typed *aliases*. In particular, pointer
arithmetic (this includes all kinds of buffer overflows), conversions
through void*, reinterpret_casts, unions and dangling pointers all
allow to modify values of type T by means that are outside of T's
interface and *that* is what makes the whole language unsafe and the
sad reality is that these features are too frequently used - most
likely because they are too easy to use.

You can use point 1. if you want to convince someone that it is
possible to build a reliable system in C++. There are people who
believe in it and there are such systems.
You can use point 2. to convince someone that C++ is not the best
choice when support for reliability is required. The argument about
untyped aliases is valid and widely acknowledged - even within the C++
community, and if anybody objects you can refer to any well known
security vulnerability to make your point. This can create an
opportunity to later highlight the advantages of Ada and perhaps
recruit some new Ada converts.

I hope that this will allow you to better address your audiences.
Even if there is a C++ programmer listening. ;-)

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
                   ` (3 preceding siblings ...)
  2010-04-15 21:31 ` Maciej Sobczak
@ 2010-04-18  0:27 ` Gene
  2010-04-18 20:38 ` Gautier write-only
  5 siblings, 0 replies; 31+ messages in thread
From: Gene @ 2010-04-18  0:27 UTC (permalink / raw)


On Apr 15, 4:59 am, "J-P. Rosen" <ro...@adalog.fr> wrote:
> While preparing the upcomming "Using Object Oriented Technologies in
> Secure Systems" tutorial for Ada-Europe (plug, plug...), I came across
> this beautiful statement (OOTiA, B.1.1.6):
>
> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".
>
> Ain't that cute?

Too, motorcycles are perfectly safe until you have an accident.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-17 22:02                 ` Maciej Sobczak
@ 2010-04-18  8:04                   ` J-P. Rosen
  2010-04-18 20:17                     ` Maciej Sobczak
  0 siblings, 1 reply; 31+ messages in thread
From: J-P. Rosen @ 2010-04-18  8:04 UTC (permalink / raw)


Maciej Sobczak a �crit :
[..]
> No. Not only it is not logical - it will not even compile.
> 
[...]
> Your example above cannot compile, because the actual parameter int
> cannot be promoted to long (int is never promoted, only "lower" types
> are) and its conversion to either short or long has equal rank -
> therefore the call is ambiguous.
> 
> This has *nothing* to do with representation - these types are all
> different even if they have the same representation.
> 
[...]
> Overload resolution does *not* depend on implementation in C++, it is
> precisely defined with no relation to representation.
I admit my C++ is a bit old, based mainly on Stroustrup where I picked
this example from. Is current C++ differs, it is a good thing, but I
still wonder
1) if your description is about standard (1998) C++?
2) if all compilers really behave like this?

> Just imagine - what would happen if there was a C++ programmer on your
> tutorial and you presented these arguments? ;-) ;-) ;-)
If my point is wrong, I'll withdraw it. The first thing when arguing is
to have valid argument, otherwise it is too easy to dismiss you.
Thanks for pointing out valid arguments!

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-18  8:04                   ` J-P. Rosen
@ 2010-04-18 20:17                     ` Maciej Sobczak
  0 siblings, 0 replies; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-18 20:17 UTC (permalink / raw)


On 18 Kwi, 10:04, "J-P. Rosen" <ro...@adalog.fr> wrote:

> I admit my C++ is a bit old, based mainly on Stroustrup where I picked
> this example from. Is current C++ differs, it is a good thing, but I
> still wonder
> 1) if your description is about standard (1998) C++?

This is where I looked at. If necessary/helpful I can provide relevant
citations and paragraph numbers.

> 2) if all compilers really behave like this?

I still don't have a fully-compliant Ada 2005 compiler, so...

Back to C++ - it does not matter what *all* compilers do; what does
matter in the industry is what the two most popular do (g++/VC++).
There are plenty of "C++" compilers around.

> Thanks for pointing out valid arguments!

There is no reason to hide them - awareness of problems benefits
everybody.

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
                   ` (4 preceding siblings ...)
  2010-04-18  0:27 ` Gene
@ 2010-04-18 20:38 ` Gautier write-only
  2010-04-19  8:46   ` Maciej Sobczak
  5 siblings, 1 reply; 31+ messages in thread
From: Gautier write-only @ 2010-04-18 20:38 UTC (permalink / raw)


> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".

The whole debate went over my head of a simple programming language
user, but perhaps it would be enlightening to have a few examples. For
instance:

- in C++, is it possible to do arithmetic with the (or a) boolean
type, or convert silently from/to integer ?
- in C++, is it possible to assign a value of a type enum1 to a
variable of type enum2, or is it possible to do any mix or arithmetic
without something like enum1'Pos ?

Sorry, I don't have the answer (my last experience with C++ was 15
years ago, linked to some math exercise...). Any help ?
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
NB: For a direct answer, e-mail address on the following web site:
http://www.fechtenafz.ethz.ch/wm_email.htm



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A new notion: stronglly-typed-by-user language
  2010-04-18 20:38 ` Gautier write-only
@ 2010-04-19  8:46   ` Maciej Sobczak
  0 siblings, 0 replies; 31+ messages in thread
From: Maciej Sobczak @ 2010-04-19  8:46 UTC (permalink / raw)


On 18 Kwi, 22:38, Gautier write-only <gautier_niou...@hotmail.com>
wrote:

> - in C++, is it possible to do arithmetic with the (or a) boolean
> type, or convert silently from/to integer ?

Yes, bool is promoted to int (false->0, true->1) when used in mixed
context.

> - in C++, is it possible to assign a value of a type enum1 to a
> variable of type enum2,

No. Enums are distinct types and assignment between them requires
explicit conversion.

> or is it possible to do any mix or arithmetic
> without something like enum1'Pos ?

Enums can be promoted to int, so you can do "arithmetic" on them.
But you would not be able to silently assign the result back to enum,
as conversion from int (the result of "arithmetic") would have to be
explicit.

That is, you cannot use these tricks to silently subvert the type
system to mess the value of the enumeration type.

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2010-04-19  8:46 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-15  8:59 A new notion: stronglly-typed-by-user language J-P. Rosen
2010-04-15  9:19 ` Martin Krischik
2010-04-16  0:22   ` BrianG
2010-04-16  6:26     ` Martin Krischik
2010-04-15  9:59 ` Dmitry A. Kazakov
2010-04-15 10:49 ` Georg Bauhaus
2010-04-15 21:31 ` Maciej Sobczak
2010-04-16  7:28   ` J-P. Rosen
2010-04-16  7:48     ` Dmitry A. Kazakov
2010-04-16 15:32     ` Maciej Sobczak
2010-04-16 16:52       ` Georg Bauhaus
2010-04-16 17:24         ` Dmitry A. Kazakov
2010-04-16 20:53           ` Pascal Obry
2010-04-16 21:51             ` Dmitry A. Kazakov
2010-04-16 20:20       ` J-P. Rosen
2010-04-16 20:50         ` Maciej Sobczak
2010-04-17  5:25           ` J-P. Rosen
2010-04-17  7:00             ` Dmitry A. Kazakov
2010-04-17 11:40               ` J-P. Rosen
2010-04-17 14:09                 ` Dmitry A. Kazakov
2010-04-17 14:33             ` Maciej Sobczak
2010-04-17 18:57               ` J-P. Rosen
2010-04-17 22:02                 ` Maciej Sobczak
2010-04-18  8:04                   ` J-P. Rosen
2010-04-18 20:17                     ` Maciej Sobczak
2010-04-16  7:29   ` Dmitry A. Kazakov
2010-04-16 10:34   ` xavier grave
2010-04-16 19:26     ` Gautier write-only
2010-04-18  0:27 ` Gene
2010-04-18 20:38 ` Gautier write-only
2010-04-19  8:46   ` Maciej Sobczak

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