I want to make tub thumper more organized code wise. right now, it uses neither functional or OOP, not sure what you call it. run time programming? I do use a few functions, for tables and stuff.
Now, what I want to do is, organize it all, and put each function in it's own file. reply functions (the form to reply and to actually insert the data, edit), topic functions (ditto). table functions so it's themeable. display functions (topic, forum list, private messages, etc)....
anyway, you get the idea.
The reason I'm not sure about using OOP, is because there would only be one instance of each, so would it really be useful?
Also, a question about OOP. what's with $this->varname? why can't you just say $varname?
Thanks!
jemfinch
07-30-2001, 01:23 AM
PHP is a bad language both for OOP and Functional Programming. In fact, for anything but most web-centric page generation out there, PHP is some other common language's inferior.
$varname would be a global variable, whereas $this->varname would be an instance variable, allowed to change within any given instance of an object.
Jeremy
Sweede
07-30-2001, 02:26 AM
Originally posted by jemfinch:
<STRONG>PHP is a bad language both for OOP and Functional Programming. In fact, for anything but most web-centric page generation out there, PHP is some other common language's inferior.
$varname would be a global variable, whereas $this->varname would be an instance variable, allowed to change within any given instance of an object.
Jeremy</STRONG>
What are you talking about ?
PHP is an excellent language for Web programming and with the advent of PHP-GTK and the ncurses functions in php 4.0.7 it is becoming more of a general scripting language for normal use (and far simpler to use/learn than perl).
Granted PHP 3 doesnt do OO to well, PHP 4 is far better and faster.
Using OO generates more re-usable code IF AND ONLY IF you plan ahead waaay before you code (draw it out).
OOp is also really good for storing items such as themes or session data.
functions like get_posts() or write_post_data() are functional programmed (no oops)
your class data would include themes.
$html_page = new PageStart("Page title");
$userinfo = new StartUserSession();
$userinfo = GetUserID($HTTP_SESSION_VARS['sessid']);
$number = get_data_from_userid($this->userinfo);
i personaly dont find OO all that nessecary, mainy causs i dont know OO all that well :)
jemfinch
07-30-2001, 06:59 AM
Originally posted by Sweede:
PHP is an excellent language for Web programming and with the advent of PHP-GTK and the ncurses functions in php 4.0.7 it is becoming more of a general scripting language for normal use (and far simpler to use/learn than perl).
If by simpler, you mean, "It has fewer features", then sure, I can abide. If by simpler, you mean "there are fewer syntactical mishaps", then I can abide. But if by simpler, you don't mean "it doesn't support some of the higher level concepts that perl does", then I can't abide: where are the higher order functions? Where are the separate namespaces for modules?
Granted PHP 3 doesnt do OO to well, PHP 4 is far better and faster.
I'm really not all that concerned with speed in a scripting language. PHP4's OO module isn't good -- it's basically C structs with function pointers. Nothing to be impressed by, IMO.
Using OO generates more re-usable code IF AND ONLY IF you plan ahead waaay before you code (draw it out).
No, using OO generates more re-usable code anytime you want to refactor the implementation of some functionality without affecting the interface. It's for the times that you don't plan ahead well that OO helps: those are the times where OO's enforcement of adherence to public interfaces has the greatest effect.
functions like get_posts() or write_post_data() are functional programmed (no oops)
Neither of those are functions. They're both procedures. The difference is fairly academic in practice, but note the name of both: they both have side effects. A true "function" operates on one domain and results in another domain, and has no side effects: the net effect of the function is always the same given the same input to the function.
PHP is not even close to a functional programming language. Where's anonymous functions? Where are higher-order functions? Where's tail recursion optimization?
$html_page = new PageStart("Page title");
$userinfo = new StartUserSession();
$userinfo = GetUserID($HTTP_SESSION_VARS['sessid']);
$number = get_data_from_userid($this->userinfo);
I can't say I like this horrible mish-mash of procedural and object-oriented code. Why did is PageStart and object? Why are you calling "get_data_from_userid" instead of having the UserInfo object offer a method "get_data"?
i personaly dont find OO all that nessecary, mainy causs i dont know OO all that well :)
That's fine; a long time ago I would've said the same thing. There are several languages freely available that make OO much more natural and easy to learn properly, than PHP.
PHP can't even stretch to be called a functional programming language.
PHP supports so few high level concepts in OO and functional programming that it's perilously close to being relegated to the "toy language" department, at least in my mind. The only place I'd consider it useful is in web programming, where its lack of support for high level programming concepts is less problematic (due to the nature of the problem.)
Jeremy
PS: What do you want to gain from writing an infobot/blootbot in PHP?
Sweede
07-30-2001, 10:56 AM
Originally posted by jemfinch:
<STRONG>
PS: What do you want to gain from writing an infobot/blootbot in PHP?</STRONG>
umm, experiance in PHP to the point where i have a good reference to get a PHP programming job that i have seen far far more than Python programming jobs that pay more money than some perl jobs that ive seen.
why do you program in python ?
david
07-30-2001, 05:03 PM
jemfinch: ok... :)
anyway...
maybe i will try perl, but php has done me well up until now, i have yet to find anything I need to do that php can't do
Sweede
07-30-2001, 10:27 PM
please dont use perl, its a whole lot slower than php and is not designed for web applications like php is.
you dont need to use OO in php, look at phpBB and that commercial one, (vbb?).
both of those boards blow the UBB and perl away in speed, power, and scalability.
jemfinch
07-30-2001, 11:56 PM
Originally posted by Sweede:
please dont use perl, its a whole lot slower than php
This is absolutely, positively not true. Feel free to offer some evidence, though.
Perhaps, if you're interested in learning PHP better, you can use the standalone interpreter and write up the different benchmarks for Doug Bagley's Computer Language Shootout (http://www.bagley.org/~doug/shootout/), and see for yourself that your claim isn't true.
and is not designed for web applications like php is.
That's right, Perl is designed for serious programming of all kinds, not just web applications.
both of those boards blow the UBB and perl away in speed, power, and scalability.[/QB]
That's funny. The busiest bulletin-board type site I know of is Slashdot, and that definitely has more capabilities and is more scalable, I imagine, than either of the two BBS systems you posted. And it's written in Perl.
It's one thing to like PHP. I don't understand such a preference, since PHP is really inferior to several freely available and excellent programming languages, but I have no problem with a person having a preference. But don't spread falsehoods about other languages, that's just not right.
Jeremy
Rob 'Feztaa' Park
07-31-2001, 10:54 AM
I like PHP. It was easier for me to learn than perl (I know a little of both, but more of php). It does everything I need it to do for my website, so it works well.
I realize that php is tailor made for web stuff. I wouldn't dream of trying to write a php script that DIDN'T output an HTML page in the end. (can php even do anything else?)
Perl may be an all purpose language, but php is specialized for web content, which in my mind means that it ought to be better at it...
Salmon
07-31-2001, 02:18 PM
Originally posted by Sweede:
you dont need to use OO in php, look at phpBB and that commercial one, (vbb?).
both of those boards blow the UBB and perl away in speed, power, and scalability.
Ok, I'm a huge fan of PHP for web-based applications, but this is completely wrong on all counts. Because PHP is so easy to learn and use, alot of people that "know PHP" really don't know anything at all about it. These kinds of comments don't help things.
First, UBB uses a flat-file database (or at least it used to). That's why the other boards you mentioned might be faster. It has nothing to do with Perl vs. PHP. And the comment about scalabilty . . . huh? How are any of them more scalable than the rest?
Second, the Perl vs. PHP speed issue that you are mentioning -- is that for the PHP module vs. the Perl executable? Well of course the apache module will probably be faster. It's also completely unsuitable for any kind of serious application on a shared server, which most people use.
How are you going to run your scripts in a secure enviroment using the PHP module? You can't, although this is a detail that most "experienced PHP developers" completely ignore (or rather just don't know anything about). No, you have to use the PHP executable. Show us some actual numbers on that comparison and then maybe you'll have some evidence to support your claim. My guess that we'll probably never see such supporting evidence.
Again, I really like PHP for web-based applications, but that's what it was designed for. That's its strength. Off the web, there are *much* better alternatives.
And since we're on the edge of a PHP vs. Perl war . . .
You like the database connectivity in PHP, yes? It sucks. Try Perl DBI on and you'll see how much.
XML parsing? PHP has all those nifty built in functions. They're great right? Try Perl's XML::Parser Module. PHP can't compete.
Etc.
[ 31 July 2001: Message edited by: Salmon ]
nanode
07-31-2001, 05:21 PM
I had composed a big long flame-post and then my browser crashed...
I guess someone will get spared this time :)
david
07-31-2001, 10:10 PM
Originally posted by nanode:
<STRONG>I had composed a big long flame-post and then my browser crashed...
I guess someone will get spared this time :)</STRONG>
who's side was it for though? :)
Ninja-Penguin
08-08-2001, 05:54 PM
No one seems to have answered your original question david. If you want to have functions in different files save them as .lib files and then put them into your scripts using the include() function. The syntax is
include(filename.lib)
This will include all the functions in that file and you can call them from in your pages as u usually would.
functionname(param1...)
make sure all the include statements go at the top of your code
hope this is of some help
nanode
08-09-2001, 02:39 PM
PHP isn't a complete and proper language when compared to things like Java and Python, but it is sure nice for webpage scripting.
It's fast, most programmers understand the syntax and there are a lot of included functions that are useful and relavent to http server-side scripting.
I've only used classes a few times with PHP - not because PHP wouldn't be good at it, rather OOP is not as useful in a web scripting paradigm.
I do some JSP work as well, and aside from utility classes and data encapsulation, you don't leverage all the aspects of OOP in a webpage.
However, if you plan on making extensive libraries for the code in your webpages to use, then OOP is the way to go.
jcrowe
08-09-2001, 06:48 PM
I think that nanode started to make a good point. I think that a mistake is being made by comparing apple sauce to apple juice. If you are going to compare PHP to something I think that it should be compared to that which fills the same gape. ASP, Cold Fusion, JSP and PHP are three technologies that I think are able to be compared and contrasted. Likewise, Perl and Python would also be two scripting languages that could be fairly compared. I think that when you start to compare perl and php, you run into problems. The two languages were made to fill two differant niches. Perl was not made for the sole purpose of web scripting. It can function in the web scripting relm, but wasn't intended for that function. PHP on the otherhand was created with the sole intention of being used for web scripting. Since it's creation it has filtered into the relm of general scripting languages. PHP may not have all of the bells and whistles that other programming languages have, but I know enough to say that it has what it needs to preform as a great web programming language.
As for the original poster. I would stick to writing functions. Trying to make php fit into an OOP mold will usually make your job harder than it needs to be.
justlinux.com
Copyright Internet.com Inc. All Rights Reserved.