Mental Burden of Programming Language

  golang, php, Programming language, swoole

Many articles comparing programming languages always like to compare the performance, syntax and IO models of various programming languages. This article will compare different programming languages and technologies from the perspective of mental burden. Because I am good at programming language is limited, if there is anything wrong, please correct me.

Memory out of bounds

For example: c language, C++(C with class)
C/C++Can directly operate the memory, but programming must face memory out of bounds. After memory violation occurs, the program will directlycore dump, developers need to usegdbThe tool analyzes the cause of memory errors. If memory out-of-bounds is accidental, for example, due to data synchronization problems, it will occur once in hundreds of millions of times, which is very difficult to solve and even requires top experts to find the cause of the problem.

Mental Burden: 10

ModernC++ProvidedSTLThe library contains a large number of containers, and in additionC++Support reference syntax, no longer need to directly operate pointer, reduce the risk of memory error reading and writing. Use modernC++The programming style of can avoid this problem. But becauseC++The pointer has not been completely removed from the grammar level, which is not thorough enough.

Macro

C/C++Predefined macros are often used in programs to implement some logic, resulting in poor readability. In some cases, macros will be nested multiple times and become extremely difficult to read when expanded.Mental Burden: 6

So inC/C++Recommended inenumOrstatic inlineFunction instead of macro.

memory management

For example: C language, C++

C/C++Language requires manual memory management.malloc/newThe memory requested should be the same asfree/deleteUse in pairs. If the requested memory is forgotten to be released, a memory leak will occur.Mental Burden: 8

Java/PHP/GoWaitGCThe programming language, does not need to manually manage memory, will not cause memory leaks due to code errors.Mental burden: 0

Numeric type

C/C++/GOSuch as programming languages, provide signed, unsigned integer and floating-point types,8/16/32/64Integers of different sizes. Additional processing is required during programming to avoid numerical overflow.Mental Burden: 6

PHP/JavaSuch as programming languages, the default integer is signedint64, reduce the mental burden. It is difficult to exceed in general business items2^63The number of, will not encounter problems. But if you do scientific calculations,int64It is difficult to meet the demand. InPHPIn excess of2^63The bottom layer will be converted to floating point type, and the calculation will lose precision.Mental burden: 1

AndPythonIntegers are unlimited in length and can be used for numerical calculation of any number of digits.Mental burden: 0

Type constraint

JavaIs a static strongly typed programming language, so there are type constraints in programming, which may not be particularly convenient in some cases. Such asJSONSerialization. Explicit type conversion may be required when different types of variables operate on each other.Mental Burden: 2

PHP/JSIs a dynamic weak type programming language, the underlying automatic implicit type conversion. Programming is more convenient.Mental burden: 0.

Project maintenance

Weak type dynamic language will bring maintainability problems in large-scale projects, code refactoring of existing systems, and code replacement of developers for projects.Java/Go/C++Such static strongly typed programming languages can find problems at compile time. However, dynamic and weak types of languages may cause runtime errors due to refactoring or other maintenance operations, increasing mental burden.Mental Burden: 5

Multithreaded programming

Java/C++/GoMulti-thread parallel programming and lock-free programming are provided, and data synchronization problem will exist in programming. thereforeCritical resources need to be locked. But the wrong lock operation will bring about deadlock and hot spot competition. Developers are required to have extremely high quality, otherwise it is difficult to be correct and perform well, which may require a lot of mind.Mental Burden: 10

Memory leak

Except ..PHP(php-fpm)Other programming languages and technologies (includingPHP + Swoole), which is a long life cycle in server-side programs. Operations on global/static variables may cause memory or resource handle leaks. Attention should be paid when programming.Mental Burden: 3

AndPHP(php-fpm)It has a short life cycle and will release all memory and handles immediately after the request is completed without worrying about leakage.Mental burden: 0

IO timeout

Synchronous blockingIOThe programming language and technology of the model meet a certain slownessIOCauses the entire process or thread to hang. In extreme cases, all processes/threads will hang, resulting in the unavailability of online services. Developers need to pay special attention to settingsIOTimeout for operations to avoid process/thread blocking due to slow requests.Mental Burden: 2

And asynchronousIOTheGo/Node.js/SwooleThere is no need to worry about this problem.Mental burden: 0

Summary

图片描述