Code Room
Code reviewMedium
Question
Review this Python function that truncates a user comment to fit a 100-byte DB column and streams it.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
def truncate_comment(text: str, max_bytes: int = 100) -> bytes: encoded = text.encode("utf-8") if len(encoded) <= max_bytes: return encoded return encoded[:max_bytes]Run or narrate your approach, then ask the coach.