Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Assignment

Name: Saad Zaheen


Reg No: FA21-BSE-061
Section: B2
Submitted To: Samia Riaz

Question 1:
What is refactoring? Describes its techniques.

Answer:
Refactoring is defined as systematic process of improving existing computer code, without
adding new functionality or changing external behavior of the code. It is intended to change
the implementation, definition, structure of code without changing functionality of software.
The goal of refactoring is not to add new functionality or remove an existing one. The main
goal of refactoring is to make code easier to maintain in future and to fight technical debt.

Techniques:
There are more than 70 refactoring techniques that exist. But we will discuss only a few, more
common ones.
Different techniques of refactoring are following:
1. Red-Green Refactoring:
Red-Green is the most popular and widely used code refactoring technique in the Agile
software development process. This technique follows the “test-first” approach to
design and implementation, this lays the foundation for all forms of refactoring.
2. Refactoring by Refactoring:
This technique is mostly used by developers when there is a need to do a large amount
of refactoring. Mainly we use this technique to reduce the redundancy (duplication) in
our code. This involves class inheritances, hierarchy, creating new classes and interfaces,
extraction, replacing inheritance with the delegation, and vice versa.

3. Composing method:
During the development phase of an application a lot of times we write long methods in
our program. These long methods make your code extremely hard to understand and
hard to change. The composing method is mostly used in these cases.

4. Simplifying Methods:
There are two techniques involved in this approach that are:
• Simplifying Conditional Expressions Refactoring:
Conditional statement in programming becomes more logical and complicated
over time. You need to simplify the logic in your code to understand the whole
program.
• Simplifying Method Calls Refactoring:
In this approach, we make method calls simpler and easier to understand. We
work on the interaction between classes, and we simplify the interfaces for
them.

5. Moving Features Between Objects:


In this technique, we create new classes, and we move the functionality safely between
old and new classes. We hide the implementation details from public access.
When you find that a class has so many responsibilities and too much thing is going on
or when you find that a class is unnecessary and doing nothing in an application, you can
move the code from this class to another class and delete it altogether.

6. Preparatory Refactoring:
This approach is best to use when you notice the need for refactoring while adding
some new features in an application. So basically, it’s a part of a software update with a
separate refactoring process. You save yourself with future technical debt if you notice
that the code needs to be updated during the earlier phases of feature development.

7. User Interface Refactoring:


You can make simple changes in UI and refactor the code. For example: align entry field,
apply font, reword in active voice indicate the format, apply common button size, and
increase color contrast, etc.

Question 2:
What are benefits of debugging? Name different techniques for debugging?

Answer:
Benefits of debugging are given below:

• Saves Time:
Performing debugging at the initial stage saves the time of software developers
as they can avoid the use of complex codes in software development. It not only
saves the time of software developers but also saves their energy.
• Reports Errors:
It gives error report immediately as soon as they occur. This allows the detection
of error at an early stage and makes the software development process a stress
free.

• Easy Interpretations:
It provides easy interpretations by providing more information about data
structures Release bug-free software: By finding errors in software, it allows
developers to fix them before releasing them and provides bug-free software to
the customers.

Different techniques for debugging:

1. Ask Yourself the Right Questions:


It involves defining the problem and asking yourself questions about it. For example:
• Have you encountered these types of problems before?
• What did you do to fix them?
• Where and why do you think the bugs occurred?

Often, asking these questions will lead to forming some kind of hypothesis about the
nature of the errors, which will allow to find the root cause and resolve them.

2. Pay Attention to Error Messages:


Error messages aren’t just there as an annoyance — they can actually tell you exactly
what the problem is with your software. So, when an error message pops up, make sure
you read it, because it can give you a lot of insight into what’s going on with the
product.
3. Leverage a Debugger:
A debugger, also known as a debugging tool or debugging mode, can be used to easily
identify and correct bugs. To effectively leverage the tool, you’ll need to run your
program within the debugger, which allows you to monitor it in real-time and see the
error when it occurs.
4. Log Everything:
Make sure you’re logging every issue you encounter, as well as steps you take to
address them and ensure your program is running correctly. Once you’ve documented
the error, you can start mapping out potential scenarios and solutions.
5. Localize the Problem:
The method of problem localization entails removing pieces of code line by line until you
find the issue that is interfering with your program. While this is a somewhat
painstaking and involved way of identifying the error that’s taking place, it can be highly
effective in determining what, exactly, is going wrong with your product.
6. Try to Replicate the Problem:
By replicating the problem, you’ll find out what the nature of the problem is precisely. In
fact, this can lead to you creating better, cleaner code in general since you’re exercising
the critical thinking skills required to find the cause of an issue.
7. Turn to the Community:
It’s highly likely that any error you encounter is one others have encountered before
you. It can be very helpful to turn to a community associated with the language,
framework, or another development tool you’re using to find a solution for addressing
the bug you’ve encountered.
8. Test, Test, and Test Again:
The best way to spot bugs and successfully resolve them before they derail your app by
repeatedly testing the product. While the QA team will more thoroughly vet the
product, developers themselves can script simple tests during the development phase,
such as unit testing, which involves individually testing different pieces of the code.

You might also like