7

I am more practiced in PHP than in Java, and when I use Java I find myself looking at it from a PHP perspective. This can cause trouble, so I'd like to know, what are the most common programming mistakes PHP programmers make in Java?

  • 1
    Does using HashMaps all the time count as a mistake in Java? Because then I'm guilty... very guilty. – AndrewKS Jan 20 '11 at 17:48
  • 1
    Their mistake was coding all these years in PHP instead of Java. – Job Jan 20 '11 at 20:07
  • 4
    @Job: I have seen horrible code from both PHP and Java developers, and have seen beautiful code from both as well. There is no right path. – Josh K Jan 20 '11 at 20:29
  • 1
    @Josh K - good point, although I'd say both can actually be the better path for different situations. – Nicole Jan 20 '11 at 20:52
  • 1
    @Josh K nearly the same path as me. I will defend both if needed. Although I see Java as more of a programmers language and PHP as somewhat of a cowboy language, PHP is a clear winner for projects under a certain size. – Nicole Jan 20 '11 at 21:00
6

Perhaps slightly flippant, but after bingeing on PHP for many years (it pays the bills), I've often been happy to be able to use crazy things like enumerated types and native data types that aren't arrays/objects playing dress-up.

Whilst a sweeping generalisation (the best ones always are), I guess what I'm getting at is that perhaps the most common mistake is to remain in the PHP mindset and not take advantage of the features that the language offers.

3

I'd say the biggest mistake I've seen is approaching Java, which is OOP, with a procedural mindset. Methods to a PHP person look like functions, and the main method (or constructor) looks like the procedural part of PHP. So you end up with entire programs existing in 2 giant classes with thousand line long methods.

As a PHP dev who made the move to Java, I can say that it is difficult. But of course this is the case with any move from a procedural language to an OOP language

3

A few things I notice:

  • Keeping views clean

    PHP makes it very easy to "leak" logic into your views. Keeping them clean is often a chore. With some Java frameworks it's easier, but still you find a few things in them that should not be there

  • OOP vs Procedural

    With Java everything is an object, and this forces you to think through how you plan on using this object. Often times this isn't done in PHP and cheats are used. Either assoc. arrays, stdClass blanks, or other things created without a clear purpose

  • On-the-fly coding

    Java development doesn't encourage spontaneous quick changes whereas PHP does.

  • Unit testing

    Java is easy to unit test, PHP less so. The often (above mentioned) dirty views mean there is less test coverage then ideal. If the application is using tests it's often ignored by PHP developers who are new to Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.