Dialogue # 28: Contracts, Promises, And Mere Semantics

zhaozj2021-02-16  50

Dialogue # 28: Contracts, Promises, And Mere Semantics

Like most days, I started the job that day - in my square room, with fresh coffee, before starting writing the code, I was holding the morning Email. Very strange, it, Guru did not suddenly appear behind me. In fact, I accidentally heard it happened to another person.

I am working quietly at the desk, and I heard the time of nearby colleagues, this is the sound.

"Time is here," Guru said, "Talk about something."

I habitually jumped. I look at it around, but Guru did not stand behind me. I went to hear the squeak in the next room - it was Kerry, our group smart and annoying newcomers, jumping from his chair. She is with him. I doubt how long he can last; Guru scared to the most newcomers in the top months, it is equal to turn around. Kerry has been manifested as an early collapse symptom. I estimate that he will only stick to it several weeks.

I am talking about a little guilty:

"Bob tells me, there is a problem in my new code ..." I heard Kerry started to resist.

"Yes, my child?" I can recall her eyebrows and laugh at me.

"Well ... Yes. It is about coding specifications, I will get it yourself ..."

I heard the voice on the book. Guru has already closed her "brick". I am too lazy to guess what is she brought today. "Tell me, youth," I heard Guru said to Kerry, "What is our code specification? Say."

"Well ... they are here." At the same time, I also switched out the same file and found the location of him. This is part of it:

When the parameter type is declared, it is best to follow the traditional C interface usual method:

l If the argument needs to be changed, the pointer is passed.

l If the actor is not changed, the value is passed.

"I didn't do this, so Bob pointed out it. It is so much. This is right. This is right; I will modify;" Kerry is finished, it sounds very nervous.

There is a pause, I am guessing Guru is smiling or frowning. Finally, she said: "Do this, now. Now. Update code, but don't check IN. But let him see, let him use, and let him use it, then wait."

"Waiting? ... Why?" Kerry asked.

This time I determined Guru in smiling. "Just waiting, apprentice," she said, then I heard the footsteps of the shades of Shasha and the back.

The performance of the performance, I think, so I will go back. But the most exciting part will always be staged ...

After a few hours, when I was caught in the code, I heard Kerry called Bob's office desk. Although it was a bit far, but it was not far to let me hear the sound of Bobatrom Kerry.

After a while, Bob seems to be enough, Kerry is put back, lonely (I think) back to his room. When he sat down, the chair raised it, and then became silent ... but did not last for a long time.

About five minutes, I came again, the sound of Guru, Kerry's chair screamed again (or Kerry hair? He has become accustomed to sending a snoring when Guru appears), another dialogue:

"Why is the C language is hot," Guru suddenly said, "said the pig has wings." I laughed behind, I know that she may be saying Bob.

()) "I ... I said to Bob ..." "Indeed, you have done it, the child, I can hear the entire building," came to Guru soft voice. It comes from a very fast voice. "And what did he say?"

"My code must be wrong; it makes his code can't work," Kerry settled in Baba. "But I don't know what I did. I just did what he said! I just said according to the code specification!"

"Ah," - I showed Guru sharply smile - "But they are the same thing. Because Bob is one of the people who make this part of the coding specification."

"... he ... he is?"

"Oh, yes. He is indeed, apprentice. This is the reason why the code specification has occurred."

"error?"

"That is wrong for C usage," she continued.

"Although it is correct for C language without 'reference'."

"But ... if it is wrong, why don't they update?"

"Our new manager, Pete Williams, too trusted Bob, can't see the actual needs," she sighed. "His predecessor did not do this. So, the code specification is not correct. C usual method is more like this ..." I heard the writing pen on the whiteboard, this is I later seen on the whiteboard:

When the parameter type is declared, it is best to follow the traditional C interface usual method unless it is not suitable:

l If the argument needs to be changed, pass non-Const's pointer or reference.

l If the argument is not changed, the CONST reference is passed, or when the copy is overhead.

"This statement is relatively close," Guru summed up, "But

"Well ... Yes. No problem. Bob said that it applies to everything he tried, except ..."

"Auto_PTR object," Guru nodded, told him, I heard she continued to write on the whiteboard.

Kerry sent a surprised voice. "How do you know! Bob tells you? Do you see?"

"I just know. I don't need to see it." She continued to write on the whiteboard, and here is what I saw after a few minutes:

Template

Void Mutate (T * ByPointer);

Template

Void Mutate (T & Byreference);

Template

Void LeaveAlone (const t * bypointertoconst);

Template

Void LeaveAlone (Const T & ByrefeeElectrtoConst);

Template

Void LeaveAlone;

"I want to find this example, then answer: Which type of T, the name of the function is the name of the name!" She said.

I don't know what she is talking about, until I heard a different flavor, a piece of rubber rebounded from my head. Then I quickly reacted, I took my head and joined them.

"Well? What?" I muttered. "I am busy working." "In fact, you are concentrating on your ears." Guru squatted for a while, pretending to worry, and then I saw her flashing gaze. After putting down the writing pen, she opened her thick book and hangs her hair behind her ear, and smiled and walked away. "My apprentice will explain, my child ..." Her reply from the shoulders, just in the moment of her turn disappeared. I shook my head and grin. What behavior! But Kerry looked at me, I doubt that he didn't start with my and Guru in the "magic". I found that I won't mind if he did this; this gave me an interesting revelation.

"Young people," I said with a smile. I realized what I just said, I laughed more, "When you pass an auto_ptr, what happens?"

"Well ... oh!" Very clearly, Kerry has already understood. "Pass all ownership! Is she talking about this?"

"yes, I agree. "You have already understood. And the same thing happens in all the transfer of all rights - by way of manner, the typical feature is the use of non-Const references on the shape of the copy constructor. This is what you want: the value is usually meaningful You won't touch source objects, except for auto_ptr, the opposite of it - and worse, because not only modify the source auto_ptr, but also set it for null. And the pointer often means that the source object is prepared, except for auto_ptr, It has the opposite of it - you are avoiding it. For Auto_PTR, traditional usual methods are doing bad things. This is based on the usual customary code, such as the assumptions of the container to them, cannot be used, and auto_ptr The reason for collaborative work. But not just for auto_ptr; all classes that are transferred when copying, you must pay special attention to non-Const reference parameters in copy constructor; that is, you usually miss the fatisies. "

"Now," I took my voice into the body, "I have to go back to continue my meditation." I arrived at the end of the walkway, turned into a bend, just disappeared from his perspective, I couldn't help but I have to eat a smile.

[references]

[1] H. SUTTER AND J. Hyslop. "Conversations: a Midsummer Night's Madness," C / C Uses Journal C Experts Forum, August 2002.

转载请注明原文地址:https://www.9cbs.com/read-26716.html

New Post(0)