Data types are hints to a computer language, telling the language’s interpreter or compiler how best to allocate resources and optimize performance.
We will introduce the type system provided by the Perl compiler, and the many benefits of utilizing Perl data types.
The Perl interpreter itself is written in C, and implements data types for its own internal use, including:
– IV, integer value
– NV, number value
– PV, pointer value AKA string
– AV, array value
– HV, hash value
– SV, scalar value
– RV, reference value
The Perl interpreter does not provide programmers with access to these pre-defined types, and instead it encourages us not to use data types at all.
Perl does allow programmers to create user-defined data types, but none of the (numerous & incompatible) data type systems actually utilizes the underlying C data types implemented in the Perl interpreter.
The Perl compiler finally provides developers with direct access to real C data types and their C++ equivalents.
Upgrade your Perl, start utilizing data types today!
source
This post was automatic generated with this wp-automatic-plugin
Calling user-defined types "fake types" because they don't map to the underlying CPU architecture is like calling Perl a fake language because it's not assembler.
In reality, tools like Types::Standard and others create types that are more useful to humans, not computers, and thus help us to make our code more correct. Lower-level types, such a Int or Float, are great for performance, but require that the constraints required by the software be hand-coded and always watched by the programmer, thus increasing the chance for bugs. So we often trade correctness for performance. It's not that either is better or worse; they're *different*. We need to understand the tradeoffs and choose.