What are the advantages, disadvantages and differences of weakly typed languages than strongly typed languages? Can you illustrate it in two languages, such as PHP and C #?

Source: Internet
Author: User

Reply content:

Before you write JavaScript, listen to people say that you don't have to ignore the variable type, just use it. Then various into the pits.
Clearly is the distinction of good, but only the language is not obvious, plus some less intelligent type automatic conversion.
Weakly typed languages are really good for getting started, but you can't ignore variable types if you want to be proficient.
In addition, if the problem can be solved outside the runtime, why should I bring it in. How much JavaScript has been written recently has been appreciated. I knew the weak type language is very easy to write Xiang, so I sacrificed a little performance everywhere assert, load a page assert more than 2000 times, prove the effect is very good. However, the browser does not look like Visual Studio, and in any case it is very straightforward to tell me which assert is in the end. More abominable is, like c++/c# such language, exception is caught when the time is to keep the debug information of the throw, JavaScript directly first unwind stack and then catch, but also have to hard to expand the content of the Error object , human flesh see stack information, jump over, but at the moment local variables are long lost ...

Special Miss Write / http ASP , you can use Visual Studio to debug the days of the code in your browser.

PHP estimates are similar. Weak type is not rigorous, in the case of strict type requirements need to pay attention to abnormal conditions: such as receiving parameters need to be judged int, but all the PHP received can be used as a string, to their own use of intval and other functions of conversion; sometimes the judgment needs "= = =" To ensure that no problem. C # is not to worry about these, type mismatch in writing code when the error.

A good example of the advantages of weak types is that the operation json,php with Json_decode function becomes an array, the array in PHP is a universal structure, how to use it. C # Solution JSON is a bit more complex, each value to be converted to the corresponding type, that is to say you have to understand before parsing what structure, each value is what type. I guess the main thing the Lord wants to ask is that dynamic type languages and static type languages are in "rigorous" languages, usually pre-defined types of good one values, and the types of variables are fixed throughout.

The disadvantages of a weak type are as follows in contrast to strong types:
(1) A weak type does not conform to "WYSIWYG", and the defined variable type is unpredictable and can be changed.
(2) In order to be compatible with the weak type, the language execution engine has to do a lot of compatibility work, including type recognition, memory management, type conversion, and so on, which increases the complexity of the internal processing of the language, which leads to the decrease of execution efficiency.
(3) The type of variable is not controllable, so the execution process has a large number of variable type "invisible conversion", in the development of students do not know the implicit conversion rules, it is easy to produce unpredictable results. This feature is also completely incompatible with the simplicity of WYSIWYG.

However, they can develop, stand out, there are reasons, there is a reason for it.
Weak type and other language features, reducing the programmer to write the language of the threshold. Programming language is a bridge between human and machine communication, the ultimate pursuit is actually "reduce the communication cost of human and machine", The pursuit of "everyone can be programmed" realm.
For example, starting with the machine language 0 and 1, later became assembly language, assembly language developed C, and then there is now the scripting language. The threshold for programming learning is declining and the number of programmers is increasing exponentially.
Moreover, I believe that the future will continue to develop the language of the lower learning threshold, to promote the number of programmers again exponential growth.

Weak-type languages also have advantages:
(1) The complexity of the language and the error prone areas, such as: memory management, pointers, types of variables, and so on. Although it masks more complex features, it does not mean that they do not exist, that it is friendly to people (programming is simpler, less is being considered), but not friendly to machines.
(2) The project development efficiency is high.
(3) Low learning threshold.
Although it has a lot of problems, but also contains a very obvious advantage.
PHP is used in a wide range of web development, JavaScript domination browser-side development, these are not accidental, but people voted by foot.

Of course, the operation of the industry has specialized in different languages to solve the problem of different situations, can not generalize. Like Fastcsharp. , whether it is development efficiency or operational efficiency, always welcome you phper challenge.
Weakly typed languages have two advantages: one is eval, but I really don't know if this is an advantage; the second is the case where there is a weak type requirement, the code is more elegant relative to the strongly typed language (fewer keystrokes on a line).
Weak type of language disadvantage too much, it can be said to be covered, but many people are reluctant to admit it. The most important benefit of the weak type is the convenience of other linguistic features. such as closures and callback functions. PHP I do not understand, but JavaScript relies heavily on callback functions and derived error first callback pattern and other things, in the strongly typed language will not be implemented. Of course, there are other non-weak types of implementations, such as Ruby will use argument as hash and other means to avoid the problem of inconsistent function signature.

Before many people mentioned that the ideal language should have optional static typing. In fact put on strong/weak typing or the same, the most ideal is optional weak typing. I just think that unless it is necessary, it is not a compile-time check type, so the dynamic typing should be the default, explicitly declaring the static typing. The strong and weak side should be the default strongly typed, explicitly declaring weak types (that is, explicitly representing content convertible).

But at the moment there seems to be no one to complete such a language, XD, the existing make up the use of it. The advantage of PHP is that
PHP is the best language
Well, I say it again equals I have a responsibility.

PHP is a weak type of language, what is prone to problems? Give me a chestnut.

   /*Strpos (String, find)returns the position of the first occurrence of a string in another string, or FALSE if no string is found. */$string = ' Zhihu ';$find = ' h ';if (Strpos($string, $find) == false)Echo ' not found ';if (!Strpos($string, $find))Echo ' not found ';$find = ' Z ';if (Strpos($string, $find) == false)Echo ' not found ';if (!Strpos($string, $find))Echo ' not found ';?>
  • Related Article

    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.