Basic Program Structure and The Integrated Development Environment

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

CP 111 Lecture 6

Basic Program Structure and the


Integrated Development
Environment:
OUTLINE
● Essential program structure,
● Documentation and standard programming
practices,
● Integrated Development Environment (IDE) overview,
● Editing (with the IDE),
● Compilation (with the IDE),
● Execution(with the IDE),
● Debugging (with the IDE).
Essential program structure
● Programs are a sequence of instructions or statements.
● These statements form the structure of a C++ program.
● C++ program structure is divided into various sections, namely, 

○ headers,

○ class definition,

○ member functions definitions 

○ and main function.
Essential program structure…

● Note that C++ provides the flexibility of writing a program with or without a
class and its member functions definitions.
● A simple C++ program (without a class) includes comments, headers,
namespace, main() and input/output statements.
● Comments are a vital element of a program that is used to increase the
readability of a program and to describe its functioning.
● Comments are not executable statements and hence, do not increase the
size of a file.
Namespace
● Namespace: Since its creation, C++ has gone through many changes by the C++
Standards Committee.
● One of the new features added to this language is namespace.
● A namespace permits grouping of various entities like classes, objects, functions and
various C++ tokens, etc., under a single name.
● Different users can create separate namespaces and thus can use similar names of
the entities.
● This avoids compile-time error that may exist due to identical-name conflicts.
● The C++ Standards Committee has rearranged the entities of the standard library
under a namespace called std.
Namespace examples
● By specifying the using directive
using namespace std;
cout<<"Hello World";

● By specifying the full member name


std: :cout<<"Hello World";

● By specifying the using declaration


using std:: cout;
cout<<"Hello World";
Namespace examples
● As soon as the new-style header is included, its contents are included in the
std namespace.
● Thus, all the modern C++ compilers support these statements.

#include<iostream>

using namespace std;


Coding/programming Standards
○ Indentation

■ Proper and consistent indentation is important in producing easy to read and


maintainable programs. Indentation should be used to:

• Emphasize the body of a control statement such as a loop or a select statement

• Emphasize the body of a conditional statement

• Emphasize a new scope block


Coding/programming Standards …
○ Inline Comments

■ Inline comments explaining the functioning of the subroutine or key aspects of the
algorithm shall be frequently used. See section 4.0 for guidance on the usage of inline
comments.

○ Structured Programming

■ Structured (or modular) programming techniques shall be used. GO TO statements


shall not be used as they lead to “spaghetti” code, which is hard to read and maintain,
except as outlined in the FORTRAN Standards and Guidelines.
Coding/programming Standards …
○ Classes, Subroutines, Functions, and Methods

■ Keep subroutines, functions, and methods reasonably sized. This depends upon the
language being used. For guidance on how large to make software modules and
methods. A good rule of thumb for module length is to constrain each module to one
function or action (i.e. each module should only do one “thing”). If a module grows too
large, it is usually because the programmer is trying to accomplish too many actions at
one time.

■ The names of the classes, subroutines, functions, and methods shall have verbs in
them. That is the names shall specify an action, e.g. “get_name”,
“compute_temperature”.
Coding/programming Standards …
○ Source Files

■ The name of the source file or script shall represent its function. All of the routines in a
file shall have a common purpose.

○ Variable Names

■ Variable shall have mnemonic or meaningful names that convey to a casual observer,
the intent of its use. Variables shall be initialized prior to its first use.

○ Use of Braces

■ In some languages, braces are used to delimit the bodies of conditional statements,
control constructs, and blocks of scope.
Coding/programming Standards …
○ Compiler Warnings

■ Compilers often issue two types of messages: warnings and errors. Compiler warnings
normally do not stop the compilation process. However, compiler errors do stop the
compilation process, forcing the developer to fix the problem and recompile.

■ Compiler and linker warnings shall be treated as errors and fixed. Even though the
program will continue to compile in the presence of warnings, they often indicate
problems which may affect the behavior, reliability and portability of the code. Some
compilers have options to suppress or enhance compile-time warning messages.

■ Developers shall study the documentation associated with a compiler and choose the
options which fully enable the compiler’s code-checking features.
Coding/programming guidelines
● General coding guidelines provide the programmer with a set of best
practices which can be used to make programs easier to read and
maintain.
● Unlike the coding standards, the use of these guidelines is not
mandatory.
● However, the programmer is encouraged to review them and attempt to
incorporate them into his/her programming style where appropriate.
● Most of the examples use the C language syntax but the guidelines can
be applied to all languages.
Coding/programming guidelines
● Line Length
○ It is considered good practice to keep the lengths of source code lines at or
below 80 characters.

○ Lines longer than this may not be displayed properly on some terminals and
tools.

○ Some printers will truncate lines longer than 80 columns.

○ FORTRAN is an exception to this standard.

○ Its line lengths cannot exceed 72 columns


Coding/programming guidelines
● Spacing
○ The proper use of spaces within a line of code can enhance readability. Good
rules of thumb are as follows:

■ A keyword followed by a parenthesis should be separated by a space.

■ A blank space should appear after each comma in an argument list.

■ All binary operators except “.” should be separated from their operands by
spaces. Blank spaces should never separate unary operators such as unary
minus, increment (“++”), and decrement(“—“) from their operands.

■ Casts should be made followed by a blank space.


Coding/programming guidelines
● Wrapping Lines
○ When an expression will not fit on a single line, break it according to these
following principles:
Coding/programming guidelines
● Variable Declarations
○ Variable declarations that span multiple lines should always be preceded by a
type.
Coding/programming guidelines
● Program Statements
○ Program statements should be limited to one per line. Also, nested statements
should be avoided when possible.
Coding/programming guidelines
● Use of Parentheses
○ It is better to use parentheses liberally. Even in cases where operator precedence
unambiguously dictates the order of evaluation of an expression, often it is
beneficial from a readability point of view to include parentheses anyway.
Coding/programming guidelines
● Inline Comments

○ Inline comments promote program readability.

○ They allow a person not familiar with the code to more quickly understand it.

○ It also helps the programmer who wrote the code to remember details forgotten over time.

○ This reduces the amount of time required to perform software maintenance tasks.

○ As the name suggests, inline comments appear in the body of the source code itself. They explain the logic
or parts of the algorithm which are not readily apparent from the code itself. Inline comments can also be
used to describe the task being performed by a block of code.
Coding/programming documentation
● Code documentation is a guide that helps in understanding and correctly
utilizing the software code.
● The coding standards and naming conventions written in a commonly
spoken language in code documentation provide enhanced clarity for the
designer.
● Moreover, they act as a guide for the software maintenance team (this team
focuses on maintaining software by improving and enhancing the software
after it has been delivered to the end user) while the software maintenance
process is carried out. In this way, code documentation facilitates code
reusability.
Coding/programming documentation
● Some of the documentation techniques
○ Inline comments

○ Visual appearance of codes

○ Programming tools
Coding/programming documentation

● Programming documentation tools are mostly specific to


a programming language
○ Example

■ Doxygen can be used to automatically generate


documentation from C++ code.
Coding/programming documentation

● Other examples for documentation tools


○ The Rust Docs for Rust programming language

○ Docker’s Dev Docs

○ Swagger UI for RESTFUL API


Integrated Development environment (IDE)
● An integrated development environment (IDE) is a software application that provides
comprehensive facilities to computer programmers for software development.
● An IDE normally consists of at least

○ a source code editor (text editor)

○ compiler,

○ linker

○ build automation tools

○ and a debugger.
Integrated Development environment (IDE)…
● Example of C++ IDE’s

○ Dev C++

○ Turbo Borland C++

○ Borland C++

○ Celliot

○ Netbeans for C/C++ Development

○ Code::Blocks

○ Eclipse CDT(C/C++)

○ Microsoft’s Visual Studio


Integrated Development environment (IDE)…
● Net Beans and Eclipse are good examples of IDE, which contains a compiler,
interpreter, or both; other IDE’s such as Sharp Develop and Lazarus do not
include these tools.
● IDE’s have the capability of using the functionality of multiple programming
processes in a single process.
● Some IDE’s will work on a specific programming language, and also they
contain cross-language capabilities.
● IDE’s such as Eclipse, ActiveState Komodo, IntelliJ IDEA, My Eclipse, Oracle
JDeveloper, Net Beans, Codenvy and Microsoft Visual Studio supports
multiple languages.
Integrated Development environment (IDE)…
The Following are the best IDE software’s use for the development of an application:
• Microsoft Visual Studio
• Net Beans: It is an open source IDE written in Java
• PyCharm
• IntelliJ IDEA
• Eclipse: It is a free IDE, which is used for Java developers and programmers
• Code: Blocks
• Android Studio
• Komodo
• RubyMine
• Xcode
• Enide Studio 2014
• jEdit
• jGRASP
• BlueJ
• Coda
• Aptana
• Blackadder
• Geany
• MonoDevelop
• Espresso
Integrated Development environment (IDE)…
IDE’s have some common features as listed below:
• Text editor: It provides a text editor to write and manage source code.
• Debugger: It uses debugging tools to identify the errors in the source code.
• Compiler/interpreter
• Code Completion
• linker
• Programming language support
• Integration and use of plug-ins
Integrated Development environment (IDE)…
● In order to develop a software in IDE, the following sequence of procedures
should be followed.
○ Opening the IDE software

○ Opening a new project folder for the new software to be developed

○ Opening new file/files in IDE text editor for your program/software's

○ Compiling your written program and correcting error if occurred

○ Run the program to execute it

○ Debug your program if error (semantic/logical) occurred during run time.


Recommended IDE for class practices (C++)

● Dev C++
● Celliot
● Borland C++
● Borland Turbo C++
● Code::block
Questions?
END

You might also like