Identify and refactor overly complex code into simpler, more maintainable versions. Use when you encounter deeply nested conditions, long functions, or redundant logic.
When the user asks to simplify code, or when you encounter complex logic during development, follow this process:
else blocks and reduce nesting.def process_data(data):
if data:
if 'items' in data:
for item in data['items']:
if item.get('active'):
# Do something
pass
def process_data(data):
if not data or 'items' not in data:
return
for item in data['items']:
if not item.get('active'):
continue
# Do something