 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPImpact Blog: No need for set/get methods in Python
by Chris Cornutt August 18, 2008 @ 12:06:37
Federico compares two languages in this new post to the PHP::Impact blog today - PHP and Python - in their need for "getters" and "setters".
Python code doesn't typically use the get and set methods so common in PHP. Normally, when writing PHP code, you carefully protect your instance variables by making them private, so callers can only interact with them via getter and setter methods. [...] Python's solution to this problem is more readable, it has a construct called a "property".
He compares two blocks of code that do the same thing - set properties on the object with the PHP side doing a bit more error checking (seemingly) than the Python side. They both apply a title property to a book object.
voice your opinion now!
python compare getter setter example
Lars Strojny's Blog: Antipattern the verbose constructor
by Chris Cornutt July 31, 2008 @ 10:29:14
In this new post from Lars Strojny, there's a discussion of an "antipattern" - using the constructor for more than it was intended, the "verbose constructor".
Constructors are often used to shortcut dependency injection and parameter passing on instantiation. This is a valid practice and often leads to shorter code. [...] Instead of creating a new instance of "Money" and calling three setter, everything can be done compactly in the constructor. [...] So for the money object this works pretty well. The code is easy to read, but wait, the first argument can be grasped easily, the second too, but the third? It is not too obvious that it is a divisor is passed.
He compares three different ways to get the data into the class - the already-mentioned parameters in the constructor, passing an array into the constructor and using full getters/setters to push the data into the right places (with fluent interfaces even!).
voice your opinion now!
antipattern verbose constructor array getter setter
Debuggable Blog: Programming Psychology II Private methods
by Chris Cornutt July 08, 2008 @ 08:44:58
According to Felix Geisendorfer's newest post on the Debuggable blog, he thinks that "private and protected methods and properties are one of the most stupid concepts of OOP."
This is a thought I first shared at CakeFest Orlando this year, but could not explain properly at the time.
He illustrates with an example of a protected "balance" variable in a BankAccount class. Sure, it's marked as private but less skilled programmers might not use it that way. He recommends a method without the getters/setters to help make the usage of the variable a bit simpler. He also suggests that using protected/private scoping helps to promote "crappy code" - using them to provide a sort of protection for code that you either don't want getting used or hiding it away so the API can't get at it.
voice your opinion now!
private method protected bad code concept stupid getter setter
Alex Netkachov's Blog: Are setters evil?
by Chris Cornutt June 17, 2008 @ 09:36:03
Alex Netkachov has posted his own response to this opinion on the Typical Programmer on getters and setters in object-oriented applications.
"Do not use getters and setters" looks like a hastily advise, but its meaning is very important and it is "do not break encapsulation", which moves us to the question what the encapsulation is.
He notes that encapsulation is, in essence, hiding parts of the code away so that the user/other coders only see a little bit of the magic that happens. He argues that getters and setters are a valid part of the encapsulation process and that designing a good, easy to use system almost requires them.
voice your opinion now!
setter getter object oriented programming encapsulation
Typical Programmer Blog: Doing it wrong getters and setters
by Chris Cornutt June 16, 2008 @ 11:19:17
According to this new post on the Typical Programmer blog, using getters and setters in your scripts only adds in a bit of unnecessary coupling and complexity to your scripts that you just don't need.
Today most of the popular programming languages support objects, limiting scope, modularity, passing by value, and sophisticated built-in types. There should be no reason to deliberately expose an object's data to the rest of the code because the language can enforce encapsulation and data hiding.
While not specific to PHP, the post does recommend against them because of one simple reason common to all languages that make them possible - they "break the encapsulation OOP offers". For them, they're like a cheat to get around bad coding practices and are not needed to make a successful application work.
voice your opinion now!
getter setter break object oriented encapsulation scope bad
Jeff Moore's Blog: Let Your Properties be Properties
by Chris Cornutt May 10, 2007 @ 07:11:45
In a recent post to his blog, Jeff Moore advocates the philosophy that, in your OOP application development, you should "let your properties be properties".
Some times there are some ancillary methods to deal with unsetting, checking for existence, setting via an array, or dealing with references in PHP 4. They can really clutter up the definition of a class. That's not good.
[...] I think the idea is to make the class extensible. But PHP is really ok with just setting new properties on a class. So why not just do this?
He argues that getters and setters in a class are less useful than just setting the property yourself. Using the property name as part of the interface, though (like getting the $obj->foo value with $obj->getFoo) is stil clean enough to be useful.
voice your opinion now!
properties class oop setter getter object properties class oop setter getter object
|
Community Events
Don't see your event here? Let us know!
|