• 0 Posts
  • 40 Comments
Joined 3 years ago
cake
Cake day: June 19th, 2023

help-circle


  • 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.


















  • Most of the “undecidable” are only undecidable for a subset of the problem instances, while a vast number of instances can be even trivially decidable. For example in the undecidable halting problem, both you and a computer can trivially deduce that while(true) will not halt. In the same way a computer can deduce that many instances of two pieces of code are semantically equivalent.

    I’d like to see an instance of the problem where a human could decide it and the computer could not.