Complex data types are usually classes. Some might be supplied by the language, while others are user defined.
Complex data types have methods built in for working with the data, libraries that come with the language (potentially) and will vary from language to language on how they are stored and handled.
The types of data will also vary – strings and dates are common. There are lots of custom methods that may or may not be shared between languages for something so simple and straight forward. For example, checking for equality, modifying a given value, etc.
String
While some languages have a basic string, such as the old fashioned C Style String in C, most languages use a class to help us represent a String. In that class they will provide methods, built in for us, that will allow us to do things like convert it to all upper case, or all lower case. They will allow us to compare two strings.
Now languages will vary in their implementation. For example, one might use the method upper()
to convert a string to all upper case, while another might use the method ucase()
, and a third might choose toUpper()
. So while most will allow you to convert a string to all upper case, the exact syntax may vary.
Additionally, some will have methods that others will not. For example, you might have an equals()
to see if another string is equal to another, but only some have equalsIgnoreCase()
style of method to allow you to choose between if the case of the strings should matter or not. In some cases, like the old Visual Basic, the string case never mattered for comparison.
Date
Dates are also an interesting data structure, so each language provides slightly different ways of handing them. Whether it is as a library of functions, or a Date class. Usually you will need to import something to use a date.
Dates are often stored as a long, and it measures the number of milliseconds or seconds from a given point in time. This is good if you need to know the time, but limits how far into the future you can see as you’re limited to the maximum value of the data structure that is storing that distance. This means it also doesn’t work well for historical references when you need to go back more than a years, or future references. You can read about that at the Year 2038 bug, and how it’s been “fixed”.
Because of the varying ways to store the value, dates tend to vary quite a bit in implementation, and date mathematics is a bit of a rarity.
Other Built In Complex Classes
However, you can also find Sets, Dynamic Lists, Dictionary Objects and more depending upon the language. Specialized languages may have special data types not typical to general purpose languages.
User Defined
Of course, if you do not have a data type provided for you, most modern general purpose languages allow you to build your own data type.
Some, like C, provide the struct command, to build a container for data, but no methods. There are other languages that also allow you to use data structures, but most people don’t except for very simple data types that will only hold data, and not with it.
Most languages allow you to define a class, so you can not only store data, but also methods for interacting with that data.
Object Oriented Programming is about more than just storing custom data types. It is a whole methodology about storing data in a manner that is protected from other similar collections of data. It does this by providing a set of functions, called methods in object oriented parlance, that allow, and restrict access to the data contained within.
You can think of a class as a recipe on how to make this custom data type. It can be used to build an object later. As a recipe, the class doesn’t do anything, but it does define what it will look like when it is created. When a class is created, an object is made. An object is an instance of the class, and is used in the actual program.
Complex Data Types That Come with Your Language was originally found on Access 2 Learn