Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Acquia Blog:
Quick Tips for Writing Object Oriented Code in PHP
Jul 13, 2015 @ 10:58:14

On the Acquia blog Adam Weingarten has shared some tips for writing good (and modern) object-oriented code in PHP:

Recently I began working on a D8 module, but this isn't a story about a D8 module. The work I did provided me an opportunity to get back to my pre-Drupal object oriented (OO) roots. Writing OO code in PHP presented some curve balls I wasn’t prepared for. Here are some of the issues I encountered:

His tips touch on things like:

  • Using a code structure that can be autoloaded via PSR-4
  • Namespacing your classes
  • Working with types and type hinting
  • Using docblock comments for autocomplete in IDEs

There's also a few other quick topics he finishes the post out with: the lack of enums in PHP, working with associative arrays, no functional overloading and assigning responsibility to classes.

tagged: oop tips objectoriented code modern psr4 namespace typing docblock missing

Link: https://www.acquia.com/blog/quick-tips-for-writing-object-oriented-code-in-php/09/07/2015/3285651

Allan MacGregor:
Hello Hack
Mar 25, 2014 @ 09:50:33

Allan MacGregor has a new post to his site introducing you to Hack, the recently released language from Facebook based on their work with the HipHop virtual machine.

Recently Facebook unveiled Hack, a new programming language that aims to provide developers with the tools to write and ship code quickly while catching errors on the fly. Hack is as programming language designed to work with HHVM and the same time it works seamlessly with PHP as Facebook lead devs. [...] So does that mean that Hack is just a faster more efficient PHP implementation, right? Wrong, Hack is much more than that, the language brings features that are normally found in statically typed languages to the dynamically typed world of PHP.

He focuses in on the static typing functionality of Hack a bit more and includes an example of PHP code where Hack would catch the type shifting. He also briefly mentions some of the other features including built-in collections, traits, generics and asynchronous programming.

tagged: hack facebook language introduction typing

Link: http://coderoncode.com/2014/03/23/hello-hack.html

DZone.com:
The Duck is a Lie
Jun 27, 2012 @ 09:55:22

In this recent post to DZone.com Giorgio Sironi looks at duck typing and compares it in a few different languages (PHP, Ruby and Java). "Duck typing" is where the methods/functions define the structure or common interface rather than being functional.

What follows is my experience with Java, PHP and Ruby. I mainly use PHP as a dynamic language that supports duck typing but also the definition of Java-like interfaces, but does not force any of the two approaches as you can define interfaces whose method arguments accept any variable or not using interfaces at all. Is duck typing that a revolution?

He shares some of the common misconceptions he's seen including the idea that duck typing can help completely different objects work together and that, sometimes, despite naming conventions, functionality was intended to be different. He shows how even interfaces in PHP can be implemented loosely and the "acts as" and "single callback" architecture ideas.

tagged: duck typing interface misconception actsas callback

Link:

Pim Elshoff's Blog:
In favour of typing
Apr 25, 2012 @ 13:57:38

Pim Elshoff has a new post to his blog that shares his preference on typing (keystrokes, not variables) in applications (hint: he likes it):

We sometimes conceive of ideas that are arduous to express in code. Like persisting data, or some other uncommon task (sarcasm). It's not difficult, but it takes a lot of keystrokes to write. Being problem solvers, we find it difficult doing this kind of manual labour, especially when machines can do it for us. Still, I would like to take this opportunity to say that typing rocks and solutions that save typing suck.

He talks about the abstraction that frameworks provide (less typing, more work) and and some of the "magic" that comes with them. He gives specific examples of some of his pervious experience with frameworks (including some pains with Symfony2) and how some of the magic he's seen is easy to write but hard to read.

tagged: favor typing keystrokes framework magic opinion

Link:

Evert Pot's Blog:
Numeric string comparison in PHP
Apr 26, 2011 @ 09:23:47

In this new post to his blog Evert Pot reminds you (the PHP developer) about the loose and strict typing checks that you need to do when checking the values of your variables and never just assume. PHP's loose typing tendencies can cause issues if you're not paying attention.

As long as you make sure you always use strict checking (=== and !==) where you can, and fall back to the loose checks when you must. As a PHP developer, I think it's very important to understand and memorize exactly how these work, whether you're writing new code, or maintaining existing code.

He points out a specific example of some code that seems counter-intuitive when you compare how it reads and how it actually works (strings converted to floats and evaluated)

The moral is: always do strict checks when you are able to.
tagged: numeric comparison evaluate loose typing typecheck

Link:

Giorgio Sironi's Blog:
Java versus PHP
Apr 16, 2010 @ 10:55:19

In a new post to his blog Giorgio Sironi has a (more balanced) comparison of Java versus PHP that them on topics like how they handle typing and their execution models.

If you exclude C and its child C++, the most popular programming languages in the world are Java and PHP, which power most of the dynamic web. I have working experience with PHP and for academical purposes I am deepening my knowledge of Java, thus I'd like to point out similarities and key differences between these two languages. Every language has its pros and cons, so there's no absolute winner here.

He briefly covers their history, java's static versus PHP's dynamic typing, how they both handle objects, their execution plans and how easy they are to deploy when it comes to general applications.

tagged: java comparison typing oop execution infrastructure

Link:

Jani Hartikainen's Blog:
Static/Dynamic typing sweet spot
Oct 08, 2008 @ 10:24:28

In a new post today Jani Hartikainen takes a look at one of the things that makes PHP both powerful and unpredictable at times - its variable typing, static versus dynamic.

It seems that PHP has moved a bit towards static typing, and languages like C# seem to be implementing some dynamic features. Are we going towards a "mixed" language with static and dynamic typing? What's the "sweet spot" between completely static (like C++) and completely dynamic typing (like Python)?

He compares the benefits of static and dynamic, and a particular place where PHP falls a bit flat - type hinting in certain situations. He agrees, though, that dynamic typing is "the way to go" since it gives the developer the flexibility they might need for more "typing tricks" in their apps. Oh, and "duck typing"...

tagged: static dynamic typing type variable hint compare

Link:

Matthew Turland's Blog:
The Yin and Yang of Typing
Feb 01, 2008 @ 11:58:00

A little while back Matthew Turland posted about something that some developers moving over to PHP from more strict languages have an issue with - variable typing - and how its evolved in languages over time.

Without a little background in programming languages or computer science in general, it's entirely possible that typing systems are not something that have crossed your mind. I thought I'd take a blog entry to share some of my thoughts on how it’s affecting the creation and evolution of languages.

He walks through history a bit, mentioning C, Java, Python and PHP and how they differ in their default type handling. He especially focuses on the "blurred line" between strong and weak typing and how some if offers special features to the language that uses the method.

tagged: typing strong weak strict dynamic java python c

Link:

Nick Halstead's Blog:
Do faster typists make better coders?
Jul 25, 2007 @ 14:51:04

Nick Halstead asks an interesting question on his blog today - "Do faster typists make better coders?"

I have been able to touch type since about age 12 and can manage about 100 words per minute when faced with blocks of text to copy and even faster if I am just writing code. [...] Programming in C meant a lot more typing of parenthesis and a lot more thinking about the structure of the code.

PHP has introduced another set of typing problems with a lot more use of < > and a much higher mixture of variables/functions/parenthesis plus the added bonus of trying to remember a single function from a choice of 3000+.

Several of the comments on the post suggest that it could be helpful to productivity, but shouldn't be focused on too much. After all, what really matters is the programmers skill, right?

tagged: faster typist better coder productive typing problem faster typist better coder productive typing problem

Link:

Nick Halstead's Blog:
Do faster typists make better coders?
Jul 25, 2007 @ 14:51:04

Nick Halstead asks an interesting question on his blog today - "Do faster typists make better coders?"

I have been able to touch type since about age 12 and can manage about 100 words per minute when faced with blocks of text to copy and even faster if I am just writing code. [...] Programming in C meant a lot more typing of parenthesis and a lot more thinking about the structure of the code.

PHP has introduced another set of typing problems with a lot more use of < > and a much higher mixture of variables/functions/parenthesis plus the added bonus of trying to remember a single function from a choice of 3000+.

Several of the comments on the post suggest that it could be helpful to productivity, but shouldn't be focused on too much. After all, what really matters is the programmers skill, right?

tagged: faster typist better coder productive typing problem faster typist better coder productive typing problem

Link: