|
There are no translations available.
As I have argued in previous posts, a programming language which supports first class functions is invariably superior to other programming languages, that do not support them. The better programming language has functions able to accept functions as function arguments, and able to return functions as return values.
The faulty idea in Java and C# that every function should be a method
Java and C# methods cannot accept functions as arguments, or return functions as values. This is the first major source for their inferiority.
Both languages are based on the idea that every function must be a method. However, as I have argued in previous posts, object-oriented methods are just one possible polymorphization strategy, that is, a strategy to produce function closures.
Why would one closure style from an infinite number of available styles, be the best or even a sufficient style to model reality, and therefore to build systems?
Therefore, the idea that every function must be a closure around its first function argument -- the object -- is preposterous. Consequently, languages that enforce this ridiculous idea, are simply aggravating.
Progress in our field, requires experimenting with, and designing, new closure styles. It will allow us to model reality better. Therefore, languages such as Java and C# -- that mandate the use of methods -- stand in the way of progress.
The faulty idea in Java, C#, and C++ that it is possible to statically type object types
It is certainly possible to statically type atomic variable types, such as ints, floats, and strings, However, as I argued in previous posts, any attempt to statically type object types will lead to exponential complexity in the source code, exponentially large growing executables ("code bloat"), and exponentially rising complexity in the language grammar.
Either you write your algorithms in terms of the root object -- that is, you use scripting style -- or else, you create the same algorithm again, for each different object type to which it applies.
Generic programming introduces a system of templates in order to to alleviate the issue in statically typed languages. However, even generic programming can not capture all possible situations. Any attempt in the direction of capturing all the issues involved, requires an additional and even more complex template programming meta-language; while we know that the complexity of vanilla generic programming is already beyond the capabilities of the ordinary programmer.
The mind-blowing complexity resulting from statically typing in Java, C#, and C++ buys you nothing at all. It is simply snake oil.
What about Php?
The Php makers have never tried to shoehorn anybody into any big ideas that would be the be-all and end-all of all programming issues. Php originally started when Rasmus Lerdorf needed a tool the help him write personal home pages.
Php's rising popularity put its language builders under market pressures to add support for features that other people needed for their own personal home pages. Increasingly, users started using Php for more than personal home pages, and started building fully-fledged web applications in Php. It led to even more pressure to add features.
Php largely managed to maintain the simplicity for which it is still cherished. At the same time, it does not constrain the people who need to program things that are more complex than a personal home page.
Even though the language and its libraries may have their imperfections, Php is definitely a useful language that certainly reaches the goal of facilitating the construction web applications. It simply works.
First-class functions in Php
There is no function (pointer) data type in Php. So, at first glance, there are no first-class functions.
However, you can invoke funtions based on the string representation of their names:
- functions: call_user_func($function,$parm1,$parm2,...) and call_user_func_array($function,$parmArray)
- methods: $object->{$method}($parm1,...)
Also, it is possible to randomly eval($expression) any expression.
Therefore, first-class functions are supported, on the condition that you triangulate over strings.
First-class functions do not work as well as in C or Javascript, but the situation in Php is definitely better than in Java or C#.
So, the situation in terms of first-class functions is:
- Javascript, C: Works well. Correctly designed.
- Php: Works sufficiently well (a hack). Incorrectly designed.
- Java, C#: Does not work. Excluded by design.
Php is a better programming language than Java and C#
The Php language builders add features to Php under market pressure. Sometimes, it does indeed amount to just a bunch of ugly hacks. However, Php eventually always gets there. The users can use the new features and move on with their lives.
In this way, the Php language builders have also added support for first-class functions. It was not necessarily done very cleanly, but it works.
The language builders for Java and C#, on their side, dictate, mandate, enforce, control, impose, and shove their ideas down the throat of their users. This is a dangerous strategy, especially, when they get their ideas wrong.
For example, the mandatory use of methods -- which bans ordinary functions -- and the mandatory use of statically typing, are simply wrong ideas, which are costing their users dearly. The combination of being dictatorial and at the same time deluded, is indeed a recipe for disaster.
Therefore, if you are about to choose whether to use Php or else Java or C# for your next web application, I recommend the use of Php. You will have better long-term prospects.
|