We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Originally posted by JoisFe February 22, 2023
static Random rnd = new Random(); static int random(int n) { return Math.abs(rnd.nextInt()) % n; }
static int random(int n) { return Math.abs(rnd.nextInt()) % n; } public static void main(String[] args) { int n = 2 * (Integer.MAX_VALUE / 3); int low = 0; for (int i = 0; i < 1000000; ++i) { if (random(n) < n / 2) { ++low; } } System.out.println(low); }
이미 잘 만들어진 바퀴를 사용하면 되지 바퀴를 만들려고 고생할 필요가 없다.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Discussed in https://github.com/orgs/Study-2-Effective-Java/discussions/136
Originally posted by JoisFe February 22, 2023
아이템 59. 라이브러리를 익히고 사용하라
예시 코드
위 문제의 해결법?
다른 해결법
표준 라이브러리 사용의 장점
1. 표준 라이브러리를 사용하면 그 코드를 작성한 전문가의 지식과 앞서 사용한 다른 프로그래머들의 경험을 활용할 수 있음
Random 의 문제점
2. 핵심적인 일과 크게 관련 없는 문제를 해결하느라 시간을 허비하지 않아도 된다.
3. 따로 노력하지 않아도 성능이 지속해서 개선 됨
4. 기능이 점점 많아짐
5. 표준 라이브러리를 활용해 작성한 코드가 많은 사람에게 낯익은 코드가 됨
그럼에도 불구하고 직접 구현하는 경우
대부분 라이브러리에 그런 기능이 있는지 모르기 때문
라이브러리가 필요한 기능을 충분히 제공하지 못하는 경우
정리
이미 잘 만들어진 바퀴를 사용하면 되지 바퀴를 만들려고 고생할 필요가 없다.
라는 명언이 생각이 났는데 책에서도 이 예시를 들었음The text was updated successfully, but these errors were encountered: