DEV Community

Cover image for Code Smell 44 - Magic Corrections
Maxi Contieri
Maxi Contieri

Posted on • Edited on • Originally published at maximilianocontieri.com

2 1

Code Smell 44 - Magic Corrections

Compilers are smarter than us. On a Friday night production deploy they betray us.

Problems

  • Fail Fast

  • Declarativeness

  • Ambiguity

Solutions

  1. Fail Fast

  2. Do not trust magic coercion.

  3. Be Explicit

Examples

  • Type Casting

Sample Code

Wrong

<?
new Date(31, 02, 2020);
1 + 'Hello';
!3;
// Valid on most languages
view raw smarty.php hosted with ❤ by GitHub

Right

<?
new Date(31, 02, 2020);
// Throw an exception
1 + 'Hello';
// Type Mismatch
!3;
// Negating is a boolean operation
view raw failFast.php hosted with ❤ by GitHub

Detection

Many of this vicious are encouraged by languages themselves.

We should be very declarative and explicit and don't abuse language accidental magic solutions.

Tags

  • Declarative

  • Smart

Conclusion

Programmers pretend to be smart by exploiting language features.

They feel they belong to community standards that enforce bad behaviors like a sect.

Relations

More Info

Credits

Photo by Senor Sosa on Unsplash


Hackers are arrogant geek romantics. They lack the attentive spirit of inquiry.

Bruce Sterling

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay