Do not stay with a programming language for life: make the right choice for your work

Source: Internet
Author: User
One of the key decisions that programmers need to make when starting a project is to select a language or a group of languages for implementing the system. This decision will not only affect the implementation of the system, but also affect the design. when a programmer starts a project, one of the key decisions that need to be made is to select a language or a group of languages, used to implement the system. This decision will not only affect the implementation of the system, but also affect the design. For example, should we use an object-oriented language or a procedural language? Language selection has a profound impact on the project and the life cycle of the program as part of the project. many times, we choose language selection without thinking too much based on some very variable factors: I used this language to implement this type of system. I have the most thorough understanding of this language; this is my favorite language, and I enjoy programming in this language; and so on.

Since this decision will lead to profound and long-term results, should we be more pragmatic when making this decision? Most of the time, we are blindly biased towards the language we choose. In addition, sometimes the reason why we do not like to choose this language is probably the reason why we choose that language.

If we can open our minds and treat our own prejudices honestly, we can alleviate the pain of sticking a square pin to a circular hole during decoration. Although there is no secret to choosing the perfect language for the project, we can still follow some principles to help us make a better and more appropriate language choice.

No perfect language

This is expected for anyone or even new users, and many of us are willing to admit that "Of course this language is not a perfect language," but at the same time, many of us will still say, "This language is the best programming language ". The key to speaking a language is the Project Background. that is to say, the best language only exists within a certain range. This is our first principle:

No perfect language: each language has its advantages and disadvantages.

For example, many developers who usually use runtime languages, such as Java or Python, claim that C or C ++ is not very irritating because they focus on low-level details such as memory management, or focus on the strict granularity of type checks during compilation, and eliminate the responsibility of developers. This is a fact, as long as the project we are developing does not focus on seemingly trivial tasks, such as memory management or the number of copy-assignment that occurs in a single loop.

On the contrary, if we work in a project or a part of a project, it is natural that we have a biased need for code efficiency and critical program security, these seemingly tedious details may be the level of granularity we are looking. In this new context, the runtime nature of Java or Python seems to be too indifferent or too absent-minded. Instead, we want to strictly control the number of moves-assignment and copy-assignment executed when memory is allocated and released, and capture as many errors as possible during compilation, instead of letting errors penetrate into the runtime (as an exception during runtime ).

Although theoretically "no perfect language" sounds obvious, our actions as developers usually deviate from this concept: we say that we know that our favorite language is imperfect, but we continue to use this language for our development projects, whether or not it is suitable. In addition, when other developers question the language of our choice, we will firmly defend our choice, rather than seeing the truth from his or her rediss. Remember: Each language has its advantages and disadvantages. Understand the advantages and disadvantages of the language you have mastered, and then make choices based on the actual situation.

The reason you don't like a language is probably because you should use it.

This seems to be contrary to intuition, but sometimes the reason we dislike a language is probably the reason for using a language. In the above example, in my experience as a C ++ developer, many times there are so many different concepts that need to be tracked (memory management and object life time, C ++ programming, etc.), so that the completion of a simple function of the project will become cumbersome. After a few weeks of development with C ++, using Python, Java, or another "more advanced" language is just like a gift from heaven: But is it true?

Sometimes, we may not like a language because we need to use it. If I am developing a driver or some key security, real-time systems, the tedious reason described above may be the biggest advantage of this language. For example, C ++ provides a mechanism to express the logic that is executed when an object is copied, which is very valuable in terms of efficiency and rigor.

This may seem very good, so it is difficult for us to point out that in a certain context, a language that you cannot see is more helpful. So how do we know which languages you don't like are helpful? This leads to our second principle:

Be honest with yourself: Know why you don't like a language, and don't teach yourself how to hate yourself.

For example, in the above C ++ example, I do not like C ++ programming for a long time because the language requires rigorous thinking, otherwise it is easy to make mistakes, it is like being trapped in the Jungle (focusing too much on trees, not the entire forest ). Such rigor will prevent developers from questioning, for example, "Do I want to create objects on the stack or stack, or partially on the stack and the other on the stack ?" Or "should the class be extensible through template parameters or inheritance ?" . In other languages, developers only need to create an object and use object-oriented inheritance to complete these tasks, and then enter the next function, because the language (or, more accurately, compiler or interpreter) follow these details.

However, if I am honest with myself, I will admit that I do not like these functions because it will blame me for expressing these details. In other languages, not only do I not have to take responsibility for these details, but I am not responsible for expressing these details: they are abstracted away from developers. In a context where these details are essential, I do not like C ++ because I should use this language.

Does this mean that we should use the features that make us angry with the language with a frown? It is not necessary. Maybe you can change the angle: do not treat these functions as disadvantages. maybe we should embrace them as a necessity to complete the task. We should not say "this is a tragedy," but say, "Thank God, I can do this in this language ." Remember: In some cases, these functions will be a gift, and in other cases, they are cumbersome. Tell yourself honestly why you do not like the functions of a language.

The more familiar you are with other languages, the better.

This is our third principle:

If the only tool you have is a hammer, you can see that every problem is like a nail.

This rule does not apply to software engineering, but it sharply shows many software development situations. Most of the time, we choose a language or a language-supported tool (such as Java JMS, Python ASYNCIO, Rails Ruby, etc.) because we know that they exist. If the only language we are familiar with is Java, we will adapt all the problems we encounter to the context of Java. For example, "I need to create a routing framework for a communication application. What should I do in Java ?" This restricts the tools available for us and artificially limits the room for us to choose the right tools for our work.

The solution to this problem is to broaden your horizons and understand the functions and complexities of other languages. As Andrew Hunt and David Thomas suggested in The Pragmatic Programmer, a good practice is to learn a new language every year. This is not as easy as it sounds. learning a language means different things for different people. Another derivative problem is that we often only use this language for ongoing projects, making learning another language useless. For example, if I am an Android developer who only uses Java every day, learning C # may seem out of date.

Do not be blinded by the illusion. The advantage of learning other languages is that we can look at the problem from different perspectives and use the most suitable tool for this problem. To do this, we must learn warnings from other languages and how developers use these languages to solve problems. For example, if a developer wants to use C ++ to execute metaprogramming, he or she can use the Template Metaprogrammming (TMP) in C ++ ), but he or she can also use reflection in Java. Understanding how other languages solve similar problems can reduce the risks that we think are useless.

For another example, if we need to be able to change the runtime characteristics of a class, a C ++ developer who is deeply familiar with the complexity of C ++, may try to create a solution that extends the language boundaries during compilation. Another C ++ developer, who has some knowledge of Java, can say, "I like C ++, but Java runtime reflection is more suitable for solving this problem."

Given that there are so many programming languages that developers choose, it is important to prioritize the language they want to learn. Start with The most popular languages today (refer to most popular programming ages on Github, Language Trends on Github, and The 9 most popular computer programming ages). according to the Facebook for programmers ).

Language is a means rather than a purpose

This is Article 4 and the last principle. it sounds the most philosophical, but it can be said that it is the most important:

Programming language is a means rather than a purpose.

Unless you are the author of a language standard or a compiler, you should regard the programming language as a means rather than an aim to complete the project: the ultimate goal is to complete the project, rather than using a specific language. This does not mean that every developer has no right to ask him or her for a preferred language (in fact, if we are honest with ourselves, these likes and dislikes will benefit us; see the second principle above), but we should not make such a decision by deceiving ourselves. for example, "This is a good opportunity for me to use this language function ", unless the features in this language are truly suitable for the project's needs.

It is important to remember that language is just a way to express how to solve the problem at hand: Make sure you have chosen the language that best expresses the problem-solving domain.

Other considerations

Here are some additional considerations when selecting a language:

Consider how a language interacts with other languages. For example, if you think Python is the best language to complete most projects, but there is a well-defined component in your project, requires a very high level of granularity or efficiency (more suitable for C or C ++), which does not mean that you cannot use Python on this project. Instead, consider using Python, a specific component is written in C or C ++, and then the Python c api is used to interface this component. Note that to develop such a solution, we need to know that Python has a c api. Therefore, it is helpful to understand these features in the most popular languages.

Middleware supports multiple languages. For example, if there are two applications that must communicate, such as mobile devices and a server application, but that doesn't mean they must use the same language (or, of course, the same, if you think this is the best decision ). If this mobile device is an Android mobile phone, and the server application is very suitable as a Python application, use a message proxy, such as RabbitMQ, this allows you to use both languages for communication: Android applications can use Java RabbitMQ APIs, while server applications can use Python RabbitMQ APIs.

Embrace the strangeness of other languages. If you are a Java developer, you will use packages to separate the logical units of the source code. if you are a Python developer, you will use the Python package structure to do the same thing; if you are a C ++ developer, you will use the namespace or prefix class name ("DZone_MyClassName "). Learn about the special features of the language you are using and embrace it: in Rome, it is just as common. Otherwise, it looks as if you prefer to pronounce words in Italian and speak German with an Italian accent. Of course, a function in a language may also exist for a long time, but in this case, there must be a reason: Make sure you understand the truth.

Do Not Marry a Language: Selecting the Correct Language for the Job

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.