PDA

View Full Version : Microsoft compares ASP.NET to PHP


mordred
05-08-2003, 11:44 PM
It was a nice attempt. Some say 'interesting', some say 'lacking', some say 'FUD'... here it is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/phpvsaspnet.asp

It's hard to judge the article without having any real development experience in ASP.NET, so I can only state that some things were simply not mentioned - e.g. it's true that PHP is not a fully OOP language, and that objects are passed by value by default. However, they do not mention that the developer can influence that by using references. Sometimes that what's not said in an article is even more interesting.

At least this article shows that MS considers PHP to be a competitor. ;)

Spookster
05-09-2003, 02:57 AM
Well being able to pass by reference is not all that great an idea. The only time you should actually do that is if you need to return more than one value from a function or if the data you need to pass to the function is very large. Opening up the scope or basically giving global scope to all data is very bad. That is just asking for trouble. In c++ you can pass by reference. When java was created they took c++ and removed most of the features that had the potential to cause major problems....one of them being able to pass by reference like c++ does.

x_goose_x
05-09-2003, 04:58 AM
Make sure you rate the article at the end of the page...

mordred
05-09-2003, 08:55 AM
Hm Spookster, I'm not sure I agree with your points about passing references. If you have an object and want to pass that to a function that is supposed to modify some properties of that object, how do you make sure that these changes are done to the object passed without passing a reference to it? If you pass by value, you modify the properties of a new second copy of the original object - which is seldom what you really want to do. Isn't passing references in PHP roughly the same as in Java? How do you give global scope to data if you pass it by reference?

Spookster
05-09-2003, 12:06 PM
You disagree with me? How dare you!! :D This is actually an age-old argument. Some people still think that passing by reference is a good idea. In the grand scheme of things however it is not. That is why Java removed that capability. There are many factors involved with why it is a bad idea. Readability, writability, security, reliability. I suppose we should actually define pass by reference though so we are talking about the same thing. In programming we have a few different modes of passing parameters.

In Modes:
Pass by value

Out Modes:
Pass by result

In/Out Modes:
Pass by reference
Pass by name

Pass by name and Pass by result are not really used anymore in modern languages so I won't discuss those. The two most common now are obviously Pass by value and Pass by reference.

Pass by reference is a way that was added in C++ where the actual parameter is a pointer to the original data and gets passed into the formal parameter as a pointer thus when you make changes to that pointer you are making changes directly to the original value.

Pass by value is the preferred way in which the actual parameter is passed into the formal parameter as a copy therefore you modify a copy of the original value so then if you want to modify the original you need to return that value back to the caller and reassign the value to the original.

This may seem like a lot of work when you could simply just directly change the original however that is also an unsafe way to do things. You could inadvertantly change the original or change it while another method is using that value. You should never give methods wider access to data then what they need. You should keep the scope of a variable as narrow as possible. This improves both readability, writability and security which in turn provides reliability.

mordred
05-09-2003, 01:24 PM
I stand corrected, you great god of terminology... now I finally realize what you were saying. Yes indeed, in Java only values of object references are passed as parameters to a method. However, I got confused by your initial comment but now I see that I was thinking in PHP terminology, where also the manual speaks of passing references as parameters (not by, just reference handles comparable to Java IMO). This example shows both mine and your points:


class Example
{
var $foo = 'bar';
}

$test =& new Example();

function make(&$obj) {
$obj->foo = 'hello';
unset($obj);
}

make($test);
var_dump($test);


A reference handle is passed to the function make, which can influence the attributes of $test directly. But unsetting the argument does not cause the object outside the function to be destroyed.
And that was the critique of my first post, that the study seemed to imply that objects were completely and inadvertently copied into a function argument in PHP, and that's clearly not always the case. My fault that I refered to that as "passing by value".

Darknight
05-09-2003, 09:39 PM
MS is feeling the love.