I ran across a Novice java programmer’s mistakes and Common java programming errors page. This is a dubious exercise, but I am going to try and use these pages to compare the learning curve of Java and PHP.
This is inherently unfair, as these are lists of known learning problems in Java that might not exist in PHP. Please tell me, what are the learning hurdles of PHP that might not exist in Java?
First, the Java mistakes:
Naming the Class Differently from its File Name
This is an example of unwanted entanglement: the need to keep two items synchronous across a distance. No such filename entanglements in PHP.
Advantage: +1 PHP
Comparing Strings with ==
Strings aren’t objects in PHP so naive == works as expected, although weak typing can make the results of == more difficult to predict and having a === operator means more things to learn. (see PHP syntax exam)
Advantage: +.5 PHP
Forgetting to Initialize Object Arrays
PHP doesn’t require an array to be declared with a certain type, so this bit of confusion isn’t really possible.
Advantage: +1 PHP
Putting Several Public Classes in One File
Not a limitation in PHP. Naive version works as expected.
Advantage: +1 PHP
Shadowing an Attribute with a Local Variable
Attributes must be prefixed with $this->, so it isn’t possible to shadow an attribute with a local variable, although it is still possible to forget to add the $this->.
Advantage: +1 PHP
Forgetting to call a Superclass Constructors
PHP has this problem as well. Unfortunately, in PHP before __construct, there was an unfortunate naming entanglement between the class name, the constructor, and the superclass name.
Advantage: tie (+1 java vs. PHP 4)
Catching Exceptions Incorrectly
I might be getting this one wrong, but I think both languages have the same problem.
Advantage: tie
Returning void from an Accessor method
The type declaration for return value is unnecessary in PHP. Naive version works as expected.
Advantage: +1 PHP
Calling Instance Methods from main()
This is a variation on the simple hello world argument. The Java hello world makes more demands on the knowledge of the programmer.
Advantage: +1 PHP
Treating Strings as In/Out Parameters
Again, in PHP, strings aren’t objects and the naive version works if you pass by reference.
Advantage: +1 PHP
Declaring a Constructor as a Method
The special __construct name eliminates this confusion.
Advantage: +1 PHP (tie java vs. PHP 4)
Forgetting to Cast Object Data Types
Dynamic typing means no casting means no forgetting.
Advantage: +1 PHP
Extending Interfaces
Dynamic typing in PHP means that interfaces need not be declared and used as much as in Java, but I’ll still call this a tie.
Advantage: tie
Calling Superclass Methods and Forgetting to Use the Return Value
Advantage: tie
Forgetting to Add AWT Components
N/A
Neglecting Import Statements
Java and PHP both ship with large libraries. The built in PHP functions, however, are universally available. However, Woe to the beginner that has to re-compile PHP.
Advantage: +.5 PHP
Forgetting to Start Threads
No threads, no problem.
Advantage: +1 PHP
Using Deprecated java.io.DataInputStream readLine()
N/A
Assigning and passing double literals as floats
I’ll probably get this one wrong, but PHP has only doubles. Thus, no problem. (even if it did have multiple types, I think that dynamic typing would avoid this problem)
Advantage: +1 PHP
Second, the Common (Java) programming errors:
Not specifying the size of a new array.
Arrays grow and shrink in PHP. size specification unnecessary.
Advantage: +1 PHP
Not using correct array bounds.
foreach eliminates this problem. I understand Java has an equivalent now.
Advantage: tie
Doing arithmetic on an instance of a wrapper class.
No wrappers, no problem.
Advantage: +1 PHP
Adding a value of a primitive type to a collection (a set or list) or a map.
Dynamic typing, primitives welcome.
Advantage: +1 PHP
Not casting the value of type Object returned by list.get(i) or map.get(key) to the required type.
Not a problem in PHP. (covered above)
Advantage: +1 PHP
Using static components unnecessarily.
A little nod to the static main here.
Advantage: tie
Not reading the next line inside a loop
N/A
Creating a string tokenizer for a line before checking the line is present
N/A
Reading all input before processing it
N/A
Threading code
No threading, no problem.
Advantage: +1 PHP
Doing nontrivial computation in a class constructor
Advantage: tie
Not using common API methods
Advantage: tie
Not breaking out of a loop when required
Advantage: tie
Not breaking at the end of each case in a switch-statement
Fall through capability in a switch statement isn’t used and useful enough to justify requiring the extra break on each case in the normal course of events. When fall through is used, it is confusing. (see single point of entry argument in php goto) A pox on both houses.
Disadvantage: tie
Assigning constant values to boolean variables in if-statement
In a way, I find the naive version can be a little easier to understand.
Advantage: tie
Declaring variables globally, unnecessarily
Advantage: tie
Repeating code that should be in a method called repeatedly
Advantage: tie
Being too complicated
I’m tempted to knock java in general for this for things like EJB, but I won’t.
Advantage: tie
Combining computation and input/output in a single, complex method
Its easy to mix html output and php. I’ll give this one to Java.
Advantage: +1 Java
I like PHP, but a few of these +1 seem to be -1 to me:
Multiple classes to a file is -1 from my POV when developing. (There are 3 +1 given to PHP for lack of file/class relationship constraints, which seems rather excessive.) In Java there is no question about which file to open to see a class. In PHP it could be anywhere.
“Not casting the value of type Object returned by list.get(i) or map.get(key) to the required type.”
This is no longer an issue in Java 1.5, right?
Coherency of language: -1 for PHP. PHP has some internal stuff that’s in objects, but most in functions. Function naming, parameter orders, and return values exhibit little consistency. Needing to use PHP in OO environment can often reasult in creating wrapper classes for basic procedural API (e.g. DB abstraction, File IO abstraction). Frankly, a mess.
Lack of java-style overloading. PHP -1. The new PHP5 object model introduces signature checking (yay!) but since PHP doesn’t allow overloading a great deal of flexibilty was lost in this move (boo!). No longer can you override a method & provide an incompatible signature. This mixture of strict OO + PHP’s traditional loose typing is really shooting PHP in the foot.
“No threads, no problem.” PHP being unable to run (w/ stability) in a multi-threaded environment would seem to me to be a weakness.
On the exception front Java has a +1. Even though both languages do support exceptions, Java has an advantage with checked exceptions. Java requires that methods which can throw an exception (e.g. by nature of calling other methods that throw exceptions & not using try/catch block) must declare the exceptions they throw. PHP has no such feature, forcing developers using a library to rely on phpdoc documention or to examine the source. Java also supports finally { } which is extremely useful for cleanup.
-Hans
Oh, one more comment. The mention of ‘threading code’ in the java mistakes document is talking about threading program logic, not traditional process threads. Still a -1 for PHP that it is not threadsafe.
-H
Calling PHP not threadsafe really isn’t correct either. Core PHP is and has been threadsafe for quite some time. The problem is that any of the countless C libraries you MAY compile into php may not be. Additionally, in PHP’s share nothing model you will never make the mistake of using threads–hence shooting yourself in the foot when it is time to scale your app across multiple servers. I say, +1 to php.
BTW – I say +100 to Jeff for posting this. Sure, it is admittedly biased…but great fun none the less.
With respect to Hans, I think that the title really says it all: “Why PHP is easier to learn than Java”. Of course Java is more the programmer’s cup-of-tea (coffee?), but that’s because it’s designed to be.
Great post!
Very biased opinions in here, some valid some not so.
Very unbiased opinions in here, some invalid some so.
PHP’s core is not thread-safe. Try using PHP in a threaded environment such as Tomcat without any additional extensions nor libraries. It doesn’t work. It’s not thread-safe. echo() is not thread-safe.
Closing database connections in a try/catch/finally block.
PHP +3
You are right. PHP is easire to learn. Because it is a script based language. And as any scripting language it better be easy to learn.
Some of the disadvantages of java above are actually the advantages. Ans some of the above advantages of PHP are actually yhe reasons why PHP is still used primarily for front end programming and not for core business logic.
Bagus, cuba untuk buat yang terbaik!!!
“No threading, no problem”? That’s the stupidest thing I’ve ever heard!
I’ll write a language that *excels* at adding two numbers together. It’ll be better than ANYTHING PHP can do because “no web support, no problem”, “no variables, no problem”, “no syntax, no problem”!
What about “no programming, no problems”
I know the thread has been dead for a while, but…
Despite PHP being a scripting language, I still found quite a bit of “steepness” in the learning curve:
It doesn’t help when you have to debug/maintain someone else’s code base.
I also think HTML output / logic (emphasis on “slash”) should have given Java more than one point. And forgetting to use $this to access instance methods/variables is still something I do quite alot… (should have been at most a tie).
(I could go on a rant about PHP for a while, but I’ve mostly forgotten most of the head-and-heart-aches.)
What about learning an entirely different webserver for java, horrors like Tomcat, and jars and wars and tons of xml, and that’s just to get a simple webpage going.
Compared to what getting running with apache and php on Redhat in what, a couple of hours?
Hmmmm
Awsome blog! I am loving it!! Will be back later to read some more. I am taking your feeds also
Welcome to our mitsole Data Solution. Click and get more information about mitsole Data Solution.
=================================================
Mitsol Data Solution
This is a terrific posting. I am so lucky the world wide web still has wonderful material.
lollll
You actually make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complex and very broad for me. I’m looking forward for your next post, I’ll try to get the hang of it!
You actually make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand. It seems too complicated and very broad for me. I’m looking forward for your next post, I’ll try to get the hang of it!
I think this is among the most important info for me. And i’m glad reading your article. But want to remark on some general things, The site style is wonderful, the articles is really excellent : D. Good job, cheers
I have a weird desire now to make a false blog. What is a good blog site to do this and let people know that its not really my thoughts but of my characters thoughts?.
You really make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand. It seems too complicated and extremely broad for me. I’m looking forward for your next post, I’ll try to get the hang of it!
Hi there, just became alert to your blog through Google, and found that it is really informative. I am going to watch out for brussels. I will appreciate if you continue this in future. A lot of people will be benefited from your writing. Cheers!
I am really impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one today..
learn free magic tricks…
[...]Why PHP is easier to learn than Java – Professional PHP[...]…
I am really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it is rare to see a great blog like this one today..
moother speech means less chance of stuttering. Second http://www.anticlericale.net/?q=node/25578 ,, relaxation affects the mind. Even if you happen to already know this, it’s possible you’ll not have considered how it’s connected to your speech. The thoughts that’s relax
I think this is one of the most vital information for me. And i’m glad reading your article. But should remark on some general things, The site style is wonderful, the articles is really great : D. Good job, cheers
Windows 7 License…
[...]Why PHP is easier to learn than Java – Professional PHP[...]…
I’m really impressed with your writing skills and also with the layout on your blog. Is this a paid theme or did you modify it yourself? Anyway keep up the nice quality writing, it is rare to see a great blog like this one these days..
It’s perfect time to make some plans for the future and it’s time to be happy. I have read this post and if I could I want to suggest you some interesting things or suggestions. Perhaps you can write next articles referring to this article. I want to read even more things about it!
increased number of hurricanes and tropical storms of late, many northerners that moved to
Hey there, You’ve done an incredible job. I’ll definitely digg it and personally suggest to my friends. I’m sure they’ll be benefited from this site.
I like the helpful information you provide in your articles. I will bookmark your weblog and check again here regularly. I’m quite certain I’ll learn a lot of new stuff right here! Good luck for the next!
We are a group of volunteers and starting a new scheme in our community. Your website provided us with valuable info to work on. You have done an impressive job and our entire community will be grateful to you.
excellent. I actually like what you’ve acquired here, certainly like what you are saying and the way in which you say it. You make it entertaining and you still take care of to keep it smart. I can’t wait to read much more from you. This is really a wonderful website.
Very nice post. I just stumbled upon your weblog and wanted to say that I have truly enjoyed surfing around your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon!
Your house is valueble for me. Thanks!…
Magnificent beat ! I would like to apprentice while you amend your site, how could I subscribe for a blog site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear idea
If you’re one of the 552,642 people who own a piece of this campaign, let us know why. We’ll RT your reasons.
I like the helpful info you provide in your articles. I will bookmark your weblog and check again here frequently. I am quite certain I will learn plenty of new stuff right here! Good luck for the next!
Hello There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful information. Thanks for the post. I will definitely comeback.
I am really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you modify it yourself? Anyway keep up the nice quality writing, it’s rare to see a great blog like this one today..
Simply desire to say your article is as astounding. The clearness in your post is simply spectacular and I can assume you are an expert on this subject. Fine with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the gratifying work.
Heya i’m for the first time here. I found this board and I find It truly useful & it helped me out much. I hope to give something back and aid others like you helped me.
I think this is one of the most important info for me. And i’m glad reading your article. But should remark on few general things, The site style is perfect, the articles is really excellent : D. Good job, cheers
Attractive section of content. I just stumbled upon your web site and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Anyway I will be subscribing to your feeds and even I achievement you access consistently quickly.
Fantastic beat ! I wish to apprentice while you amend your site, how can I subscribe for a blog site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear idea
I like the helpful info you provide in your articles. I’ll bookmark your blog and check again here frequently. I’m quite sure I will learn a lot of new stuff right here! Best of luck for the next!
hello there and thank you for your information – I’ve certainly picked up anything new from right here. I did however expertise several technical issues using this website, as I experienced to reload the site a lot of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I’m complaining, but slow loading instances times will sometimes affect your placement in google and can damage your quality score if ads and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for much more of your respective interesting content. Make sure you update this again very soon..
Hello there, You’ve done a great job. I’ll definitely digg it and personally suggest to my friends. I am sure they will be benefited from this website.
hey there and thank you for your information – I’ve certainly picked up anything new from right here. I did however expertise several technical issues using this website, as I experienced to reload the site a lot of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I’m complaining, but slow loading instances times will often affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my e-mail and can look out for much more of your respective exciting content. Make sure you update this again soon..
fantastic. I really like what you’ve acquired here, certainly like what you’re saying and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I cant wait to read far more from you. This is actually a wonderful web site.
Undeniably believe that which you said. Your favorite reason appeared to be on the net the easiest thing to be aware of. I say to you, I definitely get irked while people consider worries that they plainly do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks
Loved every bit of the article post. Keep writing.
[...]The information mentioned in the article are some of the best available [...]……
[...]The information mentioned in the article are some of the greatest available [...]……
Undeniably believe that which you stated. Your favorite reason seemed to be on the net the easiest thing to be aware of. I say to you, I certainly get annoyed while people think about worries that they just do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks
I like and thank you for post.Truly thank you! Excellent.
Fantastic goods from you, man. I have understand your stuff previous to and you’re just too
Hi, I think that I saw you visited my weblog thus I came to “return the favorâ€.I am attempting to find things to enhance my website!I suppose its ok to use a few of your ideas!!
I am extremely impressed with your writing skills and also with the layout on your blog. Is this a paid theme or did you modify it yourself? Anyway keep up the excellent quality writing, it is rare to see a nice blog like this one these days..
Hello There. I found your blog using msn. This is an extremely well written article. I’ll make sure to bookmark it and return to read more of your useful info. Thanks for the post. I will certainly return.
I know I can find this hair for cheaper than $320. But I dead have no time to search
Pretty nice post. I just stumbled upon your blog and wished to say that I’ve really enjoyed surfing around your blog posts. After all I’ll be subscribing to your rss feed and I hope you write again very soon!
Take it easy and rest As you are Studying the Strategies of dirt bikes for sale
I am not sure where you’re getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for excellent information I was looking for this info for my mission.
Undeniably believe that which you stated. Your favorite justification seemed to be on the internet the simplest thing to be aware of. I say to you, I definitely get irked while people think about worries that they just don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks
Woah! I’m really loving the template/theme of this website. It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between usability and visual appearance. I must say you have done a excellent job with this. In addition, the blog loads super quick for me on Chrome. Outstanding Blog!
wonderful. I actually like what you’ve acquired here, certainly like what you’re stating and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I can’t wait to read much more from you. This is really a great site.
301 Moved Permanently I was recommended this web site by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my problem. You’re amazing! Thanks! your article about 301 Moved PermanentlyBest Regards SchaadAndy