PHP impressions of Java programmers

Source: Internet
Author: User
Tags drupal
Java Development Experience: 8 years. PHP development experience: 3 months. I want to build a website. Because I have many years of Java experience, I naturally wanted to use Strutsibatis at the beginning. Although Java Web development and configuration are cumbersome, I have accumulated many years of experience, naturally, this is not a big problem. During the preparation process, I gradually found that the website I want to do is preferably based on a mature

Java Development Experience: 8 years. PHP development experience: 3 months. I want to build a website. Because I have many years of Java experience, I naturally wanted to use Strutsibatis at the beginning. Although Java Web development configuration is cumbersome, I have accumulated many years of experience, naturally, this is not a big problem. During the preparation process, I gradually found that the website I want to do is preferably based on a mature

Java Development Experience: 8 + years.
PHP development experience: <3 months.

I want to build a website. Because I have many years of Java experience, I naturally wanted to use Struts + ibatis at the beginning. Although Java Web development configuration is cumbersome, I have accumulated many years of experience, naturally, this is not a big problem.

During the preparation process, I gradually found that the website I Want To Do should be customized based on a mature CMS or WIKI system. Otherwise, it would be too heavy to start from scratch. However, after comparison and selection, I found that in this open-source field, the Java camp lost to the PHP camp without any resistance.

It's so painful. I want to select PHP, Drupal or Joomla, but I am worried that it will take too long to get PHP from the beginning, so I hope it can be used in a mix, that is, the front-end display, PHP is customized on Drupal, and backend business logic is emphasized. Java is used for development. The two are interconnected using Web Services.

However, there is also a problem with this mix and match style, that is, the high development complexity, from environment setup to testing, is troublesome, and Java consumes resources and has high requirements on Virtual Hosts. Therefore, in the end, I gave up the idea of using Jaa on this project (at least temporarily) and switched completely to PHP.

Some insights are summarized as follows:

Complexity: PHP wins
I used Java for 2-3 years of Swing development and turned to WEB. The first framework I came into contact with was Struts. At that time, I felt that there were too many configuration items, after more than three months of experience, I feel better.

Now, PHP has learned about three months in total (and only in their spare time) from the beginning. One week of time is reading the documents on the PHP official website to learn about the main language features, basically, the code is changed while reading and writing. Although the understanding of software development in those years cannot be compared with today's, objectively speaking, PHP is indeed simple, easy to learn, and especially suitable for WEB development.

Development Experience: Each winner
What upset me most about PHP:
Often, when an error occurs, the Screen is blank (White Screen Of Death, all Of which have exclusive terms. It can be seen that this is a major feature Of PHP error performance) and there is no information.
The auto complete capability of the development tool is far inferior to that of java.

Something nice about PHP:
In php, arrays are equivalent to hash tables and are the most widely used data structures. Variable Length parameters + arrays are used as parameters, which greatly improves the flexibility of code writing.
Basically, you don't have to worry about NPE.
Accessing the database is much simpler than JDBC, and DAO-like code can be quickly written without any persistence framework.
Many features designed specifically for the WEB make it lightweight to retrieve information from or output information to pages.

Not nice or uncomfortable:
The echo content is directly sent to the front-end page. At first, I thought echo is the same as java's System. out and will be written to the log.
Unlike Java, which imposes strict requirements on classpath and class paths, I am not used to it at the moment. It is basically impossible to consider where to create a Java class, however, it is often necessary to determine the directory in which a file should be stored.
Because it can be OOP or not OOP, when adding new functions, it is often hard to understand O or O.
Code style! I am so used to the naming of getData. It is not applicable to functions such as get_data. Therefore, I am persistent and can see it at a glance, which belong to the framework and mine.

Platform comparison
If I compare PHP with JAVA, I think PHP is Swiss Army knife, while JAVA is N sets of home hardware repair tools, N> = 100. in solving the problem of website development, PHP is indeed small and easy to use, but it is also unsatisfactory.

For example, I found that JDBC connection pools, which are almost essential in J2EE, are approximately none in PHP. Therefore, if a user requests to access the database, they are all connected, retrieved, and disabled, the reason is that the architecture is different.

In fact, J2EE has the concept of Web iner. User requests are completed by the thread allocated by the Container. The thread can use the memory space of the process to exchange data, while PHP depends on Apache, every user request, Apache starts a new process to execute the PHP script. After the process is executed, all resources are recycled. Therefore, by default, it is not easy for a PHP script to leave something "global" (I was cheated by the keyword "global" In the beginning). Of course, it does not mean that different requests cannot exchange data at all, in this case, you need to use shared memory or use files for persistence.

However, Apache uses a process to process requests more robust than the thread mode, because in J2EE, the entire Container fails due to a thread problem.

OOP
Mainstream PHP versions already support OOP well, but for historical reasons, the code of many open-source PHP projects is not so OOP. At the beginning, I followed the framework's habit of writing code in a non-OOP way. After writing a dozen scattered functions, I finally couldn't help it, and all of them re-formed the object.

After so many years of Java, the idea of OOP has been very deep. Although it was also a shift from structured programming to object-oriented programming when I came out of school, N years later, turning from object-oriented to structured, this kind of unaccustomed feeling is more intense. Maybe OOP is more in line with the natural habit of thinking. Now, looking at a long string of scattered functions, there is a very insecure feeling. Besides, we need to name the method with an empty mind, to avoid conflicts, tired!

Summary
1. Incorporate PHP into your development toolkit.
2. PHP is not perfect, but there are many notable points.
3. added a lot of colors for PHP targeting
4. In the open-source field, PHP is more developed as the final application, so many people use wordpress to build independent blogs, even if they have no development experience; JAVA is developed by developing frameworks and class libraries for programmers. From this perspective, Java is a niche language.

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.