Skip to content

Magic Numbers Should Be Named Constants #9

@LinuxMainframe

Description

@LinuxMainframe

Medium: Magic Numbers Should Be Named Constants

Priority: MEDIUM

Type: Code Quality

Locations

Multiple locations throughout libwsv5.c

Examples

Event thread timeout:

lws_service(conn->lws_context, 50);  // What is 50?

Request timeout:

if (now - (*req)->timestamp > 30) {  // What is 30?

Sleep durations:

struct timespec ts = {0, 50000000};  // 50ms - hard to read

Connection wait loops:

for (int i = 0; i < 50 && !obsws_is_connected(conn); i++) {
    usleep(100000);  // What is 100000?
}

Impact

  • Reduced code readability
  • Harder to maintain and tune performance
  • Values might be used inconsistently
  • Intent is unclear

Metadata

Metadata

Assignees

No one assigned

    Labels

    MEDIUMNot a risk, but definitely would improve functionalityenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions