function add(a, b) {
return a + b;
}
function add(a, b) {
console.log(a);
console.log(b);
console.log(a);
console.log(b);
console.log(a);
console.log(b);
console.log(a);
console.log(b);
console.log(a);
console.log(b);
console.log(a);
console.log(b);
return a + b;
}
console.log
는 인자로 들어온 a
, b
값을 확인하기 위한 테스트의 용도 외에 어떤 영향도 미치지 않습니다.console.log
가 최종 결과물에 남아있다면 가독성을 해칠 수 있습니다.console.log
가 잔존한 상태로 새로운 테스트를 위해 console.log
를 추가했을 때console.log
와 혼재되어서 내가 진짜로 확인하고 싶은 값이 무엇인지 알기 어려워집니다.console.log
를 지우는 것은console.log
는 지워주셔야 합니다.// bad
let value = "Tom";
let value2 = "Cruise"
// good
let firstName = "Tom"
let lastName = "Cruise"
value
와 value2
라는 변수가 무슨 값을 담고있는지 바로 이해하실 수 있으신가요?firstName
과 lastName
이라는 변수명을 보면 각각의 변수가 이름과 성을 나타내고있다는것을 바로 알 수 있습니다.// bad
const data = ["tory", "mozzi"];
// good
const petsOfYeonuk = ["tory", "mozzi"];
data
라는 변수에 담긴 배열이 어떤 data
인지 명확히 인식이 되시나요?data
인 건 알겠는데, 무슨 data
인지 알 수가 없습니다.data
, value
등의 포괄적인 이름은 지양해주셔야 합니다.petsOfYeonuk
) 바로 이해할 수 있습니다.개발자가 보내는 시간 중 코드를 짜는 시간은 10% 밖에 안된다고 합니다.
나머지 90% 시간은 모두 코드를 읽고 해석하면서 시간을 보낸다고 합니다.
그렇기 때문에 내가 짠 코드를 미래의 내가, 그리고 협업하는 다른 팀원들이 읽기 쉽게 만드는 일은
가장 기본이면서 가장 중요한 일입니다.
따라서, 모두 명확하고 직관적인 네이밍을 통해서 가독성이 좋은 코드를 짜셔야 합니다.
const thisIsButton = document.getElementsByClassName('login-btn')[0];
thisIsButton.addEventListener('click', function() {
const password = document.getElementById('password').value;
const rePassword = document.getElementById('re-password').value;
if (!password) {
alert('비밀번호를 입력해주세요!');
return;
}
if (!rePassword) {
alert('비밀번호 확인을 입력해주세요!');
return;
}
if (password !== rePassword) {
alert('비밀번호가 맞지 않습니다!');
return;
}
alert('회원가입 성공!!');
});
const thisIsButton = document.getElementsByClassName('login-btn')[0];
thisIsButton.addEventListener('click', function() {
const password = document.getElementById('password').value;
const rePassword = document.getElementById('re-password').value;
if (!password) {
alert('비밀번호를 입력해주세요!');
return;
}
if (!rePassword) {
alert('비밀번호 확인을 입력해주세요!');
return;
}
if (password !== rePassword) {
alert('비밀번호가 맞지 않습니다!');
return;
}
alert('회원가입 성공!!');
});
const thisIsButton = document.getElementsByClassName('login-btn')[0];
thisIsButton.addEventListener('click', function() {
const password = document.getElementById('password').value;
const rePassword = document.getElementById('re-password').value;
if (!password) {
alert('비밀번호를 입력해주세요!');
return;
}
if (!rePassword) {
alert('비밀번호 확인을 입력해주세요!');
return;
}
if (password !== rePassword) {
alert('비밀번호가 맞지 않습니다!');
return;
}
alert('회원가입 성공!!');
});
셀프 리팩토링 리팩토링이무엇일까요? 리팩토링은 소프트웨어의 겉보기 동작은 그대로 유지한 채,
코드를 이해하고 수정하기 쉽도록 내부 구조를 변경하는 기법입니다.
제목:셀프 리팩토링
본문:
리팩토링이무엇일까요? 리팩토링은 소프트웨어의 겉보기 동작은 그대로 유지한 채,
코드를 이해하고 수정하기 쉽도록 내부 구조를 변경하는 기법입니다.
<article>
<h1>셀프 리팩토링</h1>
<p>
리팩토링이무엇일까요? 리팩토링은 소프트웨어의 겉보기 동작은 그대로 유지한
채, 코드를 이해하고 수정하기 쉽도록 내부 구조를 변경하는 기법입니다.
</p>
</article>
semantic vs non-semantic tag
<!-- non-semantic -->
<div style="font-size:32px">제목</div>
<!-- semantic -->
<h1>제목</h1>
<!-- non-semantic -->
<div class="mentorList">
<div>Joonsik</div>
<div>Jongtaek</div>
<div>Seonghoon</div>
<div>Dohyun</div>
<div>Yeonuk</div>
</div>
<!-- semantic -->
<ul class="mentorList">
<li>Joonsik</li>
<li>Jongtaek</li>
<li>Seonghoon</li>
<li>Dohyun</li>
<li>Yeonuk</li>
</ul>
( 위와 같은 이유로 alt
속성은 중요하기 때문에 src
속성보다 먼저 작성하는게 좋습니다. )
<!-- Bad -->
<img src="/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" />
<!-- Good -->
<img alt="Google Logo" src="/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" />
<div>
) 와 닫는태그 (</div>
)로 이루어져 있습니다.<!-- Bad -->
<input type="password"></input>
<!-- Good -->
<input type="password" />
<br>
<hr>
<img>
<meta>
<link>
<input>
우리의 옷장을 생각해봅시다. 우리는 자연스럽게 상의, 하의, 겨울옷, 여름옷 등의 기준으로
보관하는 공간을 분리합니다. 기준없이 뒤섞여 있어도 옷에는 어떠한 영향도 미치지 않지만
우리는 자연스럽게 옷을 찾기 편하게 하기 위함입니다.
Javascript
유지보수보다 힘듭니다..login-btn {
height: 2.5rem;
margin: 0.625rem 0px;
border: 0;
border-radius: 0.3125rem;
background-color: var(--disabled);
color: var(--white);
font-weight: 700;
font-size: 0.9375rem;
}
.find-password {
margin: 3.75rem 0 1.25rem 0;
color: #00376b;
text-align: center;
font-size: 12px;
}
.enabled-btn {
background-color: var(--enabled);
cursor: pointer;
}
.disabled-btn {
background-color: var(--disabled);
cursor: default;
}
.login-btn {
height: 2.5rem;
margin: 0.625rem 0px;
border: 0;
border-radius: 0.3125rem;
background-color: var(--disabled);
color: var(--white);
font-weight: 700;
font-size: 0.9375rem;
}
.find-password {
margin: 3.75rem 0 1.25rem 0;
color: #00376b;
text-align: center;
font-size: 12px;
}
.enabled-btn {
background-color: var(--enabled);
cursor: pointer;
}
.disabled-btn {
background-color: var(--disabled);
cursor: default;
}
display:block;
을 부여하는 것width:100%
를 부여하는 것<div>, <article>
등 수많은 요소는 이미 display:block을 default style로 적용이 되고 있습니다.display:block
을 선언해줘서 불필요한 코드를 작성할 필요는 없습니다.display:block
요소들은 기본적으로 부모요소의 너비를 모두 차지하고 있습니다.display:block
요소들에 불필요하게 width:100%
를 선언해줄 필요도 없습니다.CSS
유지보수가 Javascript
유지보수보다 힘듭니다.// bad
.feedList {
height:100vh;
}
.feed{
height:300px;
}
// good
.feedList {
padding-top:20px;
}
.feed{
height:300px;
}
(feedList > feed * n)
자식요소의 높이 + 20px(padding-top 값)
로 유동적으로 변할 수 있게 됩니다.