CB Login

Home arrow Computer Science 20 PHP
CS 20 PHP PDF Print E-mail
Written by Administrator   
Wednesday, 12 November 2008
Instead of teaching computer science with a borning language like Visual Basic try PHP - turn your computer science class into Web Design 101. With the skills students build they will be able to build websites which can turn into a skill that they use to run their own business or take with them into post-secondary education. Here is part of the CS 20 curriclum in Saskatchewan with some PHP information:
4.1 Demonstrate general knowledge of programs in the language, including:
  • use of internal documentation statements
  • order of execution of statements
  • executable and non-executable statements
  • termination of a program. (TL)
  • The teacher should explain the value of these things in a program.
    It can be valuable for students to critique examples of good and bad program code.
    4.2 Write programs in the language that outputs:
  • blank lines
  • numbers
  • strings (messages)
  • items that are formatted and spaced in a variety of ways
  • strings and numbers on one line. (TL, COM)
  • It is a good idea to have some sort of "ice breaker" activity to reduce the anxiety level for beginning programmers. Writing the first program can be daunting.
    Students should be given an explanation of the criteria which will be used when their programs are evaluated. Creating a checklist of these for the students to use is good.
    Whenever possible, have student programming projects link to other courses such as science, mathematics or accounting.
    The instructor can provide the students with test data to use with their program to see if the results are valid.
    4.3 Demonstrate understanding and skill in the use of variables and assignment of values to variables, as follows:
  • differentiate between variables and values
  • identify primitive types of variables
  • identify the characteristics of the different types of variables and the operators appropriate to the different types
  • explain conventions for naming variables
  • identify an acceptable program statement that assigns a value to a variable
  • explain how a variable assignment is executed.
  • PHP Variables
  • PHP 101 (part 1): Down the Rabbit Hole
  • W3 Schools PHP Variables
  • Naming conventions

    Variable names

    A lot of textbooks (particulary those about Visual C++) will try to drum hungarian notation into your head. Basically, this means having rules such as pre-pending g_ to global variables, i to integer data types etc. Not only is a lot of this irrelevant to PHP (being a typeless language), it also produces variable names such as g_iPersonAge which, to be honest, are not easy to read at a glance and often end up looking like a group of random characters strung together without rhyme or reason.

    Variable names should be all lowercase, with words separated by underscores. For example, $current_user is correct, but $currentuser, $currentUser and $CurrentUser are not.

    Names should be descriptive, but also concise. Wherever possible, keep variable names to under 15 characters, although be prepared to sacrifice a few extra characters to improve clarity. There's no hard and fast rule when it comes to the length of a variable name, so just try and be as concise as possible without affecting clarity too much. Generally speaking, the smaller the scope of a variable, the more concise you should be, so global variables will usually have the longest names (relative to all others) whereas variables local to a loop might have names consisting only of a single character.

    Constants should follow the same conventions as variables, except use all uppercase to distinguish them from variables. So USER_ACTIVE_LEVEL is correct, but USERACTIVELEVEL or user_active_level would be incorrect.

    [ http://www.evolt.org/article/PHP_coding_guidelines/18/60247/]

     

    4.4 Write programs in the language that assigns an output, as follows:
  • assign numbers to numeric variables
  • assign strings to string variables
  • transfer the value of one storage variable to another
  • output the values of numeric and string variables in a formatted way. (NUM)
  • It is important that students understand the difference between numeric and string variables and the way they are handled in the language. An activity early in the course to help students learn the differences can prevent much grief for them. An assignment where students correct variable mismatches or write a program with mismatches for a classmate to correct might be valuable.
    4.5 Write programs that:
  • display appropriate messages when prompting the user
  • store numeric data in an appropriate variable
  • store string data in an appropriate variable.
  •  I would use JavaScript to prompt users entering information into a form.  Client side scripting is more appropriate for this.  You can utilize css to style the form for user interaction.
    4.6 Recognize the various structural components of a program including variable and type declarations, conditionals, loops, modules, procedures/sub-routines, functions and other components that the chosen language supports.

    It can be a good idea to have the students write procedures for a program body supplied by the teacher.

    4.7 Demonstrate understanding and skill in the use of conditionals and looping, as follows:
  • define a conditional, a loop
  • understand how infinite loops are created and why they should be avoided
  • describe the relational operators
  • use relational operators to compare numeric and string values.
  • Conditional statements in most programming languages are implemented with an if-then-else structure. In some older languages, go to statements were used to simulate this structure. However, the use of go to should be STRONGLY discouraged in all student programming. If your chosen language requires use of go to statements, it is time for an upgrade.

    4.8 Demonstrate an understanding in the use of the language’s conditional and loop commands, as follows:
  • state the purpose of each statement of the command(s)
  • identify and correct invalid uses of the command(s)
  • follow and diagram the working of a conditional (if statement) and series of nested conditionals identifying the operators and the logical concepts involved
  • follow and diagram the working of a loop, tracking counter values, etc.
  • explain nested loops and how they work.
  • The instructor may decide to restrict the topic to one kind of loop structure; however, students should be aware that most languages have several loops, each of which has different attributes. For example, some loops are count based and some are condition based.
    Nested loops can be demonstrated through role-playing. A student could perform an action loop, such as clapping five times. This action loop can be nested inside another such as standing up and sitting down.
    4.9 Demonstrate understanding of the value and importance of proper use of sub-programs and of using sub-routines whenever practical within programming projects. The students may find an ongoing program, that is added to as new concepts are introduced, to be more interesting than a new program for every concept.
    4.10 Write programs involving single and nested loops.  
    4.11 Write programs that contain manipulations with strings using the string manipulation functions in the language.
    (COM)
    String comparison, joining, case change, and dissecting should be discussed and practised.
    A model of a string variable can show that different string functions do not change the value of the variable, they just look at a piece of it.
    4.12 Write programs that contain uses of the built-in numeric functions of the language.  
    4.13 Demonstrate an understanding of and skill in the use of user-defined functions as follows:
  • identify appropriate uses
  • contrast characteristics with other types of routines and procedures. (NUM)
  • It is useful to show the value of functions by contrasting two programs that produce similar output while differing by using or not using functions.
    4.14 Demonstrate an understanding of and skill in the use of single dimension arrays as follows:
  • describe the way that subscripted variables are stored in memory
  • explain how a loop can deal with numerous variables using an array
  • explain how a variable can be used to select a particular element from an array.
  • Visual models are valuable when introducing arrays to students.
    When beginning to use arrays, students will understand the processes much better if they first fill and extract data from an array with separate actions rather than doing it recursively. They will soon want a way to improve the process and will be eager to use loops to manipulate data in an array.

    4.15 Use single-dimension arrays appropriately in a program, as follows:
  • enter data into an array
  • access data from an array
  • search and sort items in an array.
  • The sort and search should be done quickly, with the purpose of demonstrating the use of arrays. It is not intended to have students become proficient with all aspects of searches here.
    Last Updated ( Wednesday, 12 November 2008 )