![]() ![]() In some lanaguages like C++, the compiler will expand the Generic code with the necessary type information. ![]() The compiler (or) runtime will do the rest. We provide some generic type information to the compiler. Generics prevents us from writing repetitive code for every single type that we need to implement. With Generics, we can write a piece of code that is shared across various types. Generics add one more level of abstraction. Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters. But it creates redundant code that is harder to maintain and debug. You can create two separate implementation for both Integer and String. Note: Primitive types are types like Int, Float, Character, etc., and Referenced types are those that are created by you.īut what if I need to implement List for both Integer and String? In a statically typed language, the compilers force you to have concrete types (either referenced or primitive) in (almost) every expression. Then we created statically typed languages. ![]() Types allow compilers to allocate the right memory and ensure there are no runtime surprises. With Types, it is easy to read, understand, and debug. We added types in abstraction to control how to allocate and de-allocate memory. These higher level languages (abstractions) make it easy for us to instruct the machines.ĭuring execution, machines should allocate and deallocate the memory. Instead of instructing machines with binaries (1 and 0s), we created higher level abstractions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |