[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Стабильная система?



Хосспади, OCaml... o.O
Может, когда требуется "большой кусок в императивном стиле",
следует отказаться от использования функционального языка в сторону императивного?
Или религия не позволяет? ;-)

On 15.10.2015 21:02, Dmitrii Kashin wrote:

1) Позволяет более просто комбинировать функциональное и императивное
программирование: не надо изворачиваться монадами, чтобы добиться
последовательного выполнения команд.

Но зачем?

"This is no matter of religion or esthetics; a priori neither style is
prettier or holier than the other. On the contrary, one style may be
more adequate than the other depending on the problem to be solved.

The first rule to apply is the rule of simplicity. Whether the algorithm
to use implemented is written in a book, or whether its seed is in the
mind of the programmer, the algorithm is itself described in a certain
style. It is natural to use the same style when implementing it.

The second criterion of choice is the efficiency of the program. One may
say that an imperative program (if well written) is more efficient that
its functional analogue, but in very many cases the difference is not
enough to justify complicating the code to adopt an imperative style
where the functional style would be natural". [1]

Бывает, что императивное программирование разумнее. Большинство
алгоритмов можно писать в функциональном стиле, но бывает и так, что это
порождает большой оверхед в производительности. При столкновении с
подобным "узким горлом" приходится реализовывать часть функционала в
императивном стиле. Например, управление большими словарями много
выгоднее, если они мутабельны.

[1] http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora038.html



Reply to: