|
|
|
|
ArraysWhat if you want to process large set of numbers, or 1000s of employees records. For instance, consider you need to sort 10 numbers in ascending order. Will you have 10 different variables of 'int' data types? No. Arrays are the easiest way of declaring such variables. int a[10] ; where square brackets ( '[', ']', some cases it is '(' and ')' are used ) indicate, it is an array variable. 10 is the number 'int' values you want to store. Each value is called an 'element' and is accessed by its 'subscript' or 'index'. So,
In some languages, the starting 'index' is '0' and others it is '1'. In the above example, the starting element is '0'. Suppose there is another set of 10 'int' int b[10] ; The following 'assignment' in invalid in most of the languages. a = b ; In stead, you have to use a 'loop' to assign each array element to another array element.
ProceduresAs the size of the application increases, some tasks are repeated in different places resulting in duplicates of codes. Which also leads to errors. If the complete program is written sequentially, it is difficult to maintain, test, and debug the program easily. It is more and more complicated when many people are involved in the development process. Functional decomposition (modular) is a method to divide a large program into small maintainable and reusable codes. It is implemented through using 'procedures' and 'functions'. Procedures are a subset of a large program which perform specific tasks by a call to that procedure from the main program or from another procedure or function. You can use 'loops', 'conditional statements' in your procedures and functions. You can pass 'arguments' ( also called 'parameters') of any data type to your procedures. Syntax for declaring 'procedures' are different from languages to languages. Example,
The procedure has to be declared first, before it is called from a program. You have to declare the datatype of each argument to be passed to the procedure. When the procedure is called the value of 'iBase' is assigned to 'base' and the same way 'iPower' is assigned to 'power'. Arguments 'base' and 'power' are local variables within the procedure. That means, any changes to 'base' and 'power' will not affect the values stored in 'iBase' and 'iPower'. Naming Convention:Prefix the datatype when declaring variables:
Most of the languages support long names for variables, procedures, functions. Long names can be written like,
Whatever the 'convention' you follow, stick to that throught out your life time. FunctionsDifference between 'procedures' and 'functions' is that the 'function' can return a value to the called program.
Functions can return only one value to the called program. First part of the function declaration says what is the datatype of the return value. There are two methods to pass a value to a function/procedure. Passing by valueAbove examples use this method to pass values. In this any changes to the arguments will not affect the variables in the called program. But it takes additional memory, which is same as the variables in the called program. It may use large memory for arrays. Passing by referenceAny changes to the arguments will affect the corresponding variables in the called program. Because it references (pointing to the variable in the called program), it reduces the amount of memory used. This allows you to return (indirectly) more than one value to the called program. Constant variables Sometimes you know in advance that a variable will have a constant value. e.g., const float pi=3.14 ; //const key word int iMaxSize = 10 ; // used for array size, counters. You can use 'const' in argument passing also. e.g., Find_Power( const int base, const int power ) ; In case of 'passing by reference variables', it prevents the actual value to be changed, but still uses the power of 'less memory'. LibrariesLibrary files store set of related procedures, functions and variables which can be shared with other application. It allows you to maintain the codes easily. Also gives independence to programmers to create their own libraries that can be integrated with the main application. Project/ApplicationAny software development results in 'project' or 'application' development. Some languages uses 'project' to refer to an application. 'Project' and 'application' are synonymous with each other. A project file will reference to all other library files used in the development of an application. For example in a Visual Basic application, a project file refers to:
Source ControlVersion control is important as changes are made to your application by more than one people every day. Source control system allows you share an application with many users maintain the 'changes' history. You can rollback to previous version of code from the 'history'. |
|
Send mail to arungomes@eircom.net with questions or comments about this web site.
|