What I think after I first recognized functional programming and lisp

Source: Internet
Author: User
Me. thisblog. goal = "attract some attention to functional programming and reflection on the status of Object-Oriented"; me. thisblog. style = "kan Dashan"; if (you. expectation = "view a technical blog") {return NULL;} readblog (); return you. comments; void readblog () {do you think you understand object-oriented design? ", The ghost looked at it. Article This made me very curious about functional languages. -First, in the "Object-Oriented" column of the blog Park, followed by my essay, a netizen forwarded an article on infoq, "is the object dead ?". -Second, I read the blog "hacker and painter" in the "reading area": the casual recording of venture capital investors who are born in Daniel programmers ", so I also bought this book hacker and painter. First read the second part about Programming Language Several articles, such as the programming language one hundred years later, the coveted programming language, the revenge of the nerd, and the rejection of mediocrity. -Finally, a netizen commented on my article and said, "When CMU is trashing Oop, you are starting learning it. "(when Carnegie Mellon University" throws "Oop, you start to learn it ), I also attached a infoq link to "the Computer Science Department of Carnegie Mellon University removed Oop from the introductory course of first-year freshmen and added functional language courses. The reason is that these irrelevant things eventually point to the same thing: functional programming (FP) and its relationship with object-oriented programming (Note: functional and object-oriented technologies are not at the same level, and functional interfaces correspond to the imperative type (imperative ), however, it involves a lot of object-oriented technology issues, so I have to pay attention to it ). This prompted me to understand functional languages. Among these materials, many speak The LISP Language (of course, Haskell, F #, Erlang, etc ). In fact, as early as the 1980s S, I saw a Chinese document about the lisp language, turning several pages. Now I think about it in a vague way. I felt like I couldn't understand it. I didn't have basic (I went to middle school and taught basic at that time). I didn't know how to use it, so in a later day, old books were sold. What surprised me now is why a programming language created in 1958 has such a strong vitality, today, functional programming has a tendency to replace object-oriented technology into a mainstream approach. "Why is the lisp language so advanced?" from a professional perspective, I have explained why lisp is special. There are many articles on the Internet that introduce the lisp language. You can refer to these articles to get a preliminary understanding of this language. As a layman, I first met lisp and thought the following content was quite surprising to me. -The kernel design of the language is very small. The LISP Language has only seven kinds of theorems (Basic operators ). -Write it out Code Very short. With over 30 lines of code, you can write an interpreter for the lisp dialect. It is said that the average of C code is 7 to 10 times that of Lisp code, and that is 20 times that of C code. -Why is the lisp code shorter? This is because the "bottom-up" programming method is used. Instead of developing the basic language, you build your own language on the basic language, and then use the latter for development. -If you can't imagine what the code of the lisp language is, you can try to imagine XML. Imagine that every node in XML is a function and independent variable and can be executed. (LISP code is nested and recursive. After compilation, It is a parsing tree. There is no distinction between data and code, and it is a dynamic language .) -I learned about the garbage collection mechanism when I was learning C # In. The LISP Language was introduced in. -Lisp has the highest Abstraction Level and the strongest programming capability in all languages ,. (The abstraction here refers to the abstraction of the programming language itself, not the abstraction of the program .) -The reason why lisp is not outdated is that it is not a technology, but a mathematics. Mathematics is not outdated. -Among the 23 (Object Oriented) Design Patterns in total, peternovigs found that 16 were "provided by themselves or greatly simplified" in lisp ". It really scared me. So powerful, there is no sense of life-saving object-oriented. Therefore, with only a little bit of knowledge learned, we began to look for an object-oriented living space in it. Fortunately, there are still some gains. -Object-oriented languages are closer to human natural languages. Although CMU says OOP is both anti-modular and anti-parallel, it is undeniable that OOP is natural ). If 5x2 is calculated, lisp is written as "(* 5 2)" (* equivalent to the function name, and 5 and 2 are independent variables ). In addition, can you see what the lisp code is like?
(Defun Assoc (x, y)
(Cond (eq (caar y) X) (cadar y ))
('T (assoc X (CDR y )))))
There may be a bit of debate here. Who did the code write? Is it written to the machine to "view? Or is it written to people? I think it is written to people, so I pay more attention to the natural nature of language. -The object-oriented technology also features high reusability and scalability. Even the list Master Paul Graham had to admit this. Therefore, if you need sustainable development, object-oriented technology may be the right option. -The above two items may be one-sided. Because I am looking at a language that I am good at and that I have been using for a long time that I don't know, and there are major differences, my mindset may mislead me. Let's take a look at it with the arguments of the functional language masters and experts. Object dead? Clos (Common LISP Object System, a system embedded in LISP written in LISP) is mentioned in this Article. According to Paul Graham's book on lisp: "The arrival of Clos seems to mean that lisp is changing itself to embrace object-oriented programming. Instead, it is better to change it to: lisp is still sticking to the rules and embracing Object-Oriented Programming in the old way. This is more accurate. "No matter what he says, we can see that functional programming can coexist with object-oriented programming. Define a circle class in Clos, which may be like this:
 
(Defclass circle ()
(Radius: accessor circle-radius: initarg: radius)
(Center: accessor circle-center: initarg: Center )))
The object instance may be created as follows:
 
(Circle-radius (make-instance 'circle
: Radius 2
: Center' (0. 0 )))
The above code is equivalent:
   Public     Class  Circle
{
Public Circle ( Float Radius, pointf Center)
{
_ Radium = Radius;
_ Center = Center;
}

Public Float _ Radius;
Public Pointf _ center;
}

Class Program
{
Static Void Main ( String [] ARGs)
{
Circle = New Circle ( 2 , New Pointf ( 0 , 0 ));
Console. writeline (circle. _ radius );
}
}
Therefore, object-oriented has its vitality. Maybe it will evolve and may be integrated with the function, but it will not die out in 100 (in 100, this is because of Paul Graham's article "programming language one hundred years later ). However, even so, people who like object-oriented technology should not stick to their own rules, but should jump out of the object-oriented programming circle to understand and access functional programming. P.s. I am familiar with lisp and FP. please correct me if there are any mistakes in the above content. Thank you !}

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.