NYCPHP Meetup

NYPHP.org

[nycphp-talk] Learning to program the right way

Rukbat rukbatsramblings at gmail.com
Thu Jan 26 11:03:02 EST 2012


As someone who started by writing machine code (not assembly, bits - and 
in octal, which was the big thing back when we wrote code on stone with 
wooden chisels), I can say that's very true.  I've sen some C code that, 
when it was compiled to assembly, was absolutely terrible.  (And don't 
get me started on the massive bug in version 2 of Microsoft's C 
compiler.)  But with PHP, you're writing data, not code.  Yes, it looks 
like code, but it's just data to the PHP interpreter which is running 
it.  The efficiency at the assembly level really comes from writing an 
efficient PHP interpreter.  If that's inefficient, the best PHP code 
isn't going to execute fast.

The other, and I think more important, considerations are SQL and 
Javascript  They'll impact the user's experience a lot more than the PHP 
code will.  If you do a search on a huge table using LIKE or not using a 
proper index, it may be done when you get back from lunch - in Paris.  
That has nothing to do with PHP.  Neither did the fact that some JS ran 
50 times slower in IE5 than it did in FF1.

You have to write efficient JS and efficient SQL.  Inefficient PHP isn't 
elegant, but it won't impact the user nearly as much as a SQL join that 
forces a linear search on a table with 10 million records.

And that's not stuff you teach in a CS course - that's the difference 
between an entry level programmer and someone with bloody fingers.

But yes, if you're writing on the metal, assembly can be a lot more 
efficient at runtime than a 3GL.  (Not at writing time, though - printf 
is a lot more efficient to write than poking bytes to the screen memory 
by hand, or even sending a string to an API.)

On 1/24/2012 3:08 PM, Leam Hall wrote:
> On 01/24/2012 02:52 PM, Justin Dearing wrote:
>
>> I  was going to make an argument that assembly might not be needed at 
>> the
>> associates level, but writing this has made me question that myself.
>> However, I think its more important to be able to read assembly than 
>> write
>> assembly, so maybe it should be taught that way. One or two lessons 
>> where
>> you write some stuff to appreciate the syntax, and the rest would be
>> "compile this code, step through the assembly" Seeing different calling
>> conventions in action will probably teach students a lot, and 
>> honestly I'd
>> probably audit a course taught that way.
>>
>> Justin
>
> Randall Hyde of "The Art of Assembly" book fame posits that 
> programmers who learn the machines and how things work, through 
> Assembly programming, are more able to write performant code.
>
> I don't know enough to confirm or deny that theory, but it stuck with me.
>
> Leam
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show-participation




More information about the talk mailing list