Coder Social home page Coder Social logo

ios-bank-manager's Introduction

iOS Engineer at Hyundai Motor Group (2023.03 ~)

  • working on next-generation Connected Car Service Applications that integrate with Hyundai, Kia, and Genesis brands to provide global customers with improved connectivity.

  • using SwiftUI and The Composable Architecture(TCA), etc.

iOS Developer at Flitto (2022.06 ~ 2023.02)

About Me

Education

  • Yagom Academy iOS Career Camp

    • 2021-10-04 ~ 2022-04-01 (6 months)
    • studied Swift, UIKit, SwiftUI, HIG, git/github
    • completed 9 projects with pair programming and code reviews.
    • 🎨 See all projects
  • Yagom Academy iOS Starter Camp

    • 2021-08-02 ~ 2021-09-03 (5 weeks)
    • studied basic Swift
  • 🎓 Korea Univ. ('17)

    • BS in Science & Economics (double major)

Hits

ios-bank-manager's People

Contributors

jager-yoo avatar jsim27 avatar yagom avatar

ios-bank-manager's Issues

소수점 아래 2자리 미만을 '버리는' 방법 실험

프로젝트 요구사항에서는 업무에 걸린 시간을 소수점 이하 2자리 까지만 보여주고 있습니다.

저희는 아래와 같은 String 포맷을 통해 소수점 이하 2자리까지만 보이게 처리를 해줬는데요.
저희가 의도했던 것과 다르게, 위의 포맷은 소수점 2자리 미만을 버리는 게 아니라, 그 숫자가 6 이상이라면 반올림 처리를 하는 것을 발견했습니다.

String(format: "%.2f", Double)

String(format: "%.2f", 2.566) // -> "2.57"

생각해보면, 회사에서 야근을 한다고 했을 때, 근무시간을 더 올려서 말하는 경우는 드뭅니다.
통상적으로는 근무 시간을 조금 낮춰서 말하곤 합니다. (1시간 3분 야근했다면, 1시간 야근으로 올리듯이)

그래서 저희는 완벽하게 소수점 아래 2자리 미만을 버리는 방법을 적용하기로 했습니다.
다양한 방법이 있겠지만, 저희는 아래 3가지를 고려했습니다.


1️⃣ 매직 넘버 -> 100을 곱하고 소수를 모두 버린 뒤 다시 100으로 나눔

let test = 100.569999999
print((floor(test * 100)) / 100) // -> "100.56"

2️⃣ NumberFormatter

let numberFormatter = NumberFormatter()
numberFormatter.maximumFractionDigits = 2
numberFormatter.roundingMode = .floor

let test = 100.569999999
print(numberFormatter.string(for: test)!) // -> "100.56"

3️⃣ 매직 넘버 with 파라미터

extension Double {
    func roundedOff(maximumFractionDigits: Double) -> String {
        let multiplier = pow(10, maximumFractionDigits)
        let converted = floor(self * multiplier) / multiplier
        
        return String(converted)
    }
}

let test = 100.569999999
print(test.roundedOff(maximumFractionDigits: 2)) // -> "100.56"

⚠️ 모든 방법에서, Double 타입의 숫자의 자리수가 매우 커지면 오차 때문인지 반올림이 일어나는 현상을 발견했습니다.
저희는 그 오차의 이유가 Double 타입으로 표현할 수 있는 숫자의 최대 크기를 벗어나서 이지 않을까 생각했지만, 아직 확실하진 않습니다.

구조체 타입이 delegate 으로 사용될 수 있을까?

delegate 을 구조체로 만들면 무슨 장단점이 있을까?

  • 장점

    • 순환 참조의 리스크가 사라진다.
  • 단점

    • 인스턴스가 하나 더 생기게 된다. (delegate)
    • 구조체가 소유한 프로퍼티를 수정하는 mutating 메서드가 생긴다면, 어떤 인스턴스가 메서드를 호출하는지 예상하기 어렵다.

우리의 코드에서는 BankManager 가 bank 이외의 프로퍼티를 갖지 않아서 mutating func 가 없다.
그래서 구조체 delegate 이 문제가 없었지만, 추후 다른 개발자가 프로퍼티를 추가하게 되면, 구조체 delegate 이 위험한 설계로 변할 수 있다.

✅ 결론 delegate 를 클래스 타입으로 변경한다.

Race Condition 유발 실험 및 Thread-Safe한 모델 메서드 구현하기

Race Condition 유발 실험

💡 조건 -> 고객 10,000명 + 은행원 100명(50명 + 50명) + 업무에 걸리는 시간 0.0초로 세팅


1️⃣ 기존 코드에서 실험을 진행하니까, 얼마 못 가서 Race Condition 발생하며 에러나는 것 확인

image

2️⃣ dequeue 메서드 전후로 semaphore1을 wait(), signal() 걸어놓고 실험

마찬가지로 얼마 못 가서 Race Condition 발생하며 에러나는 것 확인

image

3️⃣ 커스텀 SerialQueue 만들고 sync로 removeFirst 메서드 내부에 삽입 실험

커스텀 SerialQueue 의 sync 클로저 안에 Node 로 접근하는 모든 코드를 넣었음
실험을 약 50회 정도 진행했으나, Race Condition 발생하지 않음을 확인! 😄

✅ 이런 식으로 기초가 되는 메서드 자체를 Thread-Safe하게 만듦으로써
불필요한 semaphore 생성을 줄이고, 상위 메서드에서 코드 로직도 심플하게 리팩토링하게 됨

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.