Thread overview | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 07, 2005 [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
1) Review this code: void f( inout int i, inout int j){ i= 1; j= 2; } 2) Pass or Fail? 3) Explain. -manfred |
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | Manfred Nowak wrote:
> 1) Review this code:
>
> void f( inout int i, inout int j){
> i= 1;
> j= 2;
> }
>
>
> 2) Pass or Fail?
>
> 3) Explain.
>
>
> -manfred
I don't get it.
|
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | On Sun, 7 Aug 2005 01:05:27 +0000 (UTC), Manfred Nowak wrote: > 1) Review this code: > > void f( inout int i, inout int j){ > i= 1; > j= 2; > } Okay, done that. (A) Function name 'f' is not meaningful enough. (B) Argument 'i' is not meaningful enough for the context. (C) Argument 'j' is not meaningful enough for the context. (D) Inconsistent spacing on lines 2 and 3. Use either <identifer>=<expression>; or <identfier> = <expression>; (E) The opening brace should not be on the function declaration line. (F) The function body lines are not indented correctly. The standard calls for four spaces. > 2) Pass or Fail? Yes and no. > 3) Explain. I am unable to explain because I haven't the foggiest idea what you are on about. Explain *what*? -- Derek Parnell Melbourne, Australia 7/08/2005 6:15:41 PM |
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell <derek@psych.ward> wrote: > On Sun, 7 Aug 2005 01:05:27 +0000 (UTC), Manfred Nowak wrote: > >> 1) Review this code: >> >> void f( inout int i, inout int j){ >> i= 1; >> j= 2; >> } > > Okay, done that. > > (A) Function name 'f' is not meaningful enough. > (B) Argument 'i' is not meaningful enough for the context. > (C) Argument 'j' is not meaningful enough for the context. > (D) Inconsistent spacing on lines 2 and 3. Use either > <identifer>=<expression>; > or > <identfier> = <expression>; > (E) The opening brace should not be on the function declaration > line. (F) The function body lines are not indented correctly. > The standard calls for four spaces. Okay, you are the quality assurer and I want to implement this routine into a piece of software, that on failure cause severe harm, i.e. loss of lives or money. So I do what you want me to: void letThem( inout int becomesOne, inout int becomesTwo) { becomesOne = 1; becomesTwo = 2; } [...] > I am unable to explain because I haven't the foggiest idea what you are on about. Explain *what*? See above and repeat the three steps. Hint: try harder. -manfred |
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | The only thing I can think of is that the inout parameters are being used as out parameters, which isn't necessarily incorrect behavior.
-John Demme
On Sun, 2005-08-07 at 01:05 +0000, Manfred Nowak wrote:
> 1) Review this code:
>
> void f( inout int i, inout int j){
> i= 1;
> j= 2;
> }
>
>
> 2) Pass or Fail?
>
> 3) Explain.
>
>
> -manfred
|
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | In article <dd4hhk$30fd$1@digitaldaemon.com>, Manfred Nowak says... > >Okay, you are the quality assurer and I want to implement this routine into a piece of software, that on failure cause severe harm, i.e. loss of lives or money. So I do what you want me to: > >void letThem( inout int becomesOne, inout int becomesTwo) >{ > becomesOne = 1; > becomesTwo = 2; >} > >[...] Perhaps you're thinking of calls of the kind int i; letThem(i,i); in which case i==2? This can be avoided by adding a contract, ie. | void letThem( inout int becomesOne, inout int becomesTwo) | out | { | assert(becomesOne == 1); | assert(becomesTwo == 2); | } | body | { | becomesOne = 1; | becomesTwo = 2; | } Nick |
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | On Sun, 7 Aug 2005 08:42:28 +0000 (UTC), Manfred Nowak <svv1999@hotmail.com> wrote: > Derek Parnell <derek@psych.ward> wrote: > >> On Sun, 7 Aug 2005 01:05:27 +0000 (UTC), Manfred Nowak wrote: >> >>> 1) Review this code: >>> >>> void f( inout int i, inout int j){ >>> i= 1; >>> j= 2; >>> } >> >> Okay, done that. >> >> (A) Function name 'f' is not meaningful enough. >> (B) Argument 'i' is not meaningful enough for the context. >> (C) Argument 'j' is not meaningful enough for the context. >> (D) Inconsistent spacing on lines 2 and 3. Use either >> <identifer>=<expression>; >> or >> <identfier> = <expression>; >> (E) The opening brace should not be on the function declaration >> line. (F) The function body lines are not indented correctly. >> The standard calls for four spaces. > > Okay, you are the quality assurer and I want to implement this > routine into a piece of software, that on failure cause severe > harm, i.e. loss of lives or money. So I do what you want me to: > > void letThem( inout int becomesOne, inout int becomesTwo) > { > becomesOne = 1; > becomesTwo = 2; > } And what happens when it's called like: int a; letThem(a,a); Your function should be coded as: void letThem( inout int becomesOne, inout int becomesTwo) out() { assert(becomesOne == 1); assert(becomesTwo == 2); } body { becomesOne = 1; becomesTwo = 2; } or similar (I can't remember the syntax - bad me) > [...] >> I am unable to explain because I haven't the foggiest idea what >> you are on about. Explain *what*? > > See above and repeat the three steps. Hint: try harder. I assume there is a point to this? Regan |
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | On Sun, 7 Aug 2005 08:42:28 +0000 (UTC), Manfred Nowak wrote: > Derek Parnell <derek@psych.ward> wrote: > >> On Sun, 7 Aug 2005 01:05:27 +0000 (UTC), Manfred Nowak wrote: >> >>> 1) Review this code: >>> >>> void f( inout int i, inout int j){ >>> i= 1; >>> j= 2; >>> } >> >> Okay, done that. >> >> (A) Function name 'f' is not meaningful enough. >> (B) Argument 'i' is not meaningful enough for the context. >> (C) Argument 'j' is not meaningful enough for the context. >> (D) Inconsistent spacing on lines 2 and 3. Use either >> <identifer>=<expression>; >> or >> <identfier> = <expression>; >> (E) The opening brace should not be on the function declaration >> line. (F) The function body lines are not indented correctly. >> The standard calls for four spaces. > > Okay, you are the quality assurer and I want to implement this routine into a piece of software, that on failure cause severe harm, i.e. loss of lives or money. So I do what you want me to: > > void letThem( inout int becomesOne, inout int becomesTwo) > { > becomesOne = 1; > becomesTwo = 2; > } > > [...] >> I am unable to explain because I haven't the foggiest idea what you are on about. Explain *what*? > > See above and repeat the three steps. Hint: try harder. Okay ... (G) The specification does not say what to do with the passed values of the arguments. (H) The specification does not define if setting both values is to be atomic; that is, either none is set or both are set, or it doesn't matter. (J) The specification does not define what to do when the arguments refer to the same memory location. Should this routine be a bit more defensive, maybe along the lines of ... void letThem( inout int becomesOne, inout int becomesTwo) { int localOne; int localTwo; // Ensure the arguments reference two different integer values. if (RAM_Overlaps(&becomesOne, int.sizeof, &becomesTwo, int.sizeof)) { throw ReferenceException( ...whatever...); } // Take a local backup of value in case the transaction fails localOne = becomesOne; localTwo = becomesTwo; try { becomesOne = 1; becomesTwo = 2; } catch(Object e) { // Transaction failed, so restore previous values. becomesOne = localOne; becomesTwo = localTwo; throw e; // Pass exception up the tree. } } -- Derek Parnell Melbourne, Australia 7/08/2005 7:31:28 PM |
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> On Sun, 7 Aug 2005 08:42:28 +0000 (UTC), Manfred Nowak wrote:
>
>
>>Derek Parnell <derek@psych.ward> wrote:
>>
>>
>>>On Sun, 7 Aug 2005 01:05:27 +0000 (UTC), Manfred Nowak wrote:
>>>
>>>
>>>>1) Review this code:
>>>>
>>>>void f( inout int i, inout int j){
>>>> i= 1;
>>>> j= 2;
>>>>}
>>>
>>>Okay, done that.
>>>
>>>(A) Function name 'f' is not meaningful enough.
>>>(B) Argument 'i' is not meaningful enough for the context.
>>>(C) Argument 'j' is not meaningful enough for the context.
>>>(D) Inconsistent spacing on lines 2 and 3. Use either
>>> <identifer>=<expression>; or <identfier> = <expression>;
>>>(E) The opening brace should not be on the function declaration
>>>line. (F) The function body lines are not indented correctly.
>>>The standard calls for four spaces.
>>
>>Okay, you are the quality assurer and I want to implement this routine into a piece of software, that on failure cause severe harm, i.e. loss of lives or money. So I do what you want me to:
>>
>>void letThem( inout int becomesOne, inout int becomesTwo)
>>{
>> becomesOne = 1;
>> becomesTwo = 2;
>>}
>>
>>[...]
>>
>>>I am unable to explain because I haven't the foggiest idea what
>>>you are on about. Explain *what*?
>>
>>See above and repeat the three steps. Hint: try harder.
>
>
> Okay ...
>
> (G) The specification does not say what to do with the passed values of the
> arguments.
> (H) The specification does not define if setting both values is to be
> atomic; that is, either none is set or both are set, or it doesn't matter.
> (J) The specification does not define what to do when the arguments refer
> to the same memory location.
>
> Should this routine be a bit more defensive, maybe along the lines of ...
>
>
> void letThem( inout int becomesOne, inout int becomesTwo)
> {
> int localOne;
> int localTwo;
> // Ensure the arguments reference two different integer values.
> if (RAM_Overlaps(&becomesOne, int.sizeof, &becomesTwo, int.sizeof))
> {
> throw ReferenceException( ...whatever...);
> }
>
> // Take a local backup of value in case the transaction fails
> localOne = becomesOne;
> localTwo = becomesTwo;
>
> try { becomesOne = 1;
> becomesTwo = 2;
> }
> catch(Object e)
> {
> // Transaction failed, so restore previous values.
> becomesOne = localOne;
> becomesTwo = localTwo;
> throw e; // Pass exception up the tree.
> }
> }
>
The code isn't thread-safe. Try harder :)
|
August 07, 2005 Re: [test] A D-joke? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang | On Sun, 07 Aug 2005 18:20:17 +0800, zwang wrote: > Derek Parnell wrote: >> On Sun, 7 Aug 2005 08:42:28 +0000 (UTC), Manfred Nowak wrote: >> >> >>>Derek Parnell <derek@psych.ward> wrote: >>> >>> >>>>On Sun, 7 Aug 2005 01:05:27 +0000 (UTC), Manfred Nowak wrote: >>>> >>>> >>>>>1) Review this code: >>>>> >>>>>void f( inout int i, inout int j){ >>>>> i= 1; >>>>> j= 2; >>>>>} >>>> >>>>Okay, done that. >>>> >>>>(A) Function name 'f' is not meaningful enough. >>>>(B) Argument 'i' is not meaningful enough for the context. >>>>(C) Argument 'j' is not meaningful enough for the context. >>>>(D) Inconsistent spacing on lines 2 and 3. Use either >>>> <identifer>=<expression>; >>>> or >>>> <identfier> = <expression>; >>>>(E) The opening brace should not be on the function declaration >>>>line. (F) The function body lines are not indented correctly. >>>>The standard calls for four spaces. >>> >>>Okay, you are the quality assurer and I want to implement this routine into a piece of software, that on failure cause severe harm, i.e. loss of lives or money. So I do what you want me to: >>> >>>void letThem( inout int becomesOne, inout int becomesTwo) >>>{ >>> becomesOne = 1; >>> becomesTwo = 2; >>>} >>> >>>[...] >>> >>>>I am unable to explain because I haven't the foggiest idea what you are on about. Explain *what*? >>> >>>See above and repeat the three steps. Hint: try harder. >> >> >> Okay ... >> >> (G) The specification does not say what to do with the passed values of the >> arguments. >> (H) The specification does not define if setting both values is to be >> atomic; that is, either none is set or both are set, or it doesn't matter. >> (J) The specification does not define what to do when the arguments refer >> to the same memory location. >> >> Should this routine be a bit more defensive, maybe along the lines of ... >> >> >> void letThem( inout int becomesOne, inout int becomesTwo) >> { >> int localOne; >> int localTwo; >> // Ensure the arguments reference two different integer values. >> if (RAM_Overlaps(&becomesOne, int.sizeof, &becomesTwo, int.sizeof)) >> { >> throw ReferenceException( ...whatever...); >> } >> >> // Take a local backup of value in case the transaction fails >> localOne = becomesOne; >> localTwo = becomesTwo; >> >> try { >> becomesOne = 1; >> becomesTwo = 2; >> } >> catch(Object e) >> { >> // Transaction failed, so restore previous values. >> becomesOne = localOne; >> becomesTwo = localTwo; >> throw e; // Pass exception up the tree. >> } >> } >> > > The code isn't thread-safe. Try harder :) Yeah ... As soon as I posted it, it occurred to me too. However, I don't know how to 'do threads' in D yet. Manfred, is there a point to all of this? Is it possible for you to speak clearly, and in simple terms, about why you suggested this 'joke'? I'm guessing that you are hinting that D has some really big security holes in it and that is simply a 'bad joke' waiting to laugh at us. But I might be reading in to your minimalistic posting. -- Derek Parnell Melbourne, Australia 7/08/2005 8:33:15 PM |
Copyright © 1999-2021 by the D Language Foundation