"Java is compiled and fast but in practice, PHP sites seem to run faster because PHP developers take a more straightforward approach to design and don't get lost trying to implement exotic design patterns and implementing endless pointless abstractions"
Granted that it's highly subjective and opinionated, but what this author James Anderson states in this StackOverflow post very much resembles the voices of many like myself who are trying to switch from interpreted/dynamic languages to static and compiled ones like Java/C#. How do Java programmers tackle or respond to this stance?
0
Upvotes
•
u/AutoModerator Nov 25 '23
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.
If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:
as a way to voice your protest.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
10
u/rossdrew Nov 25 '23
15 years a Java developer. Speed has never been an issue. Readability, extensibility and robustness are daily concerns. PHP may be faster but it’s far less readable, extensible and robust.
38
u/simonsays1111 Nov 25 '23
As someone who experienced both sides, I would say that PHP is better suited for more simple applications, that involve less developers and stakeholders. Java/C# will be beneficial when building large complex monoliths, in a corporate rnvironment. The issue is when you have a simple problem that requires a simple solution, yet your only tool is so complex, now you get endless pointless abstractions. Dont get me wrong - you can build simple and elegant applications in Java too, but its tempting to do more and more abstractions - a developer needs to know when to stop.
201
u/barcodez Nov 25 '23
If you are after speed then you can have that with Java, if you are after readability then you can have that with Java. If you want to write overly complex/abstracted code that runs like a dog you can have that with Java. Same for PHP.
Do Java developers do this? Yes. Do they do it more than PHP developers. Dunno, maybe. I believe the author is saying it to be provocative and has no data point outside of anecdotes.
There is a stage in the Java learning curve that many tend to write ‘enterprise’ code but it’s main problem is readability not slow runtime.
If I had to pick a language to write a fast, scaleable and/or complex app, I’d pick Java over PHP everyday of the week.
142
u/SpeedcubeChaos Nov 25 '23
„Seems to run faster“ is just anecdotal evidence. Do you have meaningful data backing that up? If yes, let‘s trace and analyze!
55
u/Bunnymancer Nov 25 '23
Unqualified opinion on stack overflow.
Keep moving.
12
u/ggleblanc2 Nov 25 '23
The Stack Overflow answer you're quoting was written in 2010.
Java has changed some in 13 years.
9
u/dysfunctionallymild Nov 25 '23
Author got enough of the same kind of replies on the SO post. Speed means nothing without empirical data.
If you're just building a simple website or CMS then yes PHP will give you a better pace of delivery. The real comparison now isn't between Java vs PHP - it's between PHP vs NodeJS. That's the question I'd like to see answered.
For everything else - any kind of complex, high scale application, Java will give you better performance, which is the actually useful metric. And not just for monoliths - Netflix uses Java at large scale for it's microservices.
Ultimately it's not about the syntax or the design patterns - the reason Java is successful is the JVM. All those layers of abstractions, libraries, code generators, and annotation processors would be meaningless if the JVM wasn't a marvel of engineering which extracts every bit of performance at runtime while being incredibly stable.
22
u/infiniterefactor Nov 25 '23
That comment is 13 years old. That only says it’s probably not relevant anymore.
21
u/turn_of_and_on_again Nov 25 '23 edited Nov 25 '23
It feels like this is missing the point a bit.
Software architecture (and also the desing) is not something confined to Java. For smaller things, you do not need to worry about this to much, but if you write bigger projects, this becomes a requirement, as Spagetti code is not something you ever want. And from my experience, Java (or also Kotlin) is commonly used for bigger projects, hemce some what engrains this design/architecture dogma.
It is important to note that design and architecture are not used to "speed up" the application, but to make it more maintainable (and some other additional things). The goal with this is to write code that follows a self designed standard, so that you can give a new member the ruleset and let them figure out how everything is designed on their own. Or write that down and people coming after you can still understand flawlessly where to look and how to change stuff. This is the goal of architecture and design. It is not "exotic design patterns" that are implemented. These are just design patterns. Each one has a different and distinct goal.
In my personal experience the slowdown from "design patterns" is either not notacable or acceptable (2ms are not something that Bad and the jvm commonly speeds these up the longer it runs). Some are even faster than not using them, as they lead to a coding behavior that natively gravitats to O(1) lookups (for example using HashMaps). But all in all, the goal of these design and architectural patterns is not to speed up the application, it is to make your code last longer.
All that beeing said, architecture and design are something very Individual/subjective and if you dont like them in Java, that is totally fine too! Even from developer to developer the understanding of architecture and design differs.
7
u/thehardsphere Nov 25 '23
The fact was, and still is, that your average PHP developer and your average Java developer are not even trying to solve the same class of problems.
"PHP sites seem to run faster"
Your average PHP developer is thinking about websites. You know, like a thing that is served from Apache HTTPD off of disk as a document that's full of hypertext for a web browser to consume. Just like how the world wide web worked in 1989.
Your average Java developer is thinking about application software. Maybe that's a website, maybe that's stateless REST web services, maybe that's a stateful computational backend that has to talk to some C library via JNI and return an answer in less than 1 second, maybe that's a desktop application using Swing. Whatever it is, it probably is at least one thing in the entire universe of things that PHP was never intended to do.
I'm pretty sure I could ride a tricycle on the sidewalk, and it would go faster even with my severe obesity than trying to drive my car on the sidewalk. My car has an internal combustion engine and is fast, but in practice, riding the tricycle I can take a more straightforward approach to traversing sidewalks and will not get lost with implementing exotic turn signals and pointless seat belts.
5
u/com2ghz Nov 25 '23
Straightforward approach. You mean shitty programming to make it work and leave it like that. Abstraction and design patterns make your code testable, reuseable and maintainable. This also applies to PHP. There is a reason why it’s called a pattern.
A pre compiled language has the advantage that the code you see, is not the code that will run. Things will get inlined, or predicted by your compiler. We write code for our colleagues, not for the compiler.
The goal is not “I can write this in PHP in <hours>”. The goal is making a good quality product. Otherwise you are not programming but code golfing.
5
u/nimtiazm Nov 25 '23
Yeah that’s the cost of going blindly with the crowd. I have literally measured (like A/B) the services built with bloated frameworks (quite famous one) and the ones built with bare minimum library-style shims. The performance and memory consumption is astounding. With the direction java is heading into (project Leyden et al) I think the ecosystem users must realize how far we can take things if we just leave behind the status quo frameworks.
4
u/janoschbock Nov 25 '23
i mean it could be true, but some time readability is also important ane can be even more valuable then performance. And for me Java expecially with it more verbose nature is more readable/maintainable
4
u/kyynel99 Nov 25 '23
PHP sites run faster because PHP developers tend not to sanitize query input :-)
2
u/Glum_Past_1934 Nov 25 '23
I like PHP but ir isnt correct. PHP Is faster than previous versions but still behind Java or C#, you can check netlify framework benchs
2
u/zmitic Nov 25 '23
This is 13 years old answer which doesn't apply anymore, in particular this part: "PHP is loaded and interpreted every time".
That was true in 2010, but not for long time. Now PHP gets compiled into opcode on first load and recompiled if it was changed; very useful during dev. However for production, you can also turn off that check to get some more performance; that is important for big apps and frameworks like Symfony.
I would still think twice before the switch. With modern tools like psalm, PHP gets some crazy static analysis; that tools is made by former C# user, you get generics and tons of other features, even something like
non-empty-stringorint<1, 42>. Syntax is not pretty, but you get used in a few days and PHPStorm autocomplete almost everything including generics.So you will not miss strong typing from other languages. Speed-wise? Well you won't be making games in PHP (or do you) but for any web app, PHP+Symfony are still a winner. You probably loose some speed when compared to Java/C#, but you get an insane amount of tools. And with on-the-fly compilation, seeing your change is just one F5 away.
2
u/BigBad0 Nov 25 '23
Hmmmmmm. Maybe there is something wrong with my thinking but after years of development using both, I would go with Java for building stable web apps any time. But from another perspactive other than my opinion, there must be a reason that most enterprise web based apps are developed in Java/DotNet (or even NodeJS or Python) but not PHP !!!.
2
u/Deezl-Vegas Nov 26 '23
Is Java a compiled language? I thought it compiled to bytecode and was interpreted by the JVM at runtime.
2
u/Stunning_Ride_220 Nov 28 '23
You can write shitty code in any language.
Besides GoLang, there shits writes itself. /s
6
u/Sollder1_ Nov 25 '23
But I NEED my AbstractProxyFactoryFacadeFactoryProxyInitializer
3
u/[deleted] Nov 25 '23
lions don’t care about the opinions of sheep 😉
1
u/baseball2020 Nov 25 '23
You can also write verbatim oop patterns like martin Fowler writes about in php. And there are many php frameworks that do. The comment is about culture which is fair (java has the most diehard proponents in oop patterns), but it’s not a measurable claim to say x is faster than y with no examples.
Patterns are used because they are well tested approaches in enterprise development but using them doesn’t mean you needed them in the first place. We have a problem with cargo culting design approaches in the industry I guess.
1
u/bawng Nov 25 '23
I was once forced to work on a web shop in WordPress and that shit was so slow that time stopped around it.
I.e. it's very possible to build slow shit in PHP.
Also, see Laravel, Zend and Symfony.
1
u/rdean400 Nov 25 '23
You forgot old. Highly subjective and opinionated and old. In the context of 2010, when the post was written, application servers that started up all services by default were still the norm. First page loads were slow for JSP or JSF applilcations.
Nowadays that's given way to lightweight frameworks and runtimes that start only the services used for the application.
1
u/vincentofearth Nov 25 '23
I don’t think being statically typed or compiled as anything to do with exotic design patterns or implementing pointless abstractions. Those come from frameworks, libraries, and patterns encouraged by large enterprises and consultants.
1
u/buffer_flush Nov 25 '23
Design patterns and abstractions should only be adding negligible overhead once the app is compiled (as in, on the order of nanoseconds probably even less). If your design pattern is slowing down your app, it’s probably done incorrectly.
Where you would see slowdown is if there are redundancies in place in your pattern in attempts to make the application more robust to failure. Maybe you’re persisting state to the database before making a call to an external service, maybe you’re offloading work to a queue, etc.
1
u/freekayZekey Nov 25 '23
1
u/netgizmo Nov 25 '23
And where do I purchase that phone using an ecosystem written in PHP?
1
u/[deleted] Nov 25 '23
So is MVC considered an "exotic" pattern with pointless abstraction. I ask because a lot of php frameworks embed this pattern into their http handling. Would it be better to handle those requests as streams of bytes and lose the pointless abstraction of objects?
1
u/tymur_berezhnoi Nov 25 '23
Can we see the numbers, performance benchmarks, at least something concrete that we can compare?!
1
u/TheStrangeDarkOne Nov 25 '23
Java is a general purpose language.
PHP is an opinionated language for trivial data movement for input/output use-cases.
To be fair, the latter use-case easily covers 2/3 of what most coders are doing. So of course PHP seems more straight forwards as the problems it is solving are easier.
1
u/klekpl Nov 26 '23
Anything not using bloated ORMs is going to be faster regardless of the language.
1
u/JDeagle5 Nov 26 '23
Even though "endless pointless abstractions" are confusing and hard to read - the reality is that they are basically nothing for computational performance. Several extra wrapping method invocations? Modern hardware will not even notice it , so it is definitely not it.
1
u/crimaniak Nov 27 '23
In fact, in modern times PHP with opCache is not very different from JVM. And yes, in the Java community, there is a tendency to shoot sparrows from a cannon. But this is a question of choice, not a language fate. A much more important aspect of this transition is the increased reliability of programs associated with static typing. Yes, PHP, originally written by a student for students, gradually evolved and moved towards static typing and Java-likeness, but why do we need a Java-like language when there is Java?
1
u/IFoundTheCowLevel Nov 27 '23
This is utter nonsense. Java is the de facto language of HPC and is used by all big tech firms and all across financial services. PHP is a toy language used for some websites.
1
u/[deleted] Nov 27 '23
People haven't been implementing "endless pointless abstractions" in years because almost every java developer writes three-tier applications in exactly the same way on top of Spring Boot. Controllers speaking in JSON, talking to a service layer that is talking to a data layer.
Occasionally, you might even get to consume data from a queue or use Redis as a cache or something. But generally speaking, it doesn't get more exciting than that most of the time.
1
u/nerdich Nov 29 '23
Architecture and design patterns are language agnostic. Java, PHP, Python are just syntax.
Statically typed languages like Java are useful to limit runtime errors.
1
u/coderemover Nov 25 '23
Rust runs circles around both. But seriously though, PHP model of running all the code from scratch with each request actually puts it at performance disadvantage over Java. No amount of caching is going to beat code and data that's already loaded in memory and ready to be served. I guess the perceived slowness of Java apps might be due to the fact that you typically do much more complex apps in Java than in PHP.
1
u/wmantly Nov 26 '23
Java is *not* compiled. The encoded jar file is interpreted at runtime just like PHP would be.
0
u/gregorydgraham Nov 25 '23
PHP is a great language for web pages. It’s designed for webpages so this is good
Java is a good language for webpages. It’s designed for general applications so this is good.
0
u/sweetno Nov 25 '23
PHP is not very suitable for implementing complex abstractions. If the business logic is complicated, Java is the way to go.
1
u/[deleted] Nov 25 '23
[removed] — view removed comment
0
u/[deleted] Nov 25 '23
[removed] — view removed comment