Bug #11567 Updated: True Dynamic Binding and Public/Private
| From: | Mike dot Eggleston at michaelsmacshack dot com | Date: | Wed, 20 Jun 2001 15:54:35 +0000 |
| Subject: | Bug #11567 Updated: True Dynamic Binding and Public/Private | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-57407@lists.php.net to get a copy of this message | ||
ID: 11567
User Update by: Mike.Eggleston@michaelsmacshack.com
Status: Analyzed
Bug Type: Feature/Change Request
Operating system: Linux
PHP Version: 4.0.5
Description: True Dynamic Binding and Public/Private
I disagree with your comment on how dynamic bindings are used. The whole purpose of dynamic binding
is give a function whose purpose could be asked for in many different ways yet is asking to do the
same thing the ability to hide how it works from the programmer using it. In C++, there is a
function of exp, which could be sent four different methods:
int exp (int base, int exponent)
double exp (int base, double exponent)
double exp (double base, int exponent)
double exp (double base, double exponent)
If anything, it makes the programmers job easier to utilize this function because they only have to
remember ONE function, not four different ones accomplishing the same task.
Admittedly, PHP doesn't have data types in the traditional sense, however it should have
Dynamic Binding because one of the most fundamental rules of Object Oriented Programming is the idea
of hiding the how and just utilizing the functions and classes.
The same argument can be made for the public/private distinction. Adding this feature is an
excellent way to make sure that programmers do not mess with the logical code that you worked so
hard on. Also, it forces programmers to use the functions of the class, as the orginal programmer
percieved it.
I want to see PHP become the best Web Programming Language out there, and proper OOD techniques is
fundamental to getting there.
Previous Comments:
---------------------------------------------------------------------------
[2001-06-20 00:42:51] rasmus@php.net
I completely disagree with the concept of dynamic binding.
Calling different functions based on the number of arguments
is spaghetti code waiting to happen. PHP supports default
values for arguments which makes them optional. Your
would be much cleaner if written with defaulted x and y
arguments which you then check and if you have the default
value for x and/or y you would calculate the center value.
Or alternatively use func_num_args to see how many args were
passed. To me it is cleaner to collect the functionality for a function in a single function
instead of splitting it
out over multiple functions. Imagine trying to debug some
code and you end up looking at the wrong function just
because you counted 17 arguments instead of 18.
As for the public/private issue. Sure, from an OO purity
perspective it would be nice. But it is functionally irrelevant. ie. your code would not work any
better or
worse by having the public/private differentiation.
---------------------------------------------------------------------------
[2001-06-19 22:05:53] cynic@php.net
function drawMe()
{
if( 2 == func_num_args() ) {
doStuff( func_get_arg(0) , func_get_arg(1) ) ;
} else {
doStuff( $defaultX , $defaultY ) ;
}
}
private vars/methods would be good... :)
---------------------------------------------------------------------------
[2001-06-19 15:10:06] Mike.Eggleston@michaelsmacshack.com
Ok Folks. I am really happy with PHP thus far. However to make it a true Object Oriented Language
you absolutly need Dynamic binding. This would be such a huge boon for us developers who love to
work within classes. Such as:
// Inside the class Circle
function DrawMe() {
// Getting Ceter Coords..
DrawMe($centX, $centY);
}
function DrawMe($x, $y) {
// Draws the circle at $x, $y
}
// End of code demo
This kind of ability can be extremely huge, if you use it right. Also, it allows for developers to
make a module extremely flexiable and powerful.
Secondly, I think that we are missing public and private sections of the OOP world. In the above
example, I would have the functions public, and the data structures inside of it totally hidden (or
private) so the programmer who is using my include just has to deal with the interface, and
can't touch the actual data. That is strength and beauty of encapsulation.
I just thought you may want to hear this, and I am hoping to hear from you guys (and gals) that you
are hard at work to implement it and it is coming soon.
Thanks for reading my rant!!
Mike Eggleston
AmeriGroup
Mike.Eggleston@michaelsmacshack.com
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=11567