Page 4 of 5
Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 4:44 am
by VladSun
arborint wrote:I think it was Larry Wall who said that "PHP takes 'worse is better' to new lows" which if you don't understand it was a compliment.
http://www.oreillynet.com/onlamp/blog/2 ... php_5.html
Secondly, it's an overgrown templating system. People want to make dynamic webpages; they want something that lets them do that quickly and dirtily. They don't care about how well it is designed and engineered so long as it's just dead simple to get into. It's crap, but it lowers barriers to entry. In Perl, you'd have to learn the language and a templating system and a database interface and all of that separately. With PHP, you just learn a wishy-washy conglomerate of bits that makes your dynamic webpages work even if you barely have any clue at all. A few years ago, beginners would hack together horrible CGI code in Perl. Now they use PHP, and their concoctions are just a little less awful. Matt's Script Archive is dead; long live PHP.
It's a classic example of "worse is better".
According to my observations, most of the "big", "serious", etc. companies do not use PHP.
I think it has to do something with hundreads of thousands of lame, vulnerable and hackable PHP applications written by "developers" like the ones mentioned above ...
Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 8:10 am
by alex.barylski
controlling stuff is not a bad idea (buffer overflows anyone?), i just reckon you have to think hard about the real frequency and cost of the errors you make. there's a lot of attraction to being safe but don't let it become an attraction to the 'appearance of safety' for massive cost.
type-hinting IMHO is just a tool. Like the 'const' modifier in C++ or private, protected, public in most OOP languages. They simply prevent you from shooting yourself in the foot. Jenk has valid arguments as to why using access control or type-hinting 'can' lead to headaches, but they are not significant enough to tip the scale in his favour, IMHO.
Explicitly testing for type, in a language like PHP seems...hackish...useless...but type-hinting is *not* doing this...it's simply ensuring that a certain type is passed to a function parameter, which eliminates errors like I made above, such as getting the parameter order wrong.
The only other surefire solution is to pass arguments to a method as an associative array, thus removing the consequence of parameter ordering, otherwise, in a loosely typed language, this does remain a potential *difficult* to spot bug.
Jenk's primary concern (if I understand correctly) is that 'type' enforcement will somehow make unit testing or behaviorual testing more difficult, if not impossible, but I don't think that argument was confirmed with the example of testing I requested, if it was I missed it, sorry.
Cheers,
Alex
Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 8:14 am
by Jenk
It was confirmed, as the example I used was our very own project. We had to use a different tool entirely because of the problem.
There is no difference between these two:
Code: Select all
public function foo($obj) {
if (!($obj instanceof Class)) {
// etc..
}
}
public function foo(Class $obj) {
// etc..
}
save for a few keystrokes.
As for problems with testing and accessing... If that's not a show stopper for you, I would not want to work with/on any of your projects, to be frank.
Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 11:48 am
by Christopher
VladSun wrote:According to my observations, most of the "big", "serious", etc. companies do not use PHP.
I think it has to do something with hundreads of thousands of lame, vulnerable and hackable PHP applications written by "developers" like the ones mentioned above ...
I think your observations are mistaken. Several, if not many, of the biggest, most serious websites on the internet are in PHP. I addition companies like IBM, Oracle and Sun have long supported PHP -- even Microsoft recently. They wouldn't if there was no business market.
The fact that
"hundreads of thousands of lame, vulnerable and hackable PHP applications written by "developers" like the ones mentioned above" has little to do with whether big, serious web applications can be built with PHP -- and much more about the fact that those hundreds of thousands of applications were made possible because PHP makes web development accessible to many, many people who could not use other programming languages.
Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 12:05 pm
by kaisellgren
I agree with arborint. PHP is used in several big websites; e.g., Facebook (
http://www.facebook.com/home.php). It only proves how well PHP can perform on
vast websites and in fact, Facebook's traffic ranking is 4 at Alexa (
http://alexa.com/siteinfo/facebook.com); thus, it's pointless to say PHP wouldn't/couldn't be used in serious business or high-traffic websites.
Here is something that might be interesting:
Steve Grimm @ Facebook wrote:No clue if we¹re the largest installation, but Facebook has roughly 200
dedicated memcached servers in its production environment, plus a small
number of others for development and so on. A few of those 200 are hot
spares. They are all 16GB 4-core AMD64 boxes, just because that¹s where the
price/performance sweet spot is for us right now (though it looks like 32GB
boxes are getting more economical lately, so I suspect we¹ll roll out some
of those this year.)
We have a home-built management and monitoring system that keeps track of
all our servers, both memcached and other custom backend stuff. Some of our
other backend services are written memcached-style with fully
interchangeable instances; for such services, the monitoring system knows
how to take a hot spare and swap it into place when a live server has a
failure. When one of our memcached servers dies, a replacement is always up
and running in under a minute.
All our services use a unified database-backed configuration scheme which
has a Web front-end we use for manual operations like adding servers to
handle increased load. Unfortunately that management and configuration
system is highly tailored to our particular environment, but I expect you
could accomplish something similar on the monitoring side using Nagios or
another such app.
All that said, I agree with the earlier comment on this list: start small to
get some experience running memcached in a production environment. It¹s easy
enough to expand later once you have appropriate expertise and code in place
to make things run smoothly.
Can it get any more serious than that?

Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 12:10 pm
by sike
Jenk wrote:It was confirmed, as the example I used was our very own project. We had to use a different tool entirely because of the problem.
There is no difference between these two:
Code: Select all
public function foo($obj) {
if (!($obj instanceof Class)) {
// etc..
}
}
public function foo(Class $obj) {
// etc..
}
save for a few keystrokes.
As for problems with testing and accessing... If that's not a show stopper for you, I would not want to work with/on any of your projects, to be frank.
i would question the type hinting for a class rather than the type hinting itself. using interfaces for hints is a better way imho.
i really dont see a problem in using visibility modifiers in classes. if you employ unit testing and need to access internal variables for your tests then your classes and/or your tests are messed up because you should avoid to test for the internal state of objects. alway try to test the protocol/interface/contract. if you can't avoid that in some instances then you might add some fully test related methods. and they should be documented in some way.
i personally could not live without protected methods and properties because without them all that internal methods will pollute the interface (especially if your ide has auto completition). private on the other hand is totally uneccesary imho. same is true for final. that's were i see your point i guess because the only thing they do is unnecessary lock classes for extensions at some point.
cheers
chris
Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 3:30 pm
by VladSun
Several, if not many, of the biggest, most serious websites on the Internet are in PHP.
I didn't mean that "serious" and "big" applications can not be built in PHP, I meant that most of the companies (especially development ones) do not use it.
I addition companies like IBM, Oracle and Sun have long supported PHP -- even Microsoft recently. They wouldn't if there was no business market.
Well, Microsoft has a big piece of the business market but it doesn't mean that its products are superior than others.
... PHP makes web development accessible to many, many people who could not use other programming languages.
I think that "worse is better" principle is better only for people that *could* use other programming languages.
It's like shooting yourself in the foot in C++ and C#

Re: How do you feel about type-hinting
Posted: Tue Jun 30, 2009 4:22 pm
by Christopher
VladSun wrote:I think that "worse is better" principle is better only for people that *could* use other programming languages.
I think "worse is better" is what allows people who could *not* use other programming languages to develop using PHP. However, "worse is better" also provides advantages for people who *could* use other programming languages -- such as the ability to type-hint or not. PHP's type system removes an immense amount of drudgery from programming.
Re: How do you feel about type-hinting
Posted: Wed Jul 01, 2009 4:40 am
by Jenk
sike wrote:Jenk wrote:It was confirmed, as the example I used was our very own project. We had to use a different tool entirely because of the problem.
There is no difference between these two:
Code: Select all
public function foo($obj) {
if (!($obj instanceof Class)) {
// etc..
}
}
public function foo(Class $obj) {
// etc..
}
save for a few keystrokes.
As for problems with testing and accessing... If that's not a show stopper for you, I would not want to work with/on any of your projects, to be frank.
i would question the type hinting for a class rather than the type hinting itself. using interfaces for hints is a better way imho.
i really dont see a problem in using visibility modifiers in classes. if you employ unit testing and need to access internal variables for your tests then your classes and/or your tests are messed up because you should avoid to test for the internal state of objects. alway try to test the protocol/interface/contract. if you can't avoid that in some instances then you might add some fully test related methods. and they should be documented in some way.
i personally could not live without protected methods and properties because without them all that internal methods will pollute the interface (especially if your ide has auto completition). private on the other hand is totally uneccesary imho. same is true for final. that's were i see your point i guess because the only thing they do is unnecessary lock classes for extensions at some point.
cheers
chris
That's my bad.. should have used "Interface" instead of "Class" in my examplem, or even better.. just "Type".
However, again I want to take this to what is the real world.. rarely is anything done as accurately as that. A good book to read on this sort of subject is "Working Effectively With Legacy Code" by Martin C. Feathers. He talks about Object/Relationship Seams and so forth when trying to apply tests to legacy code.. and type-hinting and visibility restrictions make this much tougher. You are correct to assume that there may be an error in the design of a class that is under test if I must directly set an instance or class variable, but as my previous example of the dice class in
another thread gave.. sometimes it's essential to assert behaviour. Type-hinting is not much different to visibility restrictions, you are restricting to a certain type.. which can have its own problems, which pose very similar challenges in my experience, and are also just plain unneccessary.
Re: How do you feel about type-hinting
Posted: Wed Jul 01, 2009 5:44 am
by christinedawson
I do. It still won't get past type hints, unless you mock an interface.
Re: How do you feel about type-hinting
Posted: Wed Jul 01, 2009 3:51 pm
by DrTom
Jenk wrote:
However, again I want to take this to what is the real world.. rarely is anything done as accurately as that. A good book to read on this sort of subject is "Working Effectively With Legacy Code" by Martin C. Feathers. He talks about Object/Relationship Seams and so forth when trying to apply tests to legacy code.. and type-hinting and visibility restrictions make this much tougher.
This is an odd book for you to reference.... He specifically talks about typing to an interface and not a concrete class. By doing so, you allow yourself to lean on compilers/interpreters in the absence of tests. So basically he says the opposite of what you're saying.
Re: How do you feel about type-hinting
Posted: Thu Jul 02, 2009 4:30 am
by Jenk
because he knows that the majority of the world are using languages where you don't have the choice to not use type strict.

In that case, an Interface type is the lesser evil of a Concrete class type.
Re: How do you feel about type-hinting
Posted: Tue Jul 28, 2009 12:52 pm
by alex.barylski
I'm quite split on whether I want to bother with the extra typing and start specifying types in argument lists.
There is a lot of neat stuff you could potentially do with dynamica programming if you did specify type. Phemto for instance relies on type hinting to determine dependencies. Not sure exactly how that works, still trying to figure out, but the concept sounds quite interesting and I'm pretty sure wouldn't be possible (that elegantly) without type hinting.
I can think of several ideas like this, where type hinting had been used, more dynamic/meta programming could be employed to ultimately save you time in refactoring and possibly keystrokes overall.
Re: How do you feel about type-hinting
Posted: Tue Jul 28, 2009 3:46 pm
by koen.h
To be honest, I don't think I could use a framework that wouldn't use type hinting. Any method that requires me to open the documentation to check what needs to go in there feels wrong.
Re: How do you feel about type-hinting
Posted: Wed Jul 29, 2009 4:05 am
by Jenk
koen.h wrote:To be honest, I don't think I could use a framework that wouldn't use type hinting. Any method that requires me to open the documentation to check what needs to go in there feels wrong.
Or you could just run the app, and see which members are missing by information from the error message. I just don't get why people have to know everything before they have even tried running it.