Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pros/cons of script languages

Status
Not open for further replies.

bclt

Programmer
Mar 13, 2005
363
GR
Can anyone tell me which is better? JavaScript or PHP. Every language has its benefits so both are good. So, for what kind of web apps should i use JS or/and PHP?

 
PHP is server-side language. Javascript is primarily used client-side.

Unless you think about JScript (M$ server-side Javascript-like language), this is like comparing apples and oranges.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 

Do you mean client-side JavaScript, or server-side JavaScript?

You cannot really compare client-side Javascript and PHP - one runs on the browser, one runs on the server.

If you are talking about both server-side, then it really is personal preference.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I've no experience in programming for the web. Can you explain to me what server/client side means ? I know this question is strange (noob better) ...
 
Client-side means that the code will execute on the client (i.e. web browser, user agent, etc). Basically, the code will be run on the user's computer.

Server-side means that the code will execute on the server (and within the context of the server).

For example, if you had code to get the time, it would give you the time on the server if run server-side, and the time on the user's computer if run client-side.

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I get your point, but listen: i make a web page (html) and i use javascript. I upload the page e.g via ftp on a remote server. There scripts that will run are server or client side?
 

If it is JavaScript in an HTML page, added using the SCRIPT element, then it will be client-side script - even when uploaded to the server (it runs when it is downloaded to the users pc).

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Hmm.. so if i create a file with name file.js and i call it in the page, e.g form action="file.js" this is also client-side? I made a simple page with a submit button and the above form action and it supposed to run the script, but the file download dialog appears. To be executed the script i must press "open
 

Now that is a different matter. Form submissions (with a post action) are picked up server-side. Form submissions (with a get submission) can be picked up both client-side and server-side. However, a JS file cannot (as far as I know) be the page a form gets submitted to.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Probably 90% of web sites mix the two. Usually JavaScript is used for the client-side part, and some other language (asp, php, perl, etc.) is used for the server side. It can get confusing having to mix two languages like that, but it's something we deal with.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

As everyone has said... one is client-side and the other server-side. But on a Friday evening... sometimes you get more than you ask for!

Javascript is a useful beast regardless of how you decide to use it.

You can use it client-side (as almost everyone with an HTML page does for things like fancy rollovers etc)... but it can also be used as the "server-side scripting language of choice" for ASP (normally this is VBScript... but you can change it).

Now Javascript syntax is very very similar to PHP and to Java... so knowing Javascript is pretty cool... it means you can (kinda almost with little effort) handle server-side PHP. It also means you will not struggle to read JSP server-side code as well (since this is Java).

I have no idea where this rant is going... I just got the feeling you were trying to decide the next step to take. Get into Javascript. And do some PHP as well... they are complimentary.

Hope you do well.

Jeff

 
the only way you'll find out what you need on a roadtrip is to start driving down the road.

start developing with javascript on the html page. the more in depth your page/site becomes, you'll hit a ceiling with javascript. you may need a database, or logins, or maybe you want custom form contact pages instead of the "send email to me@yahoo.com"...

then you'll need to start developing server side functions. i prefer perl. i haven't encountered a situation it couldn't handle. I bought a book for $19.99 and never looked back.

a good example of the need for server side scripting is this forum. when you submit a post, the post is parsed server side, and stored in a database (i'm guessing, but more than likely)...that way other people, like you and i, can access the post and also add to it. but look at the button that you click to submit that post...that's javascript in action...its strength is user/browser interaction (buttons, pop ups, rollovers) and organizing user influenced information for the server to receive (forms).

the best programming step i ever made was learning server side scripting. most websites are designed around a main template that remains the same (the landscape) and only the content (information) changes. before learning perl, i created individual html pages for a home page, contact us, about us, site map, store page 1, etc...i had 30 pages, and each time i made a correction to the landscape, i had to alter each page. server side scripting allowed me to have one page, like index.pl and then manipulate the content using name/value pairs (the things that follow the ? in a url)...instead of having a home.html page, i now could use index.pl?a=home and then (server side) ask what the value of 'a' is, in this case 'home' and apply the home content to the template, then serve it out to the client/browser. 1 page to edit, less headache for me.

just relating my experience. good luck.

hope that helps.

- g

 
I actually kinda like using a different language for server script than client script. It helps me keep them straight in my head.
 
Large projects benefit from the server-side and client-side sourcecode being seperated. This is beneficial because members of the team (and maintenance programmers) may have specialist skills - developers can end up stepping on each other's toes.

Small projects with same-developers benefit from collecting the code together. This is what PHP does. In contrast, PERL is good at keeping sever & client sub-projects independent of each other.

There is no right or wrong, but some languages are inherently more compatible with some methodologies than others. If you do not follow a methodology then PHP is right up your street.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
My post did not regard where the code is executed, but was concerned with in which files the sourcecode might be stored.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top