rspec/rules/S1905/description.adoc
Fred Tingaud d3cfe19d7e
Fix broken or dangerous backquotes
Co-authored-by: Marco Borgeaud <89914223+marco-antognini-sonarsource@users.noreply.github.com>
2023-10-30 10:33:56 +01:00

12 lines
851 B
Plaintext

Casting expressions are utilized to convert one data type to another, such as transforming an integer into a string. This is especially crucial in strongly typed languages like C, {cpp}, C#, Java, Python, and others.
However, there are instances where casting expressions are not needed. These include situations like:
- casting a variable to its own type
- casting a subclass to a parent class (in the case of polymorphism)
- the programming language is capable of automatically converting the given type to another
These scenarios are considered unnecessary casting expressions. They can complicate the code and make it more difficult to understand, without offering any advantages.
As a result, it's generally advised to avoid unnecessary casting expressions. Instead, rely on the language's type system to ensure type safety and code clarity.