If Week 4 was about understanding why clean code matters, Week 5 was about practicing the how. I noticed a pattern: the more I leaned on best practices, the less time I spent fighting my own code. This week wasn’t about big refactors, but about sharpening the small details that make code reliable, idiomatic, and easier to maintain.

Fixing a Hidden Bug

This week I ran into a null pointer exception when trying to access a performance’s event during a QR scan. After digging in, here’s what I found:

  • Problem: selectPerformance returned only raw data without attaching its related event and player.
  • Impact: Accessing the event and player caused a crash.
  • Solution:
    • Updated the method so it fetches the related event and player.
    • Attached them back into the performance before returning it.

Takeaway: Small, precise fixes can make the system much more reliable without needing big refactors.

Caching Strategies That Work

Another highlight was caching. When I cached the secret key in AssetRepo, I learned that optimization isn’t about being clever but it’s about being practical.

  • What worked: simple static caching in the repository, one database call per app session, no performance impact on scans.
  • What I avoided: premature optimization, complicated cache invalidation, and over-engineering.

Takeaway: The key insight was that caching should simplify the system, not make it harder to maintain.

Trusting Libraries Over Reinventing

I caught myself manually parsing UUID strings or dates again, old habits die hard. But now, I make a conscious pause: Does the library already solve this? Nine times out of ten, the answer was yes.

  • uuid.parse() instead of rolling my own validation
  • Built-in JWT claims (jwt.jwtId, jwt.issuer) instead of digging through raw payloads
  • Using repository methods instead of re-searching lists manually

Takeaway: This shift didn’t just cut code, it cut risk.

Saying No to Over-Engineering

Last week, I still had the urge to add extra wrappers or clever abstractions. This week, I practiced restraint. I deleted unnecessary layers and focused on keeping code straightforward. Sometimes, the cleanest solution is the code you don’t write.

Reflections & Insights

  • A small bug reminded me that half-complete data is broken data and reliability means returning objects that are truly ready to use.
  • Fixes don’t need to be big; sometimes under ten lines can remove hours of future headaches.
  • Caching taught me that optimization works best when it’s simple and deliberate, not over-engineered.
  • The more I lean on types, asserts, and libraries, the less room there is for silent errors.

What’s Coming Up

  • Fix a few errors and improve the current code to return more reliable, fully populated data.
  • Write tests for the QR functionality, including mocking both QR scans and database calls.
  • Focus on making the codebase not just work, but also prove it works through tests.

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.