|
|||||||
New to SitePoint Forums? Register here for free!
|
| View Poll Results: How well would Java's class library API serve as a base for a PHP implementation? | |||
| It would work well with little modification. |
|
16 | 27.59% |
| It would work with significant modification. |
|
19 | 32.76% |
| A PHP class library would be better off not basing itself off the Java class library API at all. |
|
14 | 24.14% |
| Unsure or not familiar with Java's class library API. |
|
9 | 15.52% |
| Voters: 58. You may not vote on this poll | |||
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Java API as base for PHP library?
I agree that PHP needs a library of small, reusable objects. What I am wondering is if the other people advocating such a library (Harry, lastcraft, and many others) think about using the Java class library as a starting point for the API.
I think the Java class library API is well designed and would serve as a great starting point for development of a PHP implementation. Whenever I am writing library-type classes for PHP applications, I almost always end up creating classes that are a method to method copy of the corresponding Java library object's API. I'd like to hear any arguments for or against using the Java class library API as a base for a library of small, resuable PHP classes. |
|
|
|
|
|
#2 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2000
Location: Chico, Ca
Posts: 1,128
|
I am not much of a PHP developer but it would be a logical starting point since a lot of people are familiar with java, and it would create a easy transition between both lanuages.
Chuck |
|
|
|
|
|
#3 |
|
SitePoint Zealot
![]() ![]() Join Date: Jul 2002
Location: Portugal
Posts: 143
|
I've voted the second option, there some java designs that don't have meaning in php because of overhead.
For my work when i need some task to be acomplished i first look in java api so i can have the work done quickly. And by now i have several classes ported from java. There is JPHP an php library ported form java, but i don't like it at all because of some reasons, one of them is this PHP Code:
|
|
|
|
|
|
#4 |
|
SitePoint Victim
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: London
Posts: 2,273
|
Hi...
I think a better approach is to cherry pick, but I see the higher level designs for things like HTTP, XML, Persistence (e.g. JDO) coming from there. Java is just so far ahead of the game in the resources available; JUnit has been cloned for lots of languages for instance. That said, some of the smaller interfaces can be stolen from Python as they will be cleaner. Although PHP is about to get type hinting a straight Java copy would overuse this perhaps. I guess we are all waiting for PHP5. ![]() yours, Marcus. |
|
|
|
|
|
#5 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Marcus, I agree that the high level designs should come from Java. I think the low level designs are where the most thought needs to be directed, at least initially. This raises a number of questions:
1. Should the theoretical library have objects for primitive types such as String, Integer, etc. that can be used like their Java equivalents? It would be nice to be able to do $myString->startsWith('Foo') and other operations currently encapsulated in the PHP string functions with objects. 2. Related to #1, should the library contain classes for Arrays, HashMaps, etc.? PHP's array support is top notch and I'd be interested to hear what people think about wrapping it in collection-type classes. 3. Should all classes in the library extend one base "Object" class like they do in Java? Does anyone have any questions/answers/comments/insights on those questions? I think how a PHP class library answers those three questions will have a huge impact on who uses it and how widespread it is accepted. I also think there isn't a way to answer those questions that is going to please almost everyone. By the way, does Python have anything like Javadoc where I could browse its APIs online? I think this project should be written from the start in PHP5. It just has too many new OOP goodies to pass up. Besides, by the time a library could be finished, PHP5 will be stable. |
|
|
|
|
|
#6 |
|
sitepoint wombat
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2000
Location: Perth Australia
Posts: 1,722
|
could you not add an extra option to the poll ..
5) Just use JAVA ? ![]() |
|
|
|
|
|
#7 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
firepages,
You've now got me considering my choice of PHP over Java. I don't want this to turn into a programming language flame war, but here are some thoughts I had: PHP is very good for quickly building web-based applications. I found it very easy to jump in to the language and build some simple sites. But now as I've become what I would consider an "advanced" PHP user (I code PHP every day at work) I find myself searching for PHP solutions to problems already solved in Java. Some examples: 1. I'm still looking for a "perfect" Javadoc solution for PHP. It seems PHPDoc (http://www.callowayprints.com/phpdoc/) is just what I want but I am having a lot of problems getting it to work. I may end up having to write something like this myself. 2. I haven't found a solidly-designed library of small, reusable classes for PHP like the libraries included with Java. Currently I think a new development project needs to be started to fill this gap. And yes, I've looked at Eclipse. 3. The selection of frameworks for PHP application development is not to my liking. I've examind Eocene, Phrame, Fusebox, and many others and none fit my exact needs. I discovered WebWork (for... yes, Java) (http://opensymphony.com/webwork/) is just what I wanted and I ended up implementing it in PHP myself. 4. Although numerous, not many of the templating solutions for PHP match the flexibility of Java tag libraries. The best templating solution I've found for PHP, PHPTAL (http://phptal.sourceforge.net/) works just like a Java taglib but is not yet entirely stable. Quick! Someone bonk me over the head and remind me why I use PHP! |
|
|
|
|
|
#8 |
|
sitepoint wombat
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2000
Location: Perth Australia
Posts: 1,722
|
Hi Cyngon , well I would hate to push anyone to the dark side [img]images/smilies/wink.gif[/img]
BUT , PHP is not JAVA , nor IMO should it be , all languages have pros and cons , the existing codebase for JAVA is obviously one of its pros. Is it a con therfore for PHP ? , I personally don't think so , porting of JAVA solutions to PHP will also port over its problems, the 'cons' of JAVA do not all revolve around a JVM and hardware. Though I think it often boils down to philosophy.. example , & I had this argument recently with an applications original designer where I was reworking existing PHP code ... I mostly ignored the file manipulation classes that were available as I saw no point in loading ,instansiating and manipulating an object when include, readfile , implode($filename) etc did the job for me, even saving the file seemed pointless via the available classes, we wont even go into iterating over a returned array from a file [img]images/smilies/wink.gif[/img] ...a simple and daft example I know but there are a lot more lurking away which itself leads to templating, which has been discussed a thousand times , and I fall on the side of the fence that says that you dont need templating solutions if you are using PHP it defeats part of the purpose of PHP. I am not suggesting that I do not appreciate the merit of and the logic of java-like solutions , I just do not think that a direct port of such logic to PHP is always in itself logical. There are surely ways to implement in PHP the design patterns & advanced OOP techniques that HarryF & friends here are showing and discussing here that do not revolve around __clone(JAVA) ? If not then JAVA must surely be the alternative. |
|
|
|
|
|
#9 | |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Aug 2002
Location: Winnipeg, Manitoba, Canada
Posts: 214
|
Quote:
Cheers, Keith. |
|
|
|
|
|
|
#10 | |||||
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Quote:
Quote:
Quote:
http://www.faqs.org/docs/ZopeBook/ZPT.html Quote:
Quote:
|
|||||
|
|
|
|
|
#11 | ||
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Posts: 848
|
Quote:
Java Problems A Java Critique Java Good and Bad Java is statically typed where as PHP is dynamically typed. This makes a difference in how one might organize a class library, as well as in how one might implement classical GoF design patterns: Are Dynamic Languages Going to Replace Static Languages? Strong Typing vs. Strong Testing Benefits of Dynamic Typing Smalltalk is dynamically typed as is PHP: Smalltalk vs. Java From Why does Dynamic Typing really matter?!?: Quote:
|
||
|
|
|
|
|
#12 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Great links, Selkirk! That's exactly the kind of information I was looking for.
I'm already an owner of Design Patterns and I'm going to pick up a copy of Design Patterns Smalltalk Companion ASAP. I'll post my thoughts after I finish reading and digesting all that information. |
|
|
|
|
|
#13 | |||||
|
SitePoint Victim
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: London
Posts: 2,273
|
Hi...
There is a lot of stuff to digest in this thread so I'll have to work through one post at a time. Quote:
Quote:
Quote:
Quote:
Quote:
So are you planning to start such a project? ![]() yours, Marcus. |
|||||
|
|
|
|
|
#14 | |||
|
SitePoint Victim
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: London
Posts: 2,273
|
Hi...
Quote:
Quote:
Quote:
yours, Marcus. |
|||
|
|
|
|
|
#15 |
|
SitePoint Victim
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: London
Posts: 2,273
|
Me again!
On a more general note, the organising of the authors would have more of an impact on a library than any early design decisions. Here are my current (rather random) ideas... 1) Shared code ownership. It forces code review and cooperation, rather than a single person owning a package and effectively freezing it. Anybody is allowed to edit your code. If that frightens someone then an examination must be made of their motives. 2) No attribution of authors. If there is less vested interest in the codebase the goal becomes the utility of the library and nothing more. 3) Completely archived discussion during construction. People are more willing to allow people the free editing of their code if they talk to them often. No rudeness and no private e-mails. 4) If nobody understands something out it goes. Code has no reuse if nobody ever reuses it. That means examples or docs or the writing of stuff thats intuitively obvious. 5) Refactoring by someone other than the person that wrote the first draught. It forces two people to have written everything and means that there is some redundancy if someone drops out for a bit. Libraries written by a single person tend to be quirky. 6) Fine grained unit tests shipped with the code. You cannot refactor without them and they reduce necessary documentation by effectively providing interface examples. 7) Always responding to users comments. Usability is important and you only get this from the users. The customer doesn't always know best, but being forced to justify a position also forces a constant reevaluation of it. 8) A clear tiering of code from stable down to experimental. 9) Refactoring to reuse other library objects. There is a limit to this because you don't want to force people to use the whole library for just a few classes. If the library were decomposed properly the issues should not be major. 10) No framework stuff. As I said, pretty much random ideas. ![]() yours, Marcus |
|
|
|
|
|
#16 | |
|
Sidewalking
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2001
Location: Philadelphia, US
Posts: 2,241
|
Quote:
![]() Agreed on all counts. ![]() * Re:the Java library idea - I think Python would be a better start. Like PHP, it's dynamically typed, so that issue wouldn't be a stumbling block. The library has decent scope - not too narrow, not too wide, and is very easy to use. Python Module Index |
|
|
|
|
|
|
#17 | ||||||||||||||
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
I'm still digesting the information presented by Selkirk but I thought I'd comment on the ideas Marcus presented now.
Quote:
Quote:
j/kQuote:
Quote:
Quote:
Quote:
Quote:
Quote:
How does the dynamic versus static typed issue play in to class autoloading? By class autoloading are you talking about what PHP5 will have with it's __autoload() callback? Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
||||||||||||||
|
|
|
|
|
#18 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Also, is there online documentation for the Smalltalk class library like there is for Python and Java?
|
|
|
|
|
|
#19 | |
|
Sidewalking
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2001
Location: Philadelphia, US
Posts: 2,241
|
Quote:
|
|
|
|
|
|
|
#20 | |
|
Sidewalking
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2001
Location: Philadelphia, US
Posts: 2,241
|
Quote:
|
|
|
|
|
|
|
#21 | ||
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Quote:
Quote:
|
||
|
|
|
|
|
#22 | |
|
sitepoint wombat
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2000
Location: Perth Australia
Posts: 1,722
|
Quote:
note I do not dismiss file manipulation classes as pointless , I would use them for more involved operations , but abstracting away file() etc seems still to defeat the point (of PHP) for me in many circumstances and for me harder to read . I wont try and get into the other stuff as it whooshes gently over my head ![]() |
|
|
|
|
|
|
#23 | ||||||||||||
|
SitePoint Victim
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: London
Posts: 2,273
|
Hi...
Well, thanks for reading through this stuff in such detail. You have already put more thought into it than I did writing it .Quote:
Quote:
Actually I just liked the quote.Quote:
Quote:
Quote:
Quote:
Quote:
![]() JDBC is of course part of Java from day one, I am really thinking of JDO. That said I would be nervous about building this because if you go platform independent here you will start to make compromises on the database, which could be too far reaching for a base library. Better I think to pull in MetaBase, PEAR, ADO or whatever your taste is. Quote:
Quote:
Quote:
Quote:
Quote:
Either way you are a lot safer with the test suite. Another factor in favour is the speculative refactoring. You do a big change and see how much goes red. This gives you a handle on how hard this refactoring is going to be. You can then break it into smaller steps if it is a goer. Unit tests take away the fear of change. yours, Marcus. |
||||||||||||
|
|
|
|
|
#24 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Aug 2001
Location: Livonia, MI, USA
Posts: 556
|
Ok, based on this thread here are some proposed design guidelines for the PHP class library:
Note: I'm writing this using absolute language ("will" instead of "should"), please do not let this deter you from disagreeing with and commenting on these points. That is just the easiest way to phrase my ideas. 1. There will be a String class. The String class will be the only place in the class library's code where the PHP string manipulation functions appear. However, all public methods in the class library that are passed strings will accept primitive strings and convert them to String objects internally if needed. Code using the class library will never have to convert a string primitive into a String object just to gain the ability to call a method in the class library. 2. Other classes in the class library will convert strings to String objects if they need to manipulate strings in ways beyond what is available with just operators. For example, if a function only has to append to a string it must use a string primitive and the .= operator. If a function must get the substring of a passed string is must convert the primitive string to a String object and then call the appropriet method of the object. Basically String objects will be instanciated by other classes in the library if and only if they are needed. 3. The same rules expressed above for Strings apply to Arrays. The Array class is the only place in the class library's code where the PHP array functions can appear. Again, other classes in the library should convert native arrays to Array objects if and only if they need to manipulate them in ways beyond what they can do with the native operators. 4. There will not be an Object class that all classes in the library inherit from. Based on my understanding of the differences between strongly typed and dynamically typed languages this is unnessecary in a dynamically typed language like PHP. Please critique and post comments. Also, writing this provoced some questions: Should there be classes for Integers and Floats? At first glance I thought no but then I am wondering how mathematical functionality should be built in. Should there be an Integer class with an getAbsoluteValue() method? If not, where will that functionality go? Does it need to be included in the class library at all? Any ideas/suggestions? |
|
|
|
|
|
#25 | ||
|
Sidewalking
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2001
Location: Philadelphia, US
Posts: 2,241
|
Quote:
Quote:
|
||
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 05:29.









j/k


Linear Mode
