UPDATE: 30-Jul-2013 1404 hrs
For the record, Am using php 5.3.10-1ubuntu3.7
I have recently started picking up php and playing around with it, for my new gig. I was expecting to get pissed off with the static type declaration(i know,php supports dynamic typing) as a convention, but funnily enough, i liked that part. Infact, working on python for 4 years has biased me to become blind towards the advantages of static types and type specific thinking when designing a new program.
But the most pleasant surprise of all so far has been the error from the interpreter. So far they have been extremely helpful and to the point. In the past, my biggest initial problem in learning a new language has been the error and warning messages thrown by the compiler/interpreter. Am not sure whether this means php interpreter’s error messages are multiple orders of magnitude better than others or my understanding of computers has gone up more than i assumed. I ofcourse, would prefer the latter interpretation, but most likely the truth is somewhere in between. The real hard question, exactly where in between and at what distance from which? Hmm.. sounds like a case for bayesian reasoning*.
One thing that has been annoying is that semi-colon to end of the line to signify end of statement. But perhaps because i started poking around C recently, it hasn’t been as annoying as i would have expected. Just mild annoyance.
Now begin the real annoying part.
PHP Parse error: syntax error, unexpected ‘)’, expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /home/anand/workspace/neo4j_update/test.php on line 13
What the hell is T_PAAMAYIM_NEKUDOTAYIM ?? Sounds like malayalam to my ears and auditory cortex,which are perhaps the least trained(in disciplinary/practice/cognitive control/selection(aka ACC regulation) terms) of my faculties :-). Unfortunately am stuck right now without power and internet duh….that’s even worser…
Time to go find a coffee shop??
Ah well, i still have my mobile connection..
Hmm.. if i pass blank value for filename the fopen function returns a boolean false. Hmm…i should check for it..
Oh well time for a nap..
31-July-2013 1100 hrs..
It seems i was wrong. PHP does support first-class functions. See here.
But more reading around tells me that the biggest problems a python programmer would face migrating to php is semantic. For example take this array_filter function here. It’s a straightforward map function in python. Only the map func works on both lists and dictionaries. Only in php a list is also an array, only with auto-generated integer keys. Now it’s debatable which is better and am not qualified to comment on php’s implementation either, but i will observe that for anyone more familiar with math involved list sounds more natural than array. Perhaps for CS grads associative array with auto-gen integers for keys sounds natural?? I wouldn’t know.
Either way, i have a suspicion it is one of the reasons php doesn’t have the equivalent of scipy or numpy.
And this link here suggests that scope is also similar to that of python’s. i.e: by default the most immediate scope/variable definition is used. And to specify something outside global is used. Though static is rather absent in python. but then, with functions having attributes like any other object, we don’t need static per se.
Damn that dictionary access with key, value separation at the for look statement instead of object.get() takes some getting used to..
And more importantly itertools.. is rather absent.. there seems to be this., but for example it doesn’t have set cross product functions.. not to mention permutations and combinations . This seems useful though at the cost of a dependency.
And prefixing the variable name with $ is annoying to do every single time.. damn..
In summary, it’s worth learning the basics of php for appreciating some of the python’s subtleties and their value..
Otherwise, it’s not very useful.
*– perhaps some other time.