User:Mitrebox
This page is a test prototype of my interpretation of WikiCode. I am conduction the test as part of an information studies class at the University of Alabama
Please Read
[edit]This page is part of an assignment I'm doing for a class.
- If you view this page please sign my talk page in the VIEW area.
- If you edit this page please sign my talk page in the EDIT area.
-Thankyou --Mitrebox 14:53, 8 Apr 2005 (UTC)
Wiki Code Functions
[edit]A wiki onto which function sourcecode would be placed and avliable for viewing and editing by others.
Purpose
[edit]- Provide others with cut and paste functions
- Provide others with functions they can copy and customized for their own needs
- Provide examples of code to others for them to build their programs
- Create a repository of general error-free low level functions
- Possibly allow companies to place code (on their own intranet wikis) to allow code to be broght up to date on a continous basis as opposed to a massive update of entire applications.
- Provide the same functions in multiple programming langugaes
Termanology
[edit]- Non language specific function - a function that is not as much code as it is PDL. Could be used to create a reserved keyword to build functions in other languages. So that GetWorkingDays in vb which deals with the number of working days between two dates does the same thing as in java. This is so hopefully noone comes along and writes a function in java called GetWorkingDays that returns an array of days an employee is scheduled to work.
- Language specific function - a function that is the acutal code for a function
- language specific PDL. PDL that is customized to the langauge it is about. Some languages need for steps to occur in a specifc order that other languages might not like. In cases like this one version of PDL would not work for all langauage.
- PDL - program design language - not an actual programing language but a series of plain engligh steps that a piece of code needs to execute. Useful in writing complex functions or quickly seeing the steps in an exisiting fucntion.
PDL example open output.txt For each of the students in the array write the student name to output.txt write the student grage to output.txt close output.txt
Base Level
[edit]Functions show generally be at a base level to optomize their usuability (the ability of the functions to be used by a large number of users), simplicity/transpancy (the degree of dificulty in unserstanding the code), lack of errors.
Higher level functions can be written but they should call lower level functions.
Each line of code should generally do only one step. The purpose of the project is to make functions that are easy to understand for the maximum number of users; not specifally to make the functions that are the most efficent or the shortest number of lines.
General Outline of a non language specific function
[edit]- Name of function
- catagory of function
- Purpose of Function
- inputs
- outputs
- PDL
- Languages avliable
- Subfunctions
General Outline of a language specific function
[edit]- Name of function
- Language
- catagory
- purpose
- inputs
- outputs
- langage specifc PDL
- code
- prototype
- declaration
- example of usage
- example of output
- subfucntions
- other languages avliable
Example Function
[edit]- Name: GetWorkingDays
- Language :VB
- Catagory:Data\Time
- Inputs:Date1 Date2
- Outputs:Integer
- Purpose:Function returns the number of weekdays between date1 and date2
- Code:
Origonal copy
[edit]Function GetWorkingDays(ByVal Date1, ByVal Date2) '======================================= ' returns the number of weekdays (i.e., excluding Sat/Sun) ' between 2 dates. ' ' As implemented, Date1 should not be greater than Date2 ' (but is not verified). A more versatile version could ' allow for inverted dates and calculate and return a ' negative value. To be more robust, the arguments should ' also be verified as valid dates. ' Also adding a database of holidays can help '======================================= Dim TotalDays, FullWeeks, OddDays, n TotalDays = DateDiff("d", Date1, Date2) FullWeeks = TotalDays \ 7 OddDays = TotalDays Mod 7 GetWorkingDays = FullWeeks * 5 For n = 0 To OddDays - 1 Select Case Weekday(DateAdd("d", n, Date1)) Case vbSaturday, vbSunday 'ignore Case Else : GetWorkingDays = GetWorkingDays + 1 End Select Next Return GetWorkingDays End Function
Usage:
Dim start,end as Date start = 1/5/2005 end = 6/26/2005 Dim x as interger = GetWorkingDays( start, end )
Try it Out
[edit]Edit the function below
[edit]Function GetWorkingDays(ByVal Date1, ByVal Date2) '======================================= ' returns the number of weekdays (i.e., excluding Sat/Sun) ' between 2 dates. ' ' As implemented, Date1 should not be greater than Date2 ' (but is not verified). A more versatile version could ' allow for inverted dates and calculate and return a ' negative value. To be more robust, the arguments should ' also be verified as valid dates. ' Also adding a database of holidays can help '======================================= Dim TotalDays, FullWeeks, OddDays, n TotalDays = DateDiff("d", Date1, Date2) FullWeeks = TotalDays \ 7 OddDays = TotalDays Mod 7 GetWorkingDays = FullWeeks * 5 For n = 0 To OddDays - 1 Select Case Weekday(DateAdd("d", n, Date1)) Case vbSaturday, vbSunday 'ignore Case Else : GetWorkingDays = GetWorkingDays + 1 End Select Next Return GetWorkingDays End Function
Post the function in another programming langauge
[edit]- Language: ?