Motivation:
You need to read existing source code to add a new feature or fix a bug or clone its features to another language or system.
Suggestion:
- Try building and running the code without any modification.
- Try building and running the code with your inputs.
- Try changing a variable name to meaningful name and make sure that the change does not break anything.
- Try changing a package or module name to a meaningful name and make sure that that the change does not break anything.
- Try breaking a long method to smaller ones.
- Try breaking a large object or file to smaller ones.
- Try modifying or adding simple UI elements without touching the business logic or data layer.
- Try writing a unit test for a function.
- Try replacing an algorithm with with a better one.
- Try replacing an old component with a newer or better one.
- Try recreating the code structure from the separate components. If you cannot do this then try to understand the architecture of the existing source code.
- If you get an error when making the changes above then try showing the error on client side.
- If you cannot show the error on client side then try identifying the logic flow of the code related to the error, debug information, and learn about new terminologies or concepts in the code.
Example:
const maskPhone = (val) => {
const x = val.replace(/\D+/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
return !x[2] ? x[1] : `(${x[1]}) ${x[2]}` + (x[3] ? `-${x[3]}` : ``);
};
export { maskPhone }
If you are not sure about what the JavaScript code above does then try to learn
- what is a Regular Expression and
- how a Regular Expression is evaluated. This is a helpful tool for learning Regular Expression.
Another example:
<div class="container">
<iframe class="responsive-iframe" src="https://www.youtube.com/embed/u9Dg-g7t2l4"></iframe>
</div>
.container {
position: relative;
overflow: hidden;
width: 100%;
padding-top: 56.25%; /* 16:9 Aspect Ratio (divide 9 by 16 = 0.5625) */
}
/* Style the iframe to fit in the container div with full height and width */
.responsive-iframe {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
}
If you are not sure about what the HTML and CSS code above do then try to learn
- how many ways an element can be placed in a web page (a document),
- what is the position relationship between an element and its parent,
- what is the position relationship between an element and its siblings,
- what is the position relationship between an element and the document root, and
- what
position: relative
,position: absolute
,overflow: hidden
do.
(Visited 52 times, 1 visits today)