Overview
- Types are used to specify what kind of data are you using.
- The type of a function dictates what kind of operations and operations can be done on a data. For example, let's suppose you have
Datetype data:"1993-10-03". Then you would like toaddDays()orgetYear()on the data. Without specifying the type of data, you are more liable to make mistakes further down the code. For example, you might accidentally try togetHours()which would be wrong. - Types might seem like putting in slightly extra effort initially, but it comes with huge benefits of writing correct and expressive code.
- There are fundamentally two kinds of types
- Predefined types - These types come in-built with our language. These are detailed in the section below.
- User-defined types - Sometimes, you might want to define your own data types based on your requirements. This can be achieved via user-defined types. More information about them can be found in User-defined types
- General syntax to for data types:
def DataType variableName;
Tip
Using def is optional.