Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

met_angl_yaz / Lesson 8

.doc
Скачиваний:
2
Добавлен:
10.02.2016
Размер:
36.86 Кб
Скачать

Lesson 8

THE READING MODULE

Read the text: Multi-paradigm programming.

Multi-paradigm programming

There is a special case of the idea that “When there is more than one way to do it, each way should be used differently.” Some languages, such as Ruby, are deliberately multi-paradigm: not only are there several ways to do things, there are several entirely different philosophies the language supports. In Ruby’s case, for example, you find the usual assortment of imperative structured programming suspects like for, while, and until. But you also find some of the more obvious functional programming suspects, like lambdas as first-class values and Enumerable’s collection methods :map, :select, and :detect.

I think the idea that doing the same thing in different ways signals different intents scales up to the paradigms you use. If you have a list of phone numbers (say for people you'd like to call), and you wish to remove certain numbers from it (say a do-not-call list), in Ruby I think you should always use some kind of functional approach like combining :reject and :include or :detect. If you write this out using for loops or :each, it signals that there are side effects going on.

By making functional things look functional, you clearly signal that you are performing a calculation strictly for the result. Using imperative syntax like for and while should be reserved for the times you need to mutate variables or cause other side effects. Naturally, you may need to break this so-called rule from time to time for performance purposes. But you’re an adult, you know that just because a rule needs to be broken here and there for pragmatic reasons doesn’t mean you toss it out and write all of your code using whatever keyword is laying about at the time.

Likewise, OO is a great paradigm—when you are modelling entities in the real world or when you need long-term persistent state. Languages like Ruby force you to use objects behind the scenes, but you code shouldn’t look OO unless you are trying to signal your colleagues that there are entities involved. For this reason, you should use Proc.new when you want objects and lambda when you want functions.

The benefits of traveling far while you build a life at home

People sometimes ask why they should bother to learn other languages or other programming styles, when they do not have an opportunity to use those languages at their 9-5. I believe that if you embrace the idea of multi-paradigm programming, these other languages can teach you useful techniques such as using :unfold to model iteration over data structures.

Of course, people will ask why you are using a Haskell idiom in Ruby, or a Lisp idiom in Java. One of the answers is that it may be more expressive. Another answer could be that by making functional things look functional, by making OO things look OO, by making distributed things look distributed, and so on, by borrowing paradigms from languages where those ideas are fully exploited, you can make your Ruby and Java code signal its intent more clearly.

Pair Programming

All production software in XP is built by two programmers, sitting side by side, at the same machine. This practice ensures that all production code is reviewed by at least one other programmer, and results in better design, better testing, and better code.

It may seem inefficient to have two programmers doing "one programmer's job", but the reverse is true. Research into pair programming shows that pairing produces better code in about the same time as programmers working singly. That's right: two heads really are better than one!

Some programmers object to pair programming without ever trying it. It does take some practice to do well, and you need to do it well for a few weeks to see the results. Ninety percent of programmers who learn pair programming prefer it, so we highly recommend it to all teams.

I. Reading Exercises:

Exercise 1. Read and memorize using a dictionary:

Deliberately multi-paradigm, assortment, suspects, lambdas, to remove, approach, imperative syntax, to mutate, long-term persistent state, embrace, the reverse.

Exercise 2. Answer the questions:

1. Are some languages deliberately multi-paradigm?

2. What languages force you to use objects behind the scenes?

3. How do you think why people should bother to learn other languages or programming styles?

4.Is it right: two heads really are better than one?

Exercise 3. Match the left part with right:

1. Of course, people will ask why you

a) programming without ever trying it.

2. Some programmers object to pair

b) are using a Haskell idiom in Ruby, or a Lisp idiom in Java.

3. I believe that these other languages

c) each, it signals that there are side effects going on.

4. If you write this out using for loops or:

d) can teach you useful techniques such as using.

Exercise 4. Open brackets choosing the right words:

Some programmers object (to pair/to compose) programming without ever trying it. It (does/makes) take some practice to do well, and you (need/not to need) to do it.

THE SPEAKING MODULE

II. Speaking Exercises:

Exercise 1. Ask questions to the given answers:

1)Question: _______________________________________________________?

Answer: One of the answers is that it may be more expressive.

2)Question: _______________________________________________________?

Answer: For this reason, you should use Proc.new, when you want objects and lambda when you want functions.

3)Question: _______________________________________________________?

Answer: Some languages are deliberately multi-paradigm: not only are there several ways to do things.

4)Question: _______________________________________________________?

Answer: Naturally, you may need to break this so-called rule from time to time for performance purposes.

Exercise 2. Explain how you understand the phrase: “When there is more than one way to do it, each way should be used differently”.

THE WRITING MODULE

III. Writing exercises:

Exercise 1. Complete the sentences with the suggested words other(2), why, when, those.

People sometimes ask ______ they should bother to learn ______ languages or ______ programming styles,______ they do not have an opportunity to use______ languages at their 9-5.

Exercise 2. Make up a plan of this text.

Exercise 3. Write a story about role of the languages in the programming (up to 100 words).

Соседние файлы в папке met_angl_yaz