Scripting Languages Final Exam


  1. (15 points): Fill in the blanks for the following questions:

    1. prototype-instance The object model in Javascript is not called a class-instance model but is instead called what?

    2. expat parser If you simply need to make a single pass through an XML document to convert the tags from one set of names to a different set of names, which XML parser should you use?

    3. simple XML parser Which PHP XML parser allows you to accomplish 80% of what you want to do with 20% of the effort?

    4. javascript Which language, among the languages we discussed in this course, allows you to dynamically add new properties or methods to an object?

    5. schema What XML tool allows you to specify both the structure of an XML document and the data types of elements in that XML document?

  2. (20 points) Choose the best answer from the following set of choices:

    compiled language, like CHTMLCSS
    XMLSQLXPath
    PerlJavascriptPhP
    DTDSchemaRegular Expressions

    1. XPath The query language for XML.
    2. javascript The best language to use for client-side scripting.
    3. compiled language The best language to use for computationally intensive problems.
    4. HTML The best and simplest language for specifying the structure of a web page.
    5. CSS The language to use for specifying the appearance of a web page.
    6. PHP The most modern language for perform server-side scripting.
    7. XML The language best used for marking up the data content of a document.
    8. SQL The language best used to store your data when your data is well organized into a consistent set of fields and efficiency is of the essence.
    9. Perl The language that along with TCL ushered in the era of scripting languages. Also known for its report extraction capabilities via regular expressions.
    10. Regular Expressions A compact notation that allows you to easily specify type checking expressions for data.

  3. (5 points) In three sentences or less, explain the importance of AJAX to web scripting (please do not tell me what the acronymn stands for).

    It enables Javascript to update a portion of a web-page without having to reload the entire page. It thus makes web-pages seem more interactive, and able to provide real-time information.

  4. (12 points) Early in the semester we discussed a number of features of scripting languages that allow programmers to more rapidly develop and debug code than with corresponding conventional languages. List 4 of these features, and for each one describe how it makes program development more efficient.

    My answer has more than 4 features--you could choose any of these:

    1. Interpreted rather than compiled: makes it easy to rapidly debug programs and to try out fragments of code.
    2. Sophisticated pattern-matching and string manipulation: Makes it easy to type-check data and to extract information from documents.
    3. High-level data structures, such as lists and hash tables, and high-level control constructs, such as foreach loops, are part of the language: Allows for programs to be specified compactly, so they can be written quickly
    4. No need to declare variables: Allows for programs to be specified compactly, so they can be written quickly
    5. Variables are dynamically typed: Allows variables to hold heterogeneous types of data, such as either text or icons for a button.
    6. Easy access to system facilities: Makes it easy to glue together different modules to rapidly accomplish a task.
    7. Automatic memory management: The memory for both objects and for data structures, such as lists, arrays, and hash tables are automatically allocated and de-allocated for you.

  5. (8 points): Why does a language like Javascript allow the case branches of switch statements to contain numbers, strings, and variables, while a compiled language like C allows only integers?

    C strives for computational efficiency so it allows only integers in order to allow it to use jump tables that allow it to jump in O(1) time to the right branch of a switch statement. It thus limits the flexibility of the case statement and forces the programmer to write out if-then-else statements for strings or values that can only be determined at run-time. Javascript strives for programmer efficiency by allowing code to be expressed compactly, so it allows switch statements to contain all types of labels, since programmers often want to use strings or dynamically determined values as labels. This compromises computational efficiency because now the interpreter must examine all branches of the switch statement as though it were a series of if-then-else statements, thus potentially requiring the case statement to take O(n) time to find the right branch of the switch statement to execute.

  6. (5 points): What makes PHP a better language than Perl for creating dynamic web pages?

    PHP can be embedded within the HTML code, so the static parts can be written as they normally would be in a static html document and only the dynamically generated content needs to be written in PhP. In contrast Perl has to use print statements to generate both the static and dynamic parts of the web-page. Other advantages of PHP, although they were not asked for in this question, is that PHP was designed for server side scripting and so many constructs are embedded in the language to make it work seamlessly with client side scripts, such as session variables and associative tables for accessing the contents of forms. With Perl, you have to import a CGI module, worry about getting permissions to use it for server-side scripting, changing the file extension from .pl to .cgi--in other words, it's not as seamless as it is with PHP.

  7. (15 points): This question has two parts:

    1. Describe two client-side and two server-side solutions to keeping session information using PHP, and describe the advantages of each. Use no more than three sentences for each solution.

      1. Hidden form elements (client-side): Easy for embedding promotional codes or other information that the user does not need to see. Works when cookies are disabled.
      2. Cookies (client-side): Allows session information to be stored on the client's computer so that session information does not have to be passed back and forth over the internet between the server and client, thus speeding up the perceived interactivity of the application.
      3. Session variables: Protects the security of session information from modification by malicious users, without having to resort to dealing with the complexity of a database.
      4. Databases: Protects the security of session information from modification by malicious users, maintains state information if necessary across multiple sessions, and can handle multiple servers (session variables typically only work with a single server).

    2. Is it better to keep session information on the client-side or the server-side? Why?

      It is better to keep session information on the server-side for security purposes. Session information kept on the client-side can be modified by a malicious user but session information kept on the server-side should be free from tampering.

  8. (10 points): Describe what advantages XML has over a database and what advantages a database has over XML.

    XML provides more flexibility in the mark-up of data content, meaning that data can have multiple items or that there can be different blocks of data depending on the type of the data (e.g., a professor might have a block of data about a professor and a student might have a block of data about a student). In XML the data content is also human readable, which makes it easier for two entities to exchange data. A database provides faster access to data, more security, read-write locks, and more compact data storage.

  9. (10 points): This question has three parts:

    1. What are the advantages of using cascading style sheets to create the appearance and page layout of a web document over specifying the appearance in each html document?

      Using cascading style sheets it is easy to specify the appearance of an entire web-site in a single file and to change the appearance of a web-site by modifying a couple statements in a single file. If you hard-code the appearance of an html document, then you will need to change each html page if you want to change the appearance of your web-site.

    2. Are cascading style sheets better at specifying the visual appearance of a web document or the page layout of a web document? Justify your answer.

      They are much better at specifying the visual appearance of a web document. For page layout they are pretty much limited to specifying the horizontal layout of a page and a designer may have to do perform a bunch of kludges to get vertical alignment correct, to horizontally center content, or to get columns to line up correctly and extend to the bottom of the page without overlapping other columns.

    3. What element in HTML is often used to perform page layout and may well be superior to anything that CSS offers?

      The table element. It makes both horizontal and vertical layout fairly easy. CSS has recently been expanded to include table elements for layout purposes and future releases of browsers will support these extensions.