코드 냄새 167 - 해싱 비교
TL;DR: If you check for the hash, you should also check for equality
문제
솔루션
문맥
2022년 10월 7일에 더 큰 블록체인 중 하나가 중단되어야 했습니다.
 This news은 대부분의 블록체인이 정의상 탈중앙화되어 있기 때문에 충격적이었습니다.
여기에서 전체 기사를 읽을 수 있습니다.
   
    
      
    
  
   
    
      해커가 코드 냄새를 악용하여 $566M USD를 훔친 방법
      Maxi Contieri ・ 10월 8일 ・ 4분 읽기
      
        #programming
        #java
        #web3
        #blockchain
      
    
  
 샘플 코드
 잘못된
 public class Person {
public String name;
// Public attributes are another smell  
 @Override
 public boolean equals(Person anotherPerson) {
   return name.equals(anotherPerson.name); 
 }
@Override
 public int hashCode() {
   return (int)(Math.random()*256); 
 }
 // This is just an example of non correlation  
 // When using HashMaps we can make a mistake 
 // and guess the object is not present in the collection
}
 오른쪽
 public class Person {
public String name;
// Public attributes are another smell  
 @Override
 public boolean equals(Person anotherPerson) {
   return name.equals(anotherPerson.name); 
 }
@Override
 public int hashCode() {
   return name.hashCode(); 
 }
 // This is just an example of non correlation  
}
 발각
[X] 반자동
많은 린터에는 해시 및 평등 재정의에 대한 규칙이 있습니다.
돌연변이 테스트를 통해 동일한 해시로 다른 개체를 시드하고 테스트를 확인할 수 있습니다.
    해커가 코드 냄새를 악용하여 $566M USD를 훔친 방법
Maxi Contieri ・ 10월 8일 ・ 4분 읽기
잘못된
public class Person {
public String name;
// Public attributes are another smell  
 @Override
 public boolean equals(Person anotherPerson) {
   return name.equals(anotherPerson.name); 
 }
@Override
 public int hashCode() {
   return (int)(Math.random()*256); 
 }
 // This is just an example of non correlation  
 // When using HashMaps we can make a mistake 
 // and guess the object is not present in the collection
}
오른쪽
public class Person {
public String name;
// Public attributes are another smell  
 @Override
 public boolean equals(Person anotherPerson) {
   return name.equals(anotherPerson.name); 
 }
@Override
 public int hashCode() {
   return name.hashCode(); 
 }
 // This is just an example of non correlation  
}
발각
[X] 반자동
많은 린터에는 해시 및 평등 재정의에 대한 규칙이 있습니다.
돌연변이 테스트를 통해 동일한 해시로 다른 개체를 시드하고 테스트를 확인할 수 있습니다.
결론
모든 성능 향상에는 단점이 있습니다.
캐시와 복제가 주목할만한 예입니다.
우리는 그것들을 조심스럽게 사용할 수 있습니다.
 처지
   
    
      
    
  
   
    
      코드 냄새 49 - 캐시
      Maxi Contieri ・ 12월 11일 '20 ・ 1분 읽기
      
        #oop
        #webdev
        #codenewbie
        #caching
      
    
  
   
    
      
    
  
   
    
      코드 냄새 150 - 동등 비교
      Maxi Contieri ・ 7월 19일 ・ 2분 읽기
      
        #javascript
        #webdev
        #beginners
        #programming
      
    
  
 더 많은 정보
 Equality and Hash
 Hashcode in Java
 Hashcode vs Equal
 부인 성명
코드 냄새는 그냥 내 .
 
This will surprise some of your readers, but my primary interest is not with computer security. I am primarily interested in writing software that works as intended.
비에체 베네마
   
    
      
    
  
   
    
      소프트웨어 엔지니어링 좋은 인용구
      Maxi Contieri ・ 12월 28일 '20 ・ 13분 읽기
      
        #codenewbie
        #programming
        #quotes
        #software
      
    
  
이 기사는 CodeSmell 시리즈의 일부입니다.
   
    
      
    
  
   
    
      코드에서 냄새 나는 부분을 찾는 방법
      Maxi Contieri ・ 2021년 5월 21일 ・ 7분 읽기
      
        #codenewbie
        #tutorial
        #codequality
        #beginners
      
    
  
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(코드 냄새 167 - 해싱 비교), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://dev.to/mcsee/code-smell-167-hashing-comparison-3c4g
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
    코드 냄새 49 - 캐시
Maxi Contieri ・ 12월 11일 '20 ・ 1분 읽기
    코드 냄새 150 - 동등 비교
Maxi Contieri ・ 7월 19일 ・ 2분 읽기
더 많은 정보
 Equality and Hash
 Hashcode in Java
 Hashcode vs Equal
 부인 성명
코드 냄새는 그냥 내 .
 
This will surprise some of your readers, but my primary interest is not with computer security. I am primarily interested in writing software that works as intended.
비에체 베네마
   
    
      
    
  
   
    
      소프트웨어 엔지니어링 좋은 인용구
      Maxi Contieri ・ 12월 28일 '20 ・ 13분 읽기
      
        #codenewbie
        #programming
        #quotes
        #software
      
    
  
이 기사는 CodeSmell 시리즈의 일부입니다.
   
    
      
    
  
   
    
      코드에서 냄새 나는 부분을 찾는 방법
      Maxi Contieri ・ 2021년 5월 21일 ・ 7분 읽기
      
        #codenewbie
        #tutorial
        #codequality
        #beginners
      
    
  
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(코드 냄새 167 - 해싱 비교), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://dev.to/mcsee/code-smell-167-hashing-comparison-3c4g
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
코드 냄새는 그냥 내 .
This will surprise some of your readers, but my primary interest is not with computer security. I am primarily interested in writing software that works as intended.
비에체 베네마
    소프트웨어 엔지니어링 좋은 인용구
Maxi Contieri ・ 12월 28일 '20 ・ 13분 읽기
이 기사는 CodeSmell 시리즈의 일부입니다.
    코드에서 냄새 나는 부분을 찾는 방법
Maxi Contieri ・ 2021년 5월 21일 ・ 7분 읽기
Reference
이 문제에 관하여(코드 냄새 167 - 해싱 비교), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/mcsee/code-smell-167-hashing-comparison-3c4g텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)