Apply Functional Programming Principles

Source: Internet
Author: User

Apply Functional Programming Principles

Edward Garson

Functional programming have recently enjoyed renewed interest from the mainstream programming community. Part of the reason was because emergent properties of the functional paradigm are well positioned to address the Chal-leng Es posed by our industry ' s shift toward multicore. However, while that's certainly an important application, it's not a reason this piece admonishes you to know thy func tional programming.
Mastery of the functional programming paradigm can greatly improve the quality of the code you write in other contexts. If you deeply understand and apply the functional paradigm, your designs would exhibit a much higher degree of referential Transparency.
Referential transparency is a very desirable property:it implies that functions consistently yield the same results given The same input, irrespective of where and when they is invoked. That's, function evaluation depends less-ideally, not at all-on the side effects of mutable state.
A leading cause of defects in imperative code are attributable to mutable vari-ables. Everyone Reading this'll has investigated why some value was not as expected in a particular situation. Visibility semantics can help-mitigate these insidious defects, or at least-drastically narrow-their location, But their true culprit is in fact being the providence of designs that employ inordinate mutability.
And we certainly don ' t get much help from the industry in this regard. Intro-ductions to object orientation tacitly promote such design, because they often show examples composed of graphs of Relatively long-lived objects that happily call mutator methods on one another, which can be dangerous.
?? 4 things every Programmer should Know
?
??????????????? However, with astute test-driven design, particularly if being sure to "Mock Roles, not Objects," * Unnecessary mutabilit Y can be designed away.
The net result is a design that typically have better responsibility allocation with more numerous, smaller functions that Act on arguments passed to them, rather than referencing mutable member variables. There'll be fewer defects, and furthermore they would often be simpler to debug, because it's easier to locate where a R Ogue value is introduced in these designs than to otherwise deduce the particular context this results in an erroneous Ignment. This adds-a much higher degree of referential transparency, and positively nothing would get these ideas as deeply in To your bones as learning a functional programming language, where this model of computation is the norm.
Of course, this approach are not optimal in all situations. For example, in object-oriented systems, this style often yields better results with domain model development (i.e., wher E collaborations serve to break off the complexity of business rules) than with user-interface development.
Master the functional programming paradigm so is able to judiciously apply the lessons learned to other domains. Your Object Systems (for one) would resonate with referential transparency goodness and being much closer to their functional Counterparts than many would has you believe. In fact, some would even assert this, at their apex, functional programming and object orientation is merely a reflection of each of the other, a form of computational yin and yang.

Apply Functional Programming Principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.