Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Reddit.com: Avoid static methods at all costs? (testability)

Reddit.com: Avoid static methods at all costs? (testability)

On Reddit.com there’s a recent post questioning the (recently) common saying that PHP developers should avoid static methods when concerned about testability:

I get it: testing is important, and building your codebase in a manner that is easy to test should be a priority. However, sometimes I feel like I have to compromise on the elegance of my code in order to maintain testability. Cases where perhaps a static method makes sense, but end up having to perform some coding acrobatics in order to avoid it. Is this a common challenge, something many developers face and must balance between? Or am I misguided in how frequently static methods can be the most elegant solution (before taking testability into consideration)?

Answers point out a few things – that sometimes, state doesn’t matter and static is okay or that they can be used if the instance they return is always exactly the same, never altered.

Source: http://www.phpdeveloper.org/news/18523

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Posted Wrzesień 27th, 2012 in WEB and PHP Development.

Leave a response: