www.digitalmars.com         C & C++   DMDScript  

D - [Language design] Notational error

reply Manfred Nowak <svv1999 hotmail.com> writes:
In D it is allowed to call a function like this:

| fori(0, 0)

and like this

| fori(0.0)

provided, that `f' is overloaded for example like this:

| void fori(real v){someglobalrealvariable=v;...}
| void fori(int start, int end){for(i=start;i<=end;i++){...}}


However, if the programmer wants to type `f(0.0)' but instead types
`f(0,0)' the catastrophe might be unavoidable:

| Here is a very real example of catastrophic system failure due to a
| simple syntactical problem in a programming language:
|
| The USSR Mars probe, released from the Earth's atmosphere on November
| 27,1971, crash landed on the surface of Mars because its booster rockets
| failed. The failure was due to a single character mistake in the landing
| algorithm, which was written in Fortran. There was a breaking routine
| with a waiting loop of the style "FOR I=1,1000", which didn't perform
| properly, because the comma was replaced with a period, which was
| compiled as "FORI=1.1", variable "FORI" was assigned the value "1.1".
http://www.amadeus-3.com/main_files/oberon2vsCPP.php, [cited 06.02.04]

How does this agree with D's design goal:
| for practical programmers who need to get the job done quickly, reliably

So long.
Feb 05 2004
next sibling parent reply The Lone Haranguer <The_member pathlink.com> writes:
C learned from the problems of Fortrash.

But I suppose that this kind of problem can crop up in D if the recent
suggestion of auto-declared variables (or whatever the term was) is allowed.

These examples are the reason why modern (as opposed to 50s-era) languages
require double entry bookkeeping.
Feb 05 2004
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
The Lone Haranguer wrote:

 But I suppose that this kind of problem can crop up in D if the recent
 suggestion of auto-declared variables (or whatever the term was) is allowed.

I am with you.
 These examples are the reason why modern (as opposed to 50s-era) languages
 require double entry bookkeeping.

Double entry bookkeeping? In the example replace the two int's with two real's, then there is no double bookkeeping for a call with two int's, but dmd still does not evoke an error because of the automatic type casting. Moreover, as D is supposed to be used in programming teams, the two functions might be public and included in a module used by another team member. Have you ever read through a whole interface description? I usually stopped, when I found the function I need. So I would not be even aware of the fact, that the needed function might be overloaded. If double bookkeeping would be followed to the end, then it would mean for a distributed development team, that every used function from a "foreign" module has to be introduced explicitely into the current scope and that no tool is allowed to help with this introducing. As you surely know this is not the case with D. However, to avoid the accidentically call of an overloaded function containing one number, respectively two numbers in comparable position, D should - turn off automatic type casting, or if this is not enough - require double bookkeeping in the importing module. I.e. in the example when the overload `fori(int, int)' is declared the call `fori(0,0)' should generate something like: | ... : ambiguous overloads for 'fori', introduce overload into scope when the overload `fori(real, real)' is declared the call `fori(0,0)' should generate something like: | ... : ambiguous overloads for 'fori', no implicit type cast in either case the call `fori(0.0)' should generate something like: | ... : ambiguous overloads for 'fori', introduce overload into scope So long.
Feb 05 2004
parent "Walter" <walter digitalmars.com> writes:
"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:bvv8at$2ben$1 digitaldaemon.com...
 These examples are the reason why modern (as opposed to 50s-era)


 require double entry bookkeeping.


I think what Lone is saying is that there should be redundancy in the syntax of the language. Such redundancy will help pick up errors. If a language had no redundancy in it, then any string of random characters would be a valid program. Good language design balances the need for redundancy with orthogonality.
 In the example replace the two int's with two
 real's, then there is no double bookkeeping for a call with two int's, but
 dmd still does not evoke an error because of the automatic type casting.

The problem is mitigated, as compared with C++, with D's much more restrictive notion of overloading. D doesn't have C++'s large number of levels of overloading. It has only 3: exact match, match with implict conversions, and no match. This makes such overloading errors far less likely in D.
Feb 12 2004
prev sibling next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
1) no problems here in typing the wrong of two.. its a different place.

2) syntax highlighting the way i do it makes such situations VERY obvious.

namely my numbers are always dark yellow (good to read on white, but not
really pointing out of the screen)
my keytokens ( ({,})+-*/%&| and all those), are all in red (very pointing
out of the screen)..

so

fori(0,0)
and
fori(0.0)

would look entierly different.

and btw, you can do this in c++ as well (and java, i think, too).

"Manfred Nowak" <svv1999 hotmail.com> schrieb im Newsbeitrag
news:bvunid$1fqg$1 digitaldaemon.com...
 In D it is allowed to call a function like this:

 | fori(0, 0)

 and like this

 | fori(0.0)

 provided, that `f' is overloaded for example like this:

 | void fori(real v){someglobalrealvariable=v;...}
 | void fori(int start, int end){for(i=start;i<=end;i++){...}}


 However, if the programmer wants to type `f(0.0)' but instead types
 `f(0,0)' the catastrophe might be unavoidable:

 | Here is a very real example of catastrophic system failure due to a
 | simple syntactical problem in a programming language:
 |
 | The USSR Mars probe, released from the Earth's atmosphere on November
 | 27,1971, crash landed on the surface of Mars because its booster rockets
 | failed. The failure was due to a single character mistake in the landing
 | algorithm, which was written in Fortran. There was a breaking routine
 | with a waiting loop of the style "FOR I=1,1000", which didn't perform
 | properly, because the comma was replaced with a period, which was
 | compiled as "FORI=1.1", variable "FORI" was assigned the value "1.1".
 http://www.amadeus-3.com/main_files/oberon2vsCPP.php, [cited 06.02.04]

 How does this agree with D's design goal:
 | for practical programmers who need to get the job done quickly, reliably

 So long.

Feb 06 2004
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
davepermen wrote:

 1) no problems here in typing the wrong of two.. its a different place.

I do not grep what you mean.
 2) syntax highlighting the way i do it makes such situations VERY
 obvious.

That is nice. But syntax highlighting is not part of the language. However, that drives me to the question, whether white space should be made part of the language by introducing a `, ' token as separator for argument lists. Then at least two characters must be wrongly typed.
 and btw, you can do this in c++ as well (and java, i think, too).

That is at least true for c++. But why follow old errors? So long.
Feb 06 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
i don't accidentally type the wrong one as the keys are placed in a way to
get accessed very differently by my hands. thats what i ment with 1)

2) i know, it's not a language feature. but there is NO reason today to not
do your work on a pc, and then send it to the device. and if you work on a
pc, you can have at least TextPad to syntax highlight. hey, we're in 2004.
:D

btw, i DO understand the problem. i just don't think it is a real problem in
real development environments and situations of today anymore.

"Manfred Nowak" <svv1999 hotmail.com> schrieb im Newsbeitrag
news:bvvpgb$563$1 digitaldaemon.com...
 davepermen wrote:

 1) no problems here in typing the wrong of two.. its a different place.

I do not grep what you mean.
 2) syntax highlighting the way i do it makes such situations VERY
 obvious.

That is nice. But syntax highlighting is not part of the language. However, that drives me to the question, whether white space should be made part of the language by introducing a `, ' token as separator for argument lists. Then at least two characters must be wrongly typed.
 and btw, you can do this in c++ as well (and java, i think, too).

That is at least true for c++. But why follow old errors? So long.

Feb 06 2004
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
On Fri, 06 Feb 2004 11:18:54 +0100, davepermen wrote:

[...]
 the keys are placed in a way to get accessed very differently by my
 hands.

Upps! Which country do you live in?
 there is NO reason today to not do your work on a pc

Are you sure? When have you last time convinced the boss of your 300 computer scientists development team to introduce for the whole team an IDE, text program or syntax highlighting extension of your choice? I am really not used to work in military, medical, juridical or environments for the caring professions. You might be more experienced in this areas to state such an opinion. So long.
Feb 06 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
 Upps! Which country do you live in?

that the right english word? :D). default qwertz layout.
 Are you sure?

integrated controllers, and all. they upload it trough some COM port to the actual system. everyone uses at least DOS with 'edit', to write the code. and today, about every workstation for programmers needs (as every workstation at all:D) some sort of outlook for mailing (hehe), and some sort of internet access (oooonly for searching for infos about current problems, of course..). i know of no programmer who preferes non-syntax-highighted text over syntax-highlighted one. D gives enough possible IDE's and coloured text-editors to chose from.
 When have you last time convinced the boss of your 300 computer scientists
 development team to introduce for the whole team an IDE, text program or
 syntax highlighting extension of your choice?

boss.. hey, it's just the boss:D
 I am really not used to work in military, medical, juridical or
 environments for the caring professions. You might be more experienced in
 this areas to state such an opinion.

more comfortable tool to use, people addopt rapitly. and if it's free, even the boss can't complain. and we're talking about D here. how much people are yet in D that don't want to change to an IDE because thei're so used to notepad or 'edit' in dos? i know none. and if we're talking about c++.. vc6 is standard in most places.. never ones / other ones exist, too, of course. but i know of no ide that is in use that doesn't have syntax highlighting. again, we're in 2004. i have 16million colours to spend on 1310720 pixels. i won't write at any time in black and write. except for this newsgroup mails..
 So long.

Feb 06 2004
parent reply Scott Wood <scott buserror.net> writes:
On Fri, 6 Feb 2004 18:35:52 +0100, davepermen <davepermen hotmail.com> wrote:
 i know of no programmer who preferes non-syntax-highighted text over
 syntax-highlighted one.

You do now. :-) I find it distracting and ugly, especially when bright colors are used. I do use fonts (and sizes thereof) in which commas and periods are easily distinguishable, though. -Scott
Feb 06 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
well, then its your own choise..

i love colours. you know.. live is dark and grey enough. why shall my pc?

then again.. i'm listening to trance :D lasers, colourful lights, fancy
outfits.. (no drugs, no alc, no smoking, though.. hehe:D)

i like a colourful world.

"Scott Wood" <scott buserror.net> schrieb im Newsbeitrag
news:slrnc28ub8.23b.scott aoeu.buserror.net...
 On Fri, 6 Feb 2004 18:35:52 +0100, davepermen <davepermen hotmail.com>

 i know of no programmer who preferes non-syntax-highighted text over
 syntax-highlighted one.

You do now. :-) I find it distracting and ugly, especially when bright colors are used. I do use fonts (and sizes thereof) in which commas and periods are easily distinguishable, though. -Scott

Feb 07 2004
parent reply "C" <dont respond.com> writes:
 (no drugs, no alc, no smoking, though.. hehe:D)

C "davepermen" <davepermen hotmail.com> wrote in message news:c03r21$1d19$1 digitaldaemon.com...
 well, then its your own choise..

 i love colours. you know.. live is dark and grey enough. why shall my pc?

 then again.. i'm listening to trance :D lasers, colourful lights, fancy
 outfits.. (no drugs, no alc, no smoking, though.. hehe:D)

 i like a colourful world.

 "Scott Wood" <scott buserror.net> schrieb im Newsbeitrag
 news:slrnc28ub8.23b.scott aoeu.buserror.net...
 On Fri, 6 Feb 2004 18:35:52 +0100, davepermen <davepermen hotmail.com>

 i know of no programmer who preferes non-syntax-highighted text over
 syntax-highlighted one.

You do now. :-) I find it distracting and ugly, especially when bright colors are used. I do use fonts (and sizes thereof) in which commas and periods are easily distinguishable, though. -Scott


Feb 07 2004
next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
nah.. it's just me and some of my friends.

i don't see much in these manipulating things.. a) i know them by testing b)
my own medicine works stronger than most of it :D (asthma and alergies, as
every freak:D)

i've medicine that can kill my brain so that it can't remember anything
older than 5 minutes:D thats fun in school.. espencially if the teacher
tries to explain you something.. you'lle be damn sure i'll ask it again in 5
minutes:D

on http://davepermen.net are some picts of me and friends at certain events
btw..

now you should just know wich one i am :D

wait....


"C" <dont respond.com> schrieb im Newsbeitrag
news:c03sk7$1feb$1 digitaldaemon.com...
 (no drugs, no alc, no smoking, though.. hehe:D)

C "davepermen" <davepermen hotmail.com> wrote in message news:c03r21$1d19$1 digitaldaemon.com...
 well, then its your own choise..

 i love colours. you know.. live is dark and grey enough. why shall my


 then again.. i'm listening to trance :D lasers, colourful lights, fancy
 outfits.. (no drugs, no alc, no smoking, though.. hehe:D)

 i like a colourful world.

 "Scott Wood" <scott buserror.net> schrieb im Newsbeitrag
 news:slrnc28ub8.23b.scott aoeu.buserror.net...
 On Fri, 6 Feb 2004 18:35:52 +0100, davepermen <davepermen hotmail.com>

 i know of no programmer who preferes non-syntax-highighted text over
 syntax-highlighted one.

You do now. :-) I find it distracting and ugly, especially when bright colors are used. I do use fonts (and sizes thereof) in which commas and periods are easily distinguishable, though. -Scott



Feb 07 2004
parent "davepermen" <davepermen hotmail.com> writes:
http://davepermen.homeip.net/Pictures/Escape/24Jan2004/Pict0034.jpg

here.. thats me..

"davepermen" <davepermen hotmail.com> schrieb im Newsbeitrag
news:c03t71$1ga0$1 digitaldaemon.com...
 nah.. it's just me and some of my friends.

 i don't see much in these manipulating things.. a) i know them by testing

 my own medicine works stronger than most of it :D (asthma and alergies, as
 every freak:D)

 i've medicine that can kill my brain so that it can't remember anything
 older than 5 minutes:D thats fun in school.. espencially if the teacher
 tries to explain you something.. you'lle be damn sure i'll ask it again in

 minutes:D

 on http://davepermen.net are some picts of me and friends at certain

 btw..

 now you should just know wich one i am :D

 wait....


 "C" <dont respond.com> schrieb im Newsbeitrag
 news:c03sk7$1feb$1 digitaldaemon.com...
 (no drugs, no alc, no smoking, though.. hehe:D)

C "davepermen" <davepermen hotmail.com> wrote in message news:c03r21$1d19$1 digitaldaemon.com...
 well, then its your own choise..

 i love colours. you know.. live is dark and grey enough. why shall my


 then again.. i'm listening to trance :D lasers, colourful lights,



 outfits.. (no drugs, no alc, no smoking, though.. hehe:D)

 i like a colourful world.

 "Scott Wood" <scott buserror.net> schrieb im Newsbeitrag
 news:slrnc28ub8.23b.scott aoeu.buserror.net...
 On Fri, 6 Feb 2004 18:35:52 +0100, davepermen




 wrote:
 i know of no programmer who preferes non-syntax-highighted text





 syntax-highlighted one.

You do now. :-) I find it distracting and ugly, especially when bright colors are used. I do use fonts (and sizes thereof) in which commas and




 are easily distinguishable, though.

 -Scott




Feb 07 2004
prev sibling parent Matthias Becker <Matthias_member pathlink.com> writes:
 (no drugs, no alc, no smoking, though.. hehe:D)


hu? I live in germany ...
Feb 08 2004
prev sibling parent reply Mark T <Mark_member pathlink.com> writes:
However, if the programmer wants to type `f(0.0)' but instead types
`f(0,0)' the catastrophe might be unavoidable:

| Here is a very real example of catastrophic system failure due to a
| simple syntactical problem in a programming language:
|
| The USSR Mars probe, released from the Earth's atmosphere on November
| 27,1971, crash landed on the surface of Mars because its booster rockets
| failed. The failure was due to a single character mistake in the landing
| algorithm, which was written in Fortran. There was a breaking routine
| with a waiting loop of the style "FOR I=1,1000", which didn't perform
| properly, because the comma was replaced with a period, which was
| compiled as "FORI=1.1", variable "FORI" was assigned the value "1.1".

1) that's what code reviews are for, if the app is safety or "mission" critical then it should be thoroughly review. 2) Unit testing would probably have found it also even a very strict language like Ada will not prevent all "human" mistakes
Feb 06 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
Mark T wrote:

 that's what code reviews are for

Reviews cannot remedy weaknesses of languages. Have you herd of the error free approach to programming? Every piece of text was accepted and translated into some machine code. Would you like to review something like that? So long.
Mar 09 2004