Make your own eBooks

Use our Remix App to mix & match content. In minutes make your own course packs, training bundles, custom travel guides, you name it. Even add your own title & cover.

Education
Research
Travel
Health

Slices & Articles Get by the slice or add to your own ebook

Medium 9788328302464

5. Rekurencja

Slice ePub March 02, 2015

Zmienne niemutowalne mają oczywistą wadę: nie można ich zmieniać. Oznacza to, że trudniej jest wykonywać takie czynności, jak zmiana pojedynczego elementu z listy lub implementacja instrukcji if, która ustawia zmienną. Ponadto pomyślmy o niemutowalności w kategoriach aplikacji. W jaki sposób aplikacje mogą działać, jeśli dane nigdy nie mogą się zmienić? W takiej sytuacji musimy użyć rekurencji.

Przeanalizujmy przykład funkcji rekurencyjnej w matematyce. Jak widać, mamy do czynienia z przypadkiem końcowym, jeśli x jest mniejsze lub równe 0, oraz wykonujemy określoną operację dla wszystkich pozostałych przypadków — to jest nasza operacja sumowania.

Przeprowadziliśmy właśnie sumowanie każdej przekazywanej liczby, ale co, jeśli użylibyśmy typów funkcyjnych? Zobaczmy, co możemy zrobić.

Chociaż wygląda na to, że niewiele się zmieniło, udało nam się utworzyć operację sumowania.

Wiele osób boi się rekurencji głównie dlatego, że po prostu się nie nauczyły, w jaki sposób efektywnie pisać funkcje rekurencyjne. Panuje również przekonanie, że algorytmy iteracyjne są z natury lepsze niż algorytmy rekurencyjne. Algorytmy rekurencyjne są znacznie prostsze, ponieważ zajmują się tylko wartościami wejściowymi. Gdybyśmy mieli wykorzystywać standardową pętlę for w procesie iteracyjnym, algorytm musiałby brać pod uwagę listę jako całość. Proste sumowanie w pętli for zostało przedstawione w Przykład 5-1.

See more

Medium 9781449379803

5. Response

Slice ePub May 27, 2014

Code that responds to input from the mouse, keyboard, and other devices has to run continuously. To make this happen, place the lines that update inside a Processing function called draw().

To see how draw() works, run this example:

You'll see the following:

The code within the draw() block runs from top to bottom, then repeats until you quit the program by clicking the Stop button or closing the window. Each trip through draw() is called a frame. (The default frame rate is 60 frames per second, but this can be changed. See Example 7-2: Set the Frame Rate for more information.) In the previous example program, the println() functions write the text "I'm drawing" followed by the current frame count as counted by the special frameCount variable (1, 2, 3, ...). The text appears in the Console, the black area at the bottom of the Processing editor window.

To complement the looping draw() function, Processing has a function called setup() that runs just once when the program starts:

See more

Medium 9781550226980

Citius, Altius, Fortius

Slice ePub July 16, 2014

Oh, I remember it well: the Olympics, Squaw Valley, 1960. The final game of the hockey tournament featured the us against Czechoslovakia. Incredibly, the Americans had knocked off the favored Canadians, and the Russians, and now only the Czechs stood between them and a gold medal. But going into the third period, the group of unheralded college players trailed the skilled Czechs by a score of 4-3. That’s when Nikolai Sologubov, the Russians’ superb defenseman, waltzed into the American dressing room and suggested that the players fortify themselves by inhaling some extra oxygen from tanks. His motive? If the Americans won, the Russians would end up with the bronze medal; if they lost, the Russians would go home empty-handed. Amazingly, the Americans scored six times in the third period for their first “miracle on ice!” Was the extra oxygen responsible?

As I recall, the next day’s newspapers were filled with stories about the ingenuity of the oxygen boost. Nobody suggested that this was in any way unfair. Performance enhancement by means other than training was not yet a big issue, even though “doping” had tainted the Olympics since 1936. Just a year earlier, German scientists had isolated the male sex hormone testosterone and had shown that it increased muscle mass and aggression. There is little doubt that German athletes used it in the 1936 Berlin Olympics along with amphetamines, stimulants that had been found to ward off fatigue. By 1955, various analogues of testosterone, collectively referred to as “anabolic steroids,” had been synthesized and made their way into the bodies of athletes clamoring for glory. It is hard to know how extensive such doping was back in those days, because urine tests for steroids were not introduced until 1973. Only in 1975 did the world’s governing sport bodies officially ban the use of anabolic steroids. That certainly didn’t mean these drugs were not being used. Detection techniques were relatively primitive, and as long as athletes didn’t use steroids just prior to competition, they got away with it.

See more

Medium 9781855754744

Becoming more assertive

Slice ePub May 22, 2014

Basic principle

Becoming assertive is communicating our thoughts and feelings, openly, honestly, clearly, and without violating any other person’s rights. It is the healthy alternative to being aggressive, or to being passive. Being assertive means that we are able to say what we think and feel;

•  we are able to ask for what we want;

•  we can say “Yes” or “No” clearly and firmly;

•  we can express a range and depth of emotions;

•  we can express personal opinions;

•  we do not feel constrained by other people’s proclivities.

This means that we can start to communicate more effectively in our relationships—all without restricting ourselves unduly through fear of criticism, censure, or lack of confidence. This is improved self-esteem.

Being unassertive

We are usually quite unassertive (compliant, conforming, submissive, obedient, reserved, repressed, or quiet) because we have learnt or been forced to be so. Young babies are naturally self-assertive; their survival depends on it. These babies—and you were one once—tell those around them exactly what they need. But, as children, those around us also gradually shape our behaviour through the messages they give us, and the general level of encouragement (or lack of it), as well as by more overtly repressive or deprived circumstances. Lack of self-assertion can become chronic. In the long-term, being unassertive depletes our self-esteem, and the more we become unassertive, the more we lack a sense of identity. This can result in a corresponding lack of sense of purpose, faith, good feelings about the world and ourselves, feeling in control, trust, joi

See more

Medium 9781449394011

LINQ

Slice ePub May 27, 2014

LINQ, or Language Integrated Query, allows you to write structured type-safe queries over local object collections and remote data sources.

LINQ lets you query any collection implementing IEnumerable<>, whether an array, list, XML DOM, or remote data source (such as a table in SQL Server). LINQ offers the benefits of both compile-time type checking and dynamic query composition.

A good way to experiment with LINQ is to download LINQPad. LINQPad lets you interactively query local collections and SQL databases in LINQ without any setup and is preloaded with numerous examples.

The basic units of data in LINQ are sequences and elements. A sequence is any object that implements the generic IEnumerable interface, and an element is each item in the sequence. In the following example, names is a sequence, and Tom, Dick, and Harry are elements:

A sequence such as this we call a local sequence because it represents a local collection of objects in memory.

See more

See All Slices

0 Items 0.0 Mb
Sub-total $0.00
Click
or drag to add content