Home > Backend Development > PHP Problem > Have you learned PHP before learning Java or Python?

Have you learned PHP before learning Java or Python?

王林
Release: 2023-02-23 19:20:02
Original
4079 people have browsed it

Have you learned PHP before learning Java or Python?

Before considering whether to learn java or python, let’s talk about the application fields of the two.

Main application directions of Python:

1. Scientific computing

With NumPy, SciPy, Matplotlib, Enthoughtlibrarys, etc. With the development of many program libraries, Python is increasingly suitable for doing scientific calculations and drawing high-quality 2D and 3D images. Compared with Matlab, the most popular commercial software in the field of scientific computing, Python is a general programming language. It has a wider range of applications than the scripting language used by Matlab and is supported by more program libraries. Although many advanced functions and toolbox in Matlab are still irreplaceable, there are still many tasks in daily scientific research and development that can be done with Python.

2. Web crawler

, also known as web spider, is the core tool for obtaining data in the big data industry. Without web crawlers automatically, day and night, and highly intelligent crawling of free data on the Internet, there would probably be three-quarters fewer companies related to big data. There are many programming languages ​​that can be used to write web crawlers, but Python is definitely one of the mainstream, and its Scripy crawler framework is widely used.

3. Data analysis

Based on a large amount of data, combined with scientific computing, machine learning and other technologies, the data is cleaned, deduplicated, standardized and targeted. Pertinent analysis is the cornerstone of the big data industry. Python is one of the mainstream languages ​​for data analysis.

4. Artificial Intelligence

Python is a mainstream programming language in machine learning, neural networks, deep learning, etc. in the large field of artificial intelligence, and has been widely used. support and applications.

The main application direction of Java:

1. Enterprise-level application

This is currently the most widely used Java application In the field, it is almost unique. Including various industry applications, enterprise informatization, and e-government, etc., the fields include: office automation OA, customer relationship management CRM, human resources HR, enterprise resource planning ERP, knowledge management KM, supply chain management SCM, enterprise equipment management system EAM, product life cycle management PLM, service-oriented architecture SOA, business intelligence BI, project management PM, marketing management, process management WorkFlow, financial management... and almost all applications you can think of.

2. Embedded devices and consumer electronics products

Including wireless handheld devices, smart cards, communication terminals, medical equipment, information appliances (such as digital TVs, set-top boxes, Refrigerators), automotive electronic equipment, etc. are all popular Java application fields in recent years, especially Java applications and Java games on mobile phones, which are even more popular.

Next, let’s briefly compare python and java:

Static language and dynamic language:

Static language:
java, c, c, go, etc.
Strongly typed language (statically typed language) refers to a language that requires variable/object type declaration, and generally requires compilation and execution. A strongly typed language is a language in which once the type of a variable is determined, it cannot be converted.

Dynamic language:
python, javascript, php, ruby, etc.
Weakly typed language (dynamically typed language) refers to a language that does not require variable/object type declaration. Generally, compilation is not required (but there are also compiled versions). Dynamically typed languages ​​are languages ​​in which data types are determined at runtime. There is no need for a type declaration before a variable is used. Usually the type of the variable is the type of the value to which it is assigned.
On the contrary, in weakly typed languages, the type of a variable is determined by its application context.

Advantages of static language:

Due to the mandatory declaration of types, the IDE has strong code awareness. Therefore, when implementing complex business logic, In the development of large-scale commercial systems and applications with long life cycles, relying on IDEs can ensure system development;
Because static languages ​​are relatively closed, the intrusion of third-party development kits on code can be minimized;

Advantages of dynamic language:

Some advanced concepts in static languages, such as reflection in java and AOP based on reflection, these concepts are useful for java beginners and For people with only one or two years of work experience, it is difficult to understand these concepts, let alone how to implement them themselves. If you have used AOP, you will understand that it is difficult to understand and use these concepts proficiently, and the development efficiency will be relatively low. Although students may say "it is actually very simple to use", that may be because you I have never used decorators in dynamic languages.

In dynamic languages, the concept of AOP in Java can be completed directly using decorators and is part of the python language itself. It is not like java that requires the introduction of a third party to complete.

Python can accomplish this easily precisely because Python is a dynamic language. The characteristics of dynamic languages ​​make it extremely simple for everyone to control the initialization of the entire class and dynamically change objects. These characteristics make it extremely easy for dynamic languages ​​to Flexibility far exceeds static languages.

Interpreted and compiled languages

The interpretation execution here is relative to the compilation execution. We all know that programs written in compiled languages ​​such as C/C need to be converted from source files into machine language used by the computer, and then linked by the linker to form a binary executable file. When you run this program, you can load the binary program from the hard disk into memory and run it.

The execution process of python is similar to Java:
The python interpreter converts the source code into bytecode, and then the python interpreter executes these bytecodes.

A specific python program execution process:

- After executing the python program, the Python interpreter will be started, and then the python program will be compiled into a bytecode objectPyCodeObject.

- During runtime, the compilation result, which is the PyCodeObject object, will only exist in memory. When the Python code of this module is executed, the compilation result will be saved to the pyc file, so that next time There is no need to compile, it is loaded directly into memory. A pyc file is just a representation of a PyCodeObject object on disk.

- This PyCodeObject object contains strings, constant values ​​​​in the Python source code, and bytecode instructions compiled and generated through syntax parsing. The PyCodeObject object also stores the correspondence between these bytecode instructions and the original code line number, so that when an exception occurs, it can indicate which line of code is located.

Java is also compiled into bytecode first, and then executed in the
interpreter. Java is very special. Java needs to be compiled, but it is not directly compiled into machine language, but compiled into bytecode. The bytecode is then executed in an interpreted manner on the Java virtual machine. Python also uses a similar approach. Python is first compiled into python bytecode, and then a specialized python bytecode interpreter is responsible for interpreting and executing the bytecode.

GIL in Python

The full name of GIL is Global Interpreter Lock (global interpreter lock). The source is the consideration at the beginning of python design, and it is done for data security. Decide.

Under Python multi-threading, the execution method of each thread:
1. Obtain GIL
2. Execute the code until sleep or the python virtual machine suspends it.
3. Release the GIL

It can be seen that if a thread wants to execute, it must first get the GIL. We can regard the GIL as a "pass", and in a python process, there is only one GIL. Threads that cannot obtain a pass are not allowed to enter the CPU for execution.
Every time the GIL lock is released, threads compete for locks and switch threads, which consumes resources. And because of the GIL lock, a process in Python can only execute one thread at the same time (the thread that has obtained the GIL can execute). This is why Python's multi-threading efficiency is not high on multi-core CPUs.
Each process has its own independent GIL and does not interfere with each other, so that it can be executed in parallel in a true sense. Therefore, in python, the execution efficiency of multi-process is better than that of multi-threading (only for multi-core CPUs).

Due to the existence of GIL, Python's multi-threaded performance is very low and cannot take advantage of multi-core CPUs, and its performance is even worse than single-threaded. So if you want to use multi-core CPU, one suggestion is to use multi-process or coroutine.

Python Garbage Collection

When talking about garbage collection, the reference counting model is usually used. This is the most intuitive and simple garbage collection technology. . Python also uses reference counting, but reference counting has these shortcomings:

1. Frequently updating the reference count will reduce operating efficiency

2. Reference counting cannot solve the problem of circular references

Python uses two mainstream garbage collection technologies: mark-clearance and generational collection based on the reference counting mechanism.

The above content is for reference only!

Recommended Python video tutorial: python video tutorial

Recommended Java video tutorial: JAVA video tutorial

The above is the detailed content of Have you learned PHP before learning Java or Python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template