⬆️ ⬇️

Candy for Valerka

sweetie Have you ever encountered the problem of how to explain to a person, uncorrupted by communication with an iron friend, the basics of programming?



It so happened that we, working in GdeEtotDom (me and anei ), relatively often go to lunch at Mum. The remainder of the dinner is usually a brand candy. Which we do not eat - this is the type mismatch.



But we found a way out, feeding them to Valerka.

I honestly do not know, where does the programming, Valerka and candy, but, in general, once ...

Alexandrescu approaches Valerka and says:



Alexandrescu: Valery candy do you want?

Valerka: Yes

condition check and set value.

After that, Valerka unfolds a candy, eats and throws out a candy wrapper. The candy wrapper is a decorator.

')

Another week passes, Valerka Wirth arrives, and says:

Wirth: Valery, do you want some candy?

Valerka: Yes.

Wirth: And I still have, do you want?

Valerka: Yes.

These are cycles.

Wirth: And I still have, do you want?

Valerka: Yes

Wirth: An no: P

Standard Exception.

If in a few seconds Alexandrescu again comes running and continues to feed Valery, then there will eventually be a standard buffer overflow.

True, new-fangled technology will save you.



Once again, Wirth comes to Valerka, already with a bag, checks whether there are any candies there, and, if there are any, says:

Wirth: Valery, do you want some candy?

Valerka: Yes.

Wirth gives the candy, checks to see if there are any more candies left in the bag, and, if left, offers candy again. This continues until there is at least one candy in the bag.

This is a precondition loop.



Once Wirth came to Valerka and said that there was no candy. Valera grabbed a big stick and hit Wirth.

- Will you give me some candy? He asked sternly.

“I don’t,” Wirth squealed.

But Valery was implacable. He beat Wirth and demanded candy, until he gave up. Valery with pleasure zachavkal candy.

Such they are, cycles with postcondition.



Wirth has already been a bit crazy about Valerka, but for the sake of chocolates he is willing to endure and not like that. Therefore, when Wirth came again and laid out candy in front of him, Valery looked at him expectantly. Wirth took each candy and said:

- Valery, candy you want?

- Yes, - answered Valery and took a candy.

This is a joint or viewing cycle.



Somehow Wirth came to Valerka with candy and counted them. Then he offered Valerka one candy exactly as many times as he counted candies.

This is a cycle with a counter.



And then Stroustrup comes and says

Stroustrup: Valery, candy you want?

Valerka: Yes

Stroustrup: And do you want?

Valerka: Sek, this dog

mutex



Then Wiener comes to Valerka and says:

Wiener: Valerka, do you want candy?

Valerka: Yes

Wiener: And do you want?

Valerka: Of course, yes

Wiener: But I’ll wait until you get your first

thread synchronization



And one day Norton came to Valerka himself.

Norton: Valery, do you want candy?

Valerka: Yes

Norton: I'll give you a package right away

Valery takes and shifts from the package to the bowl, and then begins to eat.

This is a bunch. More precisely LIFO. At the same time, the process of passing the candy inside Valerka, forgive me - FIFO.



And one night a cyberdemon came to Valerka .

Cyberdemon: Valery want some candy !! ??

Valerka: yes at any time of the day or night! I will!

The cyber-demon gives Valerka a piece of candy, unfolds from it and ... did not hold, Valerka did not validate the incoming data.



We are not going to tell you how Valerka was braked by a certain gang of four in a dark alley and what kind of candy he got from them, and how he once got a candy from Hell - let's better tell the last story about the unchangeable candy!

How many do not let her Valerka - she all the time appears again.

And I don’t even know what kind of fabulous candy any unrecorded references are, or just singleton.



This technique was tested on my mother-in-law (Valeria) and the youngest son (Valerka, but he does not eat candy, let's replace the bread crumbs), and it works.



image In the process of writing, none of Valerka was hurt, but he did not receive a single wardrobe. Thank God the topic scored enough points to provide Valerka an invite. So candy is now among us.





PS: The best commentator is a box of chocolates (MSK, SPb) in the form of a textbook.







The best of comments

(yes there is almost all the best)

anei

Knut also regularly brought candy to Valery. But once he got tired of going to the store himself, he called the boy from the street and said:

“Run away, my friend, for the candy“ Cow ”to the store. Here's your money.

Since then, a boy has been running to the store.

The boy is a function, the name of the candy and money are the arguments, the candy is the return value.



Thepretender

And, and more pointers need to be explained:



Ritchie comes and says:

Ritchie: Sweetie?

Valerka: Atozh!

Ritchie: Here's a piece of paper for you, the address of the store is on it. Get off and buy some candy.

This is a pointer :))



Valery comes to the address, and there is no longer a grocery store, and a shoe. This is the wrong caste due to the lack of type checking.



Valerka comes to the address, and falls into a tunnel to the center of the Earth, which they dug in the place of a demolished store. This is an access violation.



Valery comes to the store, and in search of the confectionery department crashes into the wall. This is an access violation due to the lack of array bounds checking.



Theshock

Then Bill comes to Valerka and says:

Bill: Valery, you want some candy?

Valerka: Yes

Valery took the candy, for a long time he could not unpack it, and then she from him, at the most inopportune moment, fell out of hand in the dirt

these are problems with cross-browser compatibility (interner explorer)

Source: https://habr.com/ru/post/109076/



All Articles