[–] 7 points 2 weeks ago

Humans are very good at pattern recognition. Cyclomatic complexity ignores that, so code that is easy for a human to read can get a bad score. E.g. handling Win API messages:

    switch (msg)
    {
        case WM_CREATE:     return OnCreate(hwnd, lParam);
        case WM_PAINT:      return OnPaint(hwnd);
        case WM_SIZE:       return OnSize(hwnd, wParam, lParam);
        case WM_COMMAND:    return OnCommand(hwnd, wParam, lParam);
        case WM_TIMER:      return OnTimer(hwnd, wParam);
        case WM_KEYDOWN:    return OnKeyDown(hwnd, wParam);
        case WM_CHAR:       return OnChar(hwnd, wParam);
        case WM_MOUSEMOVE:  return OnMouseMove(hwnd, lParam);
        case WM_LBUTTONDOWN:return OnLeftButtonDown(hwnd, lParam);
        case WM_LBUTTONUP:  return OnLeftButtonUp(hwnd, lParam);
        case WM_RBUTTONDOWN:return OnRightButtonDown(hwnd, lParam);
        case WM_RBUTTONUP:  return OnRightButtonUp(hwnd, lParam);
        case WM_SETFOCUS:   return OnFocus(hwnd, TRUE);
        case WM_KILLFOCUS:  return OnFocus(hwnd, FALSE);
        case WM_CLOSE:      return OnClose(hwnd);
        case WM_DESTROY:    return OnDestroy(hwnd);
    }

Complexity score: 17. Easy to read and verify? Yes.

LRESULT OnMouseMove(HWND hwnd, LPARAM pos)
{
    if (tracking == dragging != selecting &&
        (!cancelled == (buttons & MK_LBUTTON)))
        return UpdateInteraction(hwnd, pos);

    return 0;
}

Complexity score: 3. Easy to read and verify? No.

  • source
  • parent
  • context
  • [–] 2 points 1 month ago (2 children)

    If you think I have made an error, feel free to point it out. I prefer being corrected than being wrong.

    I've never understood why people are so reluctant to admit mistakes. Insecurity? I have no problem with it.

  • source
  • parent
  • context
  • [–] 1 point 1 month ago

    Call recording laws in some U.S. states require only one party to be aware of the recording, while other states generally require both parties to be aware. Several states require that all parties consent when one party wants to record a telephone conversation.

  • source
  • parent
  • context
  • view more: next ›