Unit 4 Notes
Unit 4 Notes
The use of structured coding techniques and styles supports the primary goal of implementation
to write quality source code and internal documentation that aid in easy verification with
specification, debugging testing and modification. The source code thus generated will be
simple, clear and elegant and less obscure, clever and complex.
The structured program consists of well structured and separated modules. But the entry and exit
in a Structured program is a single-time event. It means that the program uses single-entry and
single-exit elements. Therefore a structured program is well maintained, neat and clean program.
This is the reason why the Structured Programming Approach is well accepted in the
programming world.
1. Procedural programming. Defines modules as procedures or functions that are called with
a set of parameters to perform a task. A procedural language begins a process, which is then
given data. It is also the most common category and is subdivided into the following:
b. Microservice programming focuses on creating modules that do not store data
internally and so are scalable and resilient in cloud deployment.
c. Functional programming, technically, means that modules are written from functions,
and that these functions' outputs are derived only from their inputs. Designed for
serverless computing, the definition of functional programming has since expanded to
be largely synonymous with microservices.
2. Standard headers for different modules: For better understanding and maintenance of the
code, the header of different modules should follow some standard format and information.
The header format must contain below things that is being used in various companies:
● Name of the module
● Date of module creation
● Author of the module
● Modification history
● Synopsis of the module about what the module does
● Different functions supported in the module along with their input output parameters
● Global variables accessed or modified by the module
3. Naming conventions for local variables, global variables, constants and functions: Some
of the naming conventions are given below:
● Meaningful and understandable variables name helps anyone to understand the reason of
using it.
● Local variables should be named using camel case lettering starting with small letter
(e.g. localData) whereas Global variables names should start with a capital letter
(e.g. GlobalData). Constant names should be formed using capital letters only
(e.g. CONSDATA).
● It is better to avoid the use of digits in variable names.
● The names of the function should be written in camel case starting with small letters.
● The name of the function must describe the reason of using the function clearly and
briefly.
4. Indentation: Proper indentation is very important to increase the readability of the code.
For making the code readable, programmers should use White spaces properly. Some of the
spacing conventions are given below:
● There must be a space after giving a comma between two function arguments.
● Each nested block should be properly indented and spaced.
● Proper Indentation should be there at the beginning and at the end of each block in the
program.
● All braces should start from a new line and the code following the end of braces also
start from a new line.
5. Error return values and exception handling conventions: All functions that encountering
an error condition should either return a 0 or 1 for simplifying the debugging.
Coding guidelines give some general suggestions regarding the coding style that to be followed
for the betterment of understandability and readability of the code.
Some of the coding guidelines are given below :
1. Avoid using a coding style that is too difficult to understand: Code should be easily
understandable. The complex code makes maintenance and debugging difficult and
expensive.
2. Avoid using an identifier for multiple purposes: Each variable should be given a
descriptive and meaningful name indicating the reason behind using it. This is not possible if
an identifier is used for multiple purposes and thus it can lead to confusion to the reader.
Moreover, it leads to more difficulty during future enhancements.
3. Code should be well documented: The code should be properly commented for
understanding easily. Comments regarding the statements increase the understandability of
the code.
4. Length of functions should not be very large: Lengthy functions are very difficult to
understand. That’s why functions should be small enough to carry out small work and
lengthy functions should be broken into small ones for completing small tasks
5. Try not to use GOTO statement: GOTO statement makes the program unstructured, thus it
reduces the understandability of the program and also debugging becomes difficult.
Documentation Guidelines
Software documentation is a written piece of text that is often accompanied by a software
program. This makes the life of all the members associated with the project easier. It may
contain anything from API documentation, build notes or just help content. It is a very critical
process in software development. It’s primarily an integral part of any computer code
development method. Moreover, computer code practitioners are a unit typically concerned with
the worth, degree of usage, and quality of the actual documentation throughout the development
and its maintenance throughout the total method. Motivated by the requirements of Novatel
opposition, a world-leading company developing package in support of worldwide navigation
satellite system, and based mostly on the results of a former systematic mapping studies area
unit aimed at a higher understanding of the usage and therefore the quality of varied technical
documents throughout computer code development and their maintenance.
Purpose of Documentation:
Due to the growing importance of computer code necessities, the method of crucial them needs
to be effective to notice desired results. As to such determination of necessities is often beneath
sure regulation and pointers that area unit core in getting a given goal.
These all imply that computer code necessities area unit expected to alter thanks to the ever
ever-changing technology within the world. However, the very fact that computer code
information I’d obtained through development has to be modified within the wants of users and
the transformation of the atmosphere area unit is inevitable.
While writing or contributing into any software documentation, one must keep in mind the
following set of 7-principles :
● If there’s a lot of content, you can organize it in the glossary part at the end of the document.
● List down synonyms, antonyms and difficult terminologies used.
3. Avoid ambiguity:
Documentation contains a lot of information regarding the versatile functionalities of the
software system, every part of it must be written with clear and precise knowledge while
avoiding any conflicting information that might cause confusion to the reader. For example, if
one terminology is used in different set of context than it must be explicitly defined what it
means so to avoid any miscommunication. This aspect of the software documentation is very
important to avoid any kind of conflicting knowledge between the stakeholders, developers and
the maintainers.
5. Record a Rationale
Rationale contains a comprehensive understanding of why a certain design or
development decision was made. This part of our documentation is written & maintained by the
developer or the designer itself for justification and verification for later needs. Rationale can be
mentioned in the start or the end of the document although typically, it’s in the start of the
document.
7. Review documentation
The documentation consists of too many web-pages collectively holding a large chunk of
information that’s serving a sole purpose – educate and spread knowledge to anyone who is
trying to understand or implement the software. While working with a lot of information it is
important ta take feedback from senior architects and make any necessary changes aligning the
documentation with its sole purpose depending on the type of documentation.
● The presence of documentation helps in keeping the track of all aspects of an application and
also improves the quality of the software product.
● The main focus is based on the development, maintenance, and knowledge transfer to other
developers.
● Helps development teams during development.
● Helps end-users in using the product.
● Improves overall quality of software product
● It cuts down duplicative work.
● Makes easier to understand code.
● Helps in establishing internal coordination in work.
MODERN PROGRAMMING
LANGUAGE FEATURES
TYPE CHECKING
Dynamic Typing:
In Dynamic Typing, type checking is performed at runtime. For example, Python is a
dynamically typed language. It means that the type of a variable is allowed to change over
its lifetime. Other dynamically typed languages are -Perl, Ruby, PHP, Javascript etc.
Static Typing:
Static Typing is opposite to Dynamic Typing. In Static Typing, type checking is performed
during compile time. It means that the type of a variable is known at compile time. For some
languages, the programmer must specify what type each variable is (e.g C, C++, Java), other
languages offer some form of type inference(e.g. Scala, Haskell).
With Static Typing, variables generally are not allowed to change types.
USER DEFINED DATA TYPE
A user-defined data type (UDT) is a data type that derived from an existing data
type. You can use UDTs to extend the built-in types already available and create
your own customized data types.
There are six user-defined types:
• Distinct type
• Structured type
• Reference type
• Array type
• Row type
• Cursor type
Modern programming languages have evolved significantly over the last few decades, driven by
advancements in computing, the rise of complex software systems, and the need for more
efficient and maintainable code. These languages are designed to improve productivity, enhance
performance, ensure security, and provide greater flexibility in solving contemporary software
development challenges.
TYPE CHECKING
Dynamic Typing:
In Dynamic Typing, type checking is performed at runtime. For example, Python is a
dynamically typed language. It means that the type of a variable is allowed to change over
its lifetime. Other dynamically typed languages are -Perl, Ruby, PHP, Javascript etc.
Static Typing:
Static Typing is opposite to Dynamic Typing. In Static Typing, type checking is performed
during compile time. It means that the type of a variable is known at compile time. For some
languages, the programmer must specify what type each variable is (e.g C, C++, Java), other
languages offer some form of type inference(e.g. Scala, Haskell).
With Static Typing, variables generally are not allowed to change types.
USER DEFINED DATA TYPE
A user-defined data type (UDT) is a data type that derived from an existing data
type. You can use UDTs to extend the built-in types already available and create
your own customized data types.
There are six user-defined types:
• Distinct type
• Structured type
• Reference type
• Array type
• Row type
• Cursor type
Distinct type
• Structured type
• Reference type
• Array type
• Row type
• Cursor ty
1. Type Checking
Type checking refers to verifying that the data types of variables and expressions are used
consistently and correctly in a program.
User-defined data types allow programmers to create custom data types tailored to the needs of
the program, enhancing clarity and maintainability.
● Structs (Records):
o Composite data types that group different types together (e.g., C's struct, Rust's
struct).
● Classes (Objects):
o Defines data along with functions (methods) for manipulating that data (e.g., Java,
Python).
o Supports object-oriented programming with concepts like inheritance,
encapsulation, and polymorphism.
● Enumerations (Enums):
o A type that defines a set of named values, often used to represent distinct states or
categories (e.g., Swift, Rust, C++ enum).
● Unions and Variants:
o A data type that can store different types at different times (e.g., Rust's enum
allows sum types).
3. Data Abstraction
Data abstraction hides the implementation details of data, exposing only the necessary interfaces,
making the system easier to understand and use.
Exception handling provides a way to manage and respond to runtime errors gracefully without
crashing the program.
● Try-Catch Blocks:
o A common mechanism where code that might throw an error is wrapped in a try
block, and errors are caught and handled in the catch (or except) block (e.g., Java,
Python, C++).
● Throwing Exceptions:
o If a function cannot complete its task, it can "throw" an exception to signal the
error (e.g., throw keyword in C++, Java, Swift).
● Checked and Unchecked Exceptions:
o Checked Exceptions: Must be explicitly handled or declared (e.g., Java’s I/O
operations).
o Unchecked Exceptions: Do not require explicit handling, often indicating
programming errors (e.g., NullPointerException in Java).
● Finally Block:
o Executes code after try-catch regardless of whether an exception occurred, often
used for resource cleanup (e.g., file closing, memory release).
5. Concurrency Mechanism
● Threads:
o Lightweight units of execution that run concurrently within a process (e.g., Java
Thread, Python threading).
o Multithreading: Running multiple threads concurrently for parallelism.
● Coroutines:
o A more efficient form of concurrency, allowing cooperative multitasking.
Coroutines can pause and resume execution, used in languages like Python,
Kotlin, and JavaScript (async/await).
● Asynchronous Programming:
o Uses async and await to write non-blocking code. Tasks can run in the
background without interrupting the main thread (e.g., JavaScript, Python, C#).
● Locks and Semaphores:
o Synchronization tools used to prevent race conditions and ensure thread safety
when accessing shared resources.
● Message Passing:
o Avoids direct shared memory access by using messages to communicate between
concurrent units (e.g., Go’s Goroutines and channels).
● Actors Model:
o Treats "actors" as fundamental units of concurrency. Each actor can send and
receive messages without sharing state (e.g., Akka in Scala).