프로그래밍
DRY
은율실험실
2024. 4. 9. 00:00
반응형
DRY 은(는) Dont Repeat Yourself 의 축약어로,
중복된 코드를 제거하는 것을 의미하는 개발의 기본 원칙이에요.
Bad
final class Program
{
public static void main(String[] args)
{
for (var i = 0; i < 100; i++)
{
System.out.println(i);
}
for (var i = 0; i < 200; i++)
{
System.out.println(i);
}
}
}
Good
final class Program
{
public static void main(String[] args)
{
reuse_where_possible(100);
reuse_where_possible(200);
}
public static void reuse_where_possible(int length)
{
for (var i = 0; i < length; i++)
{
System.out.println(i);
}
}
}
반응형