PHP impressions of Java programmers

Source: Internet
Author: User
Tags php error 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 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 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.