본문 바로가기

Development

[Refactoring] 여러 겹의 조건문을 감시절로 전환 조건식은 주로 두 가지 형태를 띤다. 첫째는 어느 한 경로가 정상인지를 검사하는 형태 둘째는 조건식 판별의 한 결과만 정상작동 나머지는 비정상작동이 되는 형태이다. 정상동작이 일부라고 한다면 if절과 else절로 구성된 조건문을 사용하고 조건이 특이한 조건이라면 그 조건을 검사해서 조건이 true 일때 반환하자 이런 식의 검사를 감시절 guard clause 이라고 한다. if (i_isDead) {result = deadAmount(); } else { if (_isSeparated) {result = separatedAmount();} else {if (isRetired) {result = retiredAmount();} else {result = normalPayAmount();}}} 위와 같이 i.. 더보기
[Refactoring] 제어 플래그 제거 여러가지 조건문이 사용된 코드에는 조건문을 빠져나가는 시점을 결정하는 제어 플래그가 흔히 사용이 된다. 하지만 이탈점을 하나만 사용하면 코드 안의 각종 특이한 플래그로 인해 조건문이 복잡해진다. 이러한 복잡한 조건문을 방지하는 break, continue문이 있다. for (int i=0;i 더보기
[IOS] Instrument Alloc 항목 설명 Instrument를 통해 메모리 사용량을 확인할 때 필요한 용어 정리 Live Byte - 현재 Alloc된 Object크기, #의 경우 갯수 #Transitory - release된 Object수 Overall Bytes - 지금까지 Alloc된 Objject 크기, #의 경우 갯수 [출처] Xcode Tools|작성자 인생 더보기
[IOS Library] 이동 & 삽입 & 확대해서 보기 등등 다양한 기능을 가진 GridView 코드 보러가기 Features - General:Works on both the iPhone and iPad (best suited for iPad)Works on both portrait and landscape orientationInherits from UIScrollView - you can override the UIScrollViewDelegate if you wishReusable cellsEdit mode to delete cellsGestures work great inside of the scrollView4 different layout strategies (Vertical, Horizontal, Horizontal Paged LTR/TTB)Possibility to provide y.. 더보기
[Refactoring] 조건문의 공통 실행 코드 빼내기 조건문의 모든 절에 실행 코드가 있을땐 같은 부분을 빼내자~! if (isSpecialDeal()) {total = price * 0.95;send();} else {total = price * 0.98;send();} 위와 같이 되어있는 조건문을 리팩토링을 하면.. if (isSpecialDeal()) {total = price * 0.95;} else {total = price * 0.98;}send(); 이렇게 하자~! 더보기
[Refactoring] 중복 조건식 통합 여러 조건의 검사식의 결과가 같을 땐 합치자~! double disabilityAmount () {if (_seniority 12) return 0;if (_isPartTime) return 0;.........} 위와 같은 조건식을 만들었을때.. 조건을 묶어서 함수로 만들어 보기 좋게하자~! double disabilityAmount () {if (isNotEligableForDisability()) return 0;........} 함수 내용은 귀찮아서.... 더보기
[Refactoring] 조건문 쪼개기 조건문 쪼개기 예시if (date.before(SUMMER_START) || date.after(SUMMER_END))charge = quantity * _winterRate + _winterServiceCharge;elsecharge = quantity * _summerRate; 위의 조건문을 보기 쉽게 리팩토링을 하면 if (notSummer(date))charge = winterCharge(quantity);elsecharge = summerCharge(quantity); 이 처럼 메소드로 바꾸어 보기 쉽게 만든다. 더보기
[IOS] UIScrollView에서 스크롤 중 NSTImer가 동작이 되게.. UIScrollView에서 Timer를 사용할때 [NSTimer scheduledTimerWithTimeInterval:.........] 위의 함수로 사용하면 스크롤이 완전히 종료된 후에 호출이 되어진다.그래서 아래의 코드로 대체를 하면 스크롤 중에도 동작을 합니다. NSTimer *timer [NSTimer timerWithTimeInterval:0.3 target:self selector:@selector(update:) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:m_timer forMode:NSRunLoopCommonModes]; 더보기
tomcat log보기 AWS에서 tomcat6 설치후 경로는 var/log/tomcat6/ 이동후 tail -f catalina.out 을하면 로그를 실시간으로 확인할 수 있다. 더보기
[HQL] 하이버네이트 쿼리문 작성 final Query query = this.mSessionFactory.getCurrentSession().createQuery("from " + PostLike.class.getName() + " where likeId = :likeId "); query.setParameter("likeId", postLikeId); query.uniqueResult(); 위의 코드와 같이 쿼리문을 작성할때 :likeId 라고 입력하고 query.setParameter("likeId", postLikeId); 이와 같이 값을 대입해주면 가독성 좋게 구현할할 수 있다. 더보기