|
|
Subject:
Difference between Pascal & PHP
Category: Computers > Programming Asked by: whitehat88-ga List Price: $20.00 |
Posted:
05 Jun 2005 07:40 PDT
Expires: 05 Jul 2005 07:40 PDT Question ID: 529542 |
Can someone tell me the difference between those two programming languages? Also please show as many code snippets of both languages as possible. |
|
Subject:
Re: Difference between Pascal & PHP
Answered By: djbaker-ga on 05 Jun 2005 10:37 PDT Rated: |
Greetings! Without even looking at the Syntax differences between the two, PHP and PASCAL are two very different languages. Unlike a comparison between other languages such as C and Basic or C++, the differences do not simply lie in how flexible or powerful the languages are but rather in their basic use. At its core PHP is designed as a scripting language to be used server-side while PASCAL is a regular programming language which can be used to write standalone applications. PHP has become an incredibly popular language recently. Its use can be seen through out the web, from simple form processing scripts to giant web based applications such as MediaWiki, the engine which drives http://www.wikipedia.com. PHP is a scripting language, so in terms of use and flexibility it has a lot in common with other scripting languages such as Perl, Python and Ruby. PHP is designed to be run server-side and is primarily used to enhance website functionality. So for example if you wanted a program which took user submitted data from a form on your website and added it to a database you would want to write a PHP script. Scripts can also be written which parse data, interact with users, etc. The only major limitation to PHP is that it is designed to run server-side so it cannot for most practical purposes to be used to create standalone applications. This is where PASCAL comes into play. Where PHP is designed to be run server-side, PASCAl is designed to be run client side. This mean instead of a server processing the program and feeding the information to the end user, PASCAL is used to create programs which run on the users computer. PASCAL was developed in 1970 by Niklaus Wirth. The language has fallen out of use in recent years in favor of more popular languages such as C, C++ and Java. Some of the notable things that have been developed in PASCAL include large portions of the original Macintosh Operating System as well as the typesetting system TeX. http://en.wikipedia.org/wiki/PASCAL If you wanted to write a piece of shareware or a regular program which stands alone and does not require a server then PASCAL (instead of PHP) is what you would want to use. In practical terms though not much is written in PASCAL these days. ----- Code Samples --------------- Below you'll find some code samples for the two languages which illustrate some of the syntax differences for some of the more common functions. *** File Format *** A PHP script is saved with the format filename.php. When placed on a PHP enabled server and run it will be interpreted by the server's PHP parser and executed. A Pascal program on the other hand is written in a text editor and then compiled which creates an executable program with the extension (on a PC) .exe. *** Beginning and Ending *** PHP scripts begin with the tag: <?PHP and end with ?> So a script would look like this... <?PHP ... Your script here ... ?> In PASCAL programs start with the "Program" keyword and then the main block of code is contained within begin and end tags. So a sample PASCAL program would look like this... program YourProgram(input, output) begin ... Your Code Goes Here ... end *** Basic Variables *** PHP does not have defined variable types. As a result all variables are prefixed with $. So the variable named "variable" would look like $variable. Variables in Pascal are similar to those in C and other languages. Check out this nice tutorial for examples on how to define the various variable types in PASCAL. http://www.geocities.com/SiliconValley/Horizon/5444/pas005.htm *** If/Then *** If/Then statements in PHP are fairly easy to write. It begins with an If(X) where represents the condition to be evaluated. If it evaluates to true then the code contained inside the following set of brackets is executed. For example... if (condition_to_be_evaluated) { ... if true this code executes ... } ----- $x = 1 $y =1 if ($x == $y) { print "Because X and Y are both equal to 1, the condition will evaluate to true which means this code will be exacuted"; } PASCAL looks a lot different (and a lot less clean if you ask me) when it comes to if/then statements. The basic structure of an if/then statement in PASCAl is: if BooleanExpression then begin ...this code gets evaluated end; In the above example, the condition you want to test goes where "BooleanExpression" is. If this evaluates to true then the code within the begin and end keywords gets executed. *** Output *** Outputting to the screen is very simple in both languages. The easiest way in PHP is to write: print "What you want to output goes here"; In PASCAL the syntax goes as follows: Writeln('What you want to output goes here'); *** For Loops *** In PHP for loops look like this: for (initial value x; condition for loop to finish; closing expression) { code } A practical example would be: for ($x=0; $x<10; $x++) { print x; } This loop sets the initial value to x ($x=0) and then runs the code print x; over and over until $x is greater then 10. Each loop $x is raised by 1. On the Pascal side For loops take on this structure: FOR var_name := initial_value TO final_value DO begin ...your code goes here... end; ----- Helpful Links ----- A number of helpful tutorials exist for both languages which will further illustrate the syntax differences between the two. If listed a number of the best ones below. *** PHP *** PHP - A Simple Tutorial http://us2.php.net/tut.php W3schools PHP Tutorial http://www.w3schools.com/php/default.asp PHP Tutorial Part 1 http://www.freewebmasterhelp.com/tutorials/php PHP Tutorial - Introduction http://www.tizag.com/phpT/ *** PASCAL *** Learn Pascal Tutorial http://www.taoyue.com/tutorials/pascal/ Delphi and Pascal Programming Tutorial http://ourworld.compuserve.com/homepages/TK_Boyd/Tut.htm Roby's Pascal Tutorial http://www.geocities.com/SiliconValley/Park/3230/pas/pasles00.html I hope that this answered your questions. If you need anything cleared up, please request a clarification before rating my answer and I will be more then happy to help. Best, djbaker-ga | |
| |
| |
| |
|
whitehat88-ga
rated this answer:
and gave an additional tip of:
$5.00
Very good, exactly what i expected! |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |