0% found this document useful (0 votes)
80 views5 pages

DD1

The document discusses three factors that can improve the readability of code: comments, appropriate naming of variables, and proper indentation. Comments explain the purpose of code, making it easier for others to understand. Variable names should clearly indicate what data they hold. Indentation organizes blocks of code visually to improve comprehension. Syntax highlighting, where code elements are color-coded, also aids readability by allowing quick identification of statements. All of these factors help programmers better understand existing code and make modifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views5 pages

DD1

The document discusses three factors that can improve the readability of code: comments, appropriate naming of variables, and proper indentation. Comments explain the purpose of code, making it easier for others to understand. Variable names should clearly indicate what data they hold. Indentation organizes blocks of code visually to improve comprehension. Syntax highlighting, where code elements are color-coded, also aids readability by allowing quick identification of statements. All of these factors help programmers better understand existing code and make modifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

D1- Discuss the Factors That Can Improve the Readability of Code

Improving the Readability of Code


Comments:
Comments in computer programming are basically brief annotations or explanations in
the source code of a computer program. They are added to help other programmers that
did not originally develop the program to understand the code. Using comments can
actually be very beneficial for the user as they make the code easier to read and it they
also describe the purpose of each line of the code. This all can make locating bugs and
making improvements to the code much faster as they can now easily spot any errors in
the code. Comments are a very useful tool that can improve the readability of code by
letting a programmer add comments alongside statements which explain various
functionality and therefore making the program more readable. Comments are defined in
different ways; it depends on the programming language that the programmer is using. So
in order to enter a comment in Visual Basic must the programmer ensure that he/she
added an apostrophe (‘) before he/she start typing it. In other programming languages
such as #C or CSS do they use double slashes (//) and stars (*) before they start typing the
comment. Comments can be entered anywhere in the program, as they are ignored by the
computer. So that means that the user can enter whatever he/she wants as it won’t affect
the computer in anyway.
Comment symbol

Comment

The image above shows us an example of a comment that was typed in Visual Basic.
Comments in the Visual Basic programming language are always highlighted in green. In
front of the comment is the comment symbol which is in this case here the apostrophe (‘).
That symbol must always be added before the programmer starts typing a comment or
otherwise will the program breaks down, as the Visual Basic compiler thinks that the text
does belong to a code, which doesn’t even exist. In the image above can we also see that
the comment doesn’t fit on a single line and does therefore goes into second line. So if the
comment requires more than one line is it very essential that the user use the comment
symbol on each line.
An advantage of using comments is that it helps other programmers to understand the
code much better, that the previous programmer has left them behind.
A disadvantage of using comments is that they are time consuming as a programmer have
to use appropriate comments that are detailed enough for another person to understand.
Appropriate names for variables:
One of the factors that improves the readability of code is appropriate names for
variables which basically means that the programmers need to make sure that they use
appropriate names for the variables and not any random ones. So if the programmers do
use random variable names such as “FN”, “MN” or “LS” can that affect other programmers
understanding of the code as they probably not know what the purpose of the variable is
and that will eventually make it harder for them to edit the code. Using appropriate
variable names is useful when the programmers wants to improve the readability of the
code as they make the understanding the purpose of a variable much simpler. In addition
to that does it also make it for programmers much easier to recognise the variables role in
the program. A variable name can also include the datatype of the variable that can
minimise the chances of the variable being assigned the
wrong data type.

Name for the variable

The actual variable


The actual variable

In the example above can we see two statements that were typed in Visual Basic. The first
statement (“Dim variable 1 as string”) is an example where the programmer has use a
random name for the variable. So that eventually make it harder for the other
programmers to understand that code, as they probably have no idea what the purpose of
the variable could be and that make eventually for them harder to edit to code. So that’s
why it is really important to use appropriate names for the variables. The second example
(Dim firstName as string) does show us a statement where an appropriate name has been
given to the variable. That is quite beneficial for other programmers as that will give them
a better idea of what they will be used for or what data will be stored in that.
A benefit of using appropriate names for variable is that programmers can edit the code
much easily and relate the code with appropriate variables. Another advantage of using
appropriate names for variable is that less errors will be made when referring back to the
variables later on in the code. On the other hand, can using appropriate names for
variable also be a bad thing; then sometimes can be very difficult for a programmer to
think of appropriate names for variables that all programmers can understand in a large
program that uses lots of variables.
Indentation:
One of the factors that improves the readability of code is Indentation. Indentation is
basically when the programmer breaks down each section of the source code to make it
for them easier to understand and read the code much better. Indentation can also be
used to separate blocks of code such as selection statements (also known as If/else
statements that cause the program to be transferred to a specific flow based upon
whether a certain condition is true or not) and loops (do carry out instructions for a
certain amount of times until a certain condition is reached.) Nesting is a technique that
basically improve the code by showing a chunk of codes is “nested” within another chunk
of code, and that does allow the reader to simply follow that nesting pattern. When the
code has been improved does the code go into the testing stage of the software
development cycle, where developers and IT users need to test the code first before they
released it. In this stage are the developers required to improve the code by making it
easier to read.

In this example, are the


variables separated from
each other, this will
eventually improve the
readability of the code.

The image above shows us an example of how programmers have indented that code. We
can see that the programmer has used appropriate spaces between all the variables which
were First name, Middle name and Last name to create space in the program to make it
easier to read. Other programmers who never came in touch with that code, would be
able to understand each of the procedures, as the code has been indented properly. If
that wouldn’t be the case would it firstly be very difficult to read the code and secondly it
would take a lot of time to revisit the code and use it.
An advantage of having all your coded indented is that makes the code looks very neat,
which means that the readability of the code will improve. In addition to that will it be
very easy for the programmer to read, to understand, to maintain and to maintain the
code. Another reason why indentation is quite advantageous for programmers is that it
saves their time. Programmers can see where the end of a code block is, rather than
having to read each line until they find it. So that’s why is it quite important to have codes
indented.
On the other hand, can indentation in the wrong places be even more confusing when the
programmer reads the code, this can even then lead to the program code not working.
Another drawback of Indentation is that it is very time consuming to indent code properly,
however indent properly makes therefore the code much easier to read.
Syntax Highlighting:
There are several programming languages such as Visual Basic or C++ which offer a feature
that is called Syntax Highlighting. Syntax Highlighting basically allows key parts of the code to
be displayed in different colours and fonts depending on their purpose. For instance, in the
Visual Basic programming language is the default colour for variables blue, comments are
coloured green and variable names are highlighted in black. However some of these programs
allow the user to customize, so that means that they can change the colour of each code part
within the application, this is generally a great and standard colour scheme for manipulating
code. Syntax highlighting does improve the readability of code; colour coding the code which
the programmers has written allows others viewers to identify particular elements of the
code and it also allows user to promptly tell the purpose of particular statements within the
code. That makes it much easier for developers to read, understand and modify the code.

The Code in the example is colour


coded; that makes it for
programmers easier to read,

The image above shows us an example of how syntax highlighting has been used in a program.
We can clearly see use of different colours here, which makes if for the programmers much
easier to read the code and understand. From just reading the code can programmers clearly
identify the comments which are highlighted in green, these has been added to understand
the purpose of each line much better. The text in the example that is highlighted in pink is the
text that gets displayed on the screen as notification and the variables in that example are
coloured in blue and violet. If everything would have the same colour then would
programmers find it very difficult to read the code. That why is it very essential to use
different colours for different parts of the code to avoid confusion. Colour and Font can be
changed within the application.

Syntax highlighting offers several advantages including that it helps programmers to detect
errors much faster in the program. As different parts of the codes are coloured in different
colours will it be very easy for programmers to find the mistake. Programmers can see where
the error was made, instead of having to go through each single line until they find it. Another
reason why syntax highlighting is quite advantageous for the user is that it tells programmers
and developers straightforwardly what the purpose of particular statements within the code
is, without confusing them. On the other hand does syntax highlighting also offer several
disadvantages such as that different programming languages such as Visual Basic, C++ or
Python do have different colours for their codes. For instance, in Visual Basic are variables
coloured in blue, but in another program might variables be purple. The programmers can get
confuse with all these colours.
Line Breaks:
Line Breaks or New Lines helps the programmers to structure and organise the code much
better. They are used to separate long lines of code into smaller sections so that each line
of the code is on a new line. This will help to define different areas of code which will
make it for the programmers easier to follow the code. Also, having more space can make
it easier when viewing and trying to read the code.

In the example above can we clearly see a Line Break that a programmer has added into
that program. The reason why the programmer has added that line is that it helps the
programmers to structure and organise the code much better. In the image can I see that
the long lines of code were separated into smaller sections so that each line of the code is
on a new line. This will make it easier for programmers to follow the code.
Line Breaks offer several advantages such as that

You might also like