분류 전체보기
-
switch-case 문에서 case가 많을 때, 간단하게 줄이는 방법간단기법 2021. 5. 9. 19:43
switch-case 문을 쓰다 보면, case가 선형적으로 계속 늘어나는 경우가 발생한다. 패킷을 처리할 때, 주로 발생한다. 패킷의 종류가 늘어나면, 늘어나는 만큼 case가 증가한다. case가 늘어날 때마다 선형적으로 계속 코드가 증가하는 것을 해결할 수 있을까 우선 생각나는 방법은 case에 대응하는 함수를 만들어서 처리하는 것이다. case가 증가할 때, case를 처리하는 함수들을 만들면 switch-case 문의 코드는 줄어든다. case 0: break; 같은 문장은 여전히 존재한다. 함수로 만들었으므로, 함수 호출에 대한 비용이 추가로 발생한다. 코드의 양은 생각보다 줄지 않았지만, 추가 비용이 발생한 것이다. 비용을 감내하고 더 코드를 줄일 수 있는 방식이 있다. 함수들의 시그내쳐(인..
-
IOT는 어렵다짧은경험기 2021. 4. 19. 16:09
IOT 제품은 두 가지 요소로 나눌 수 있다. 하드웨어, PCB와 MCU 그리고 WiFi를 위한 모듈, 모듈에 의하여 동작하는 기계장치 소프트웨어, MCU를 위한 펌웨어와 서버 회로를 설계하는 엔지니어는 소프트웨어를 잘하기 어렵고 펌웨어를 잘하는 개발자는 하드웨어를 잘하기 어렵다. 한 분야를 잘하기에도 많은 시간과 노력, 재능이 필요하기 때문이다. 더구나, 펌웨어를 잘하는 개발자가 서버 개발까지 잘하기 어렵다. 펌웨어를 잘한다는 것은 기기를 위한 핀 맵, 데이터 시트 등을 보고 목적에 맞는 펌웨어 개발을 잘하는 것이지 소켓 프로그래밍을 이용한 서버 개발을 잘하는 것은 아니기 때문이다. IOT 제품을 개발하는 것에는 두 가지 어려움이 있다. 기존의 기기에 네트워크를 연결할 수 있는 보드를 준비하는 것. 최..