php –observations

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.

1514 hrs..
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..

1528 hrs..
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.

1130 hrs..
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.

1303 hrs.
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.

my laptop hunt woes

I have been hunting/narrowing down on a laptop i want or need and have come to the conclusion that, unless i build/assemble one myself, i am doomed to buy one of those pre-packaged,over-priced junk.
Sites-wise, Dell’s site is the only one that provides a decent UI of filtering based on features. Lenovo’s is the worst.. It forces you to choose some series based on whatever junk their marketing department decided was their goal. I mean there perhaps is some correlation and it is a good navigation for someone who doesn’t want to spend comparing hardware specs.

But for a Techie like me, that’s outright condescending.
On the packaging, part clearly there is an established habit among consumers to correlate price and HDD size and all the laptop vendors are utilizing it as much as they can.
Don’t get me started on Acer, they have 3 categories Notebooks, Ultrabooks, Netbooks.. WTF is the difference between these nonsense categories??

Toshiba UI compares nicely to the Dell one in terms ability to search by price, but still has the packaging problem. Guess that’s the standard in laptop market and it’ll take sometime for the business model to be disrupted, by a clever, laptop assembling company.

Here’s what i want:
1. Storage: A SSD for hard disk(anything > 32G will do). The point of SSD is just to hold the OS and packages i end up installing and can get to use on the fly. Guess a 64G is a good limit for it. For any data am just going to be using my external SATA Disk.
2. Processor; most of my operations i plan to do are computation intensive. I plan to run some NLP algorithms, Machine Learning algorithms etc… Perhaps i can expand my master’s thesis. So a good processing power is a must. preferably core i7(but due to the packaging and price limit, i might end up going for core i5)
3. RAM: Again given my usage, and that am not a fan of heavy loading complex physics games, a minimum of 4GB DDR3 sounds reasonable.
4. Graphics Card: Again, not being a frothing at the mouth fan of video games, am willing to forgo heavy acceleration graphics card, and settle for normal,decent graphics performance. Intel HD graphics 3000 seems to fit the bill.
5.OS: My biggest grouch/pain-point. I don’t care for Windows 7’s new shiny UI. I have been on linux for a couple of years now, and find it painful to work even on Windows XP. Given that, i would rather, get one without any OS, but it seems like i won’t. I just can’t find a laptop without Windows installed.

From what i understand about the hardware prices, it should be possible to put together a laptop with these component within the 50K-60K INR price range.
But no apparently according to the Dell business/pricing team, if i go for a 6GB RAM i will also want a 1TB hard disk. Darn..

And if i go with a i7 i’ll have to go with a minimum of 500GB HD or 256GB SSD..Gaargh…Either am totally missing something about the hard ware price ranges.. or dell is designing it’s laptop packages to maintain their profit margin. And given my decent Quant. Aptitude skills i suspect it’s the latter.