Most modern languages have some built in complex data types that you can use.
Characters and Strings
For example most languages have the ability to work with strings and characters. In most languages a character is a single byte or two bytes in size, and can represent a letter, number, or special character like a comma, period, percent sign, etc. or even a non-printable characters like a tab, carriage return.
C-Style strings, in the C programming language, are a collection of characters in an array, with a terminating character (null). So they may store five characters in a row, for example ‘h’-‘e’-‘l’-‘l’-‘o’, or “hello”, if you prefer. However, there is no built in methods to allow you to compare that string with another, or convert it to all upper case.
Complex Strings
However, given the drop in the price of both memory and processing power, most languages give you strings as a built-in class for a string.This allows methods for working with strings, simplifying the programmers job.
Just like you can add and subtract a number, you can add to a string, remove characters from it, etc. What you can specifically do, and how you do it, is up to the language you are using.
There are some languages which were designed specifically to work with strings (SNOBOL). They had lots of built-in functions to make using strings easier.
Other languages (looking at you C) were notoriously difficult to work with strings. However, luckily for us, other people often built libraries to make working with strings easier.
Dates
A date is often a very unique type of data. That’s because it’s difficult to determine something that at first glance seems so simple, however, brings about a lot of questions as to how to handle it.
For example, is a date, just the date, or does it store the time as well? Should there be a time data type instead? Should there be both?
By default, a lot of languages and operating systems, use a counter from a specific date/time. And while that gives a way to measure time, it doesn’t answer a lot of other questions.
In most situations, accuracy to the second and millisecond is more than accurate enough. However, there are times that nigher accuracy is needed. We can’t assume that a generic date/time will or won’t work.
But you still have other things to consider. For example, how do you display a date – mm-dd-yy, mm-dd-yyyy, dd-mm-yyyy, yyyy-mm-dd? Each is valid, and used in different situations. In some cases, I don’t need to know the day, only a month and year. And what if I only need a year? Can I use a date variable, or do I need to store it some other way?
If you want to get more complicated, how do you track your date? While one would assume a set of integers, you might be surprised that it’s actually storing the number of milliseconds from a given time. This allows time to be stored, but it is limited in that it is only as accurate as a millisecond, and there can be issues with running out of bits to store dates in the far future, or far past.
You can see how dates can quickly spiral out of control for how to store, use, and work with them. Most languages provide tools to help you work on formatting, modifying, and displaying a date.
PHP offers one of the most robust, if not absolutely convoluted ways to display dates. Visit https://www.php.net/manual/en/function.date.php to see how flexible PHP is in letting you display a date, and how difficult it can be to do something simple like display a date.
If you want to get complicated, try to figure out how to determine the duration of time. Should it be done via a date object? Most systems don’t allow you to subtract one date from another to get another date. Or are you going to need a custom data type if it isn’t provided in the language?
Arrays/Lists
Arrays are another example of something that used to be simple, a memory pointer, which is not a complex data type. Now they are often semi-complex with counts as to how many elements are in the array, a way to sort the array, etc.
We’ll look at arrays as a data type in the future.
More Complex Native Types was originally found on Access 2 Learn