Overview on Primitive Data Types

I want to work my way up to classes, and I figured after talking functions it would be a good idea to step back. Primitive data types are the integers, boolean values (true, false), and so on that you typically associate with programming. There are plenty of lists on Google, so I will not get too deep into specifics. The only data type that you may think is primitive that is not is a string. For me, the easiest way to think of a string is as an array of characters. This works because floats and doubles are not merely arrays of ints, but entirely different sorts of numbers altogether. Understanding this stuff is important for designing good classes.

There are two things that programmers like to consider when they’re optimizing a program: memory and running time. Nowadays due to abundant memory running time is typically prioritized. That being said there can be significant problems for using the wrong datatype. You can run into issues such as overflows where a given value is greater or lower than the datatype supports. Old games for example sometimes limited values to only 255, and that’s because of the amount of memory they assigned to hold that value. For example, this is why the 256th level of Pacman is broken on old arcades.

However, there is another reason to also consider the correct data type. Doubles can consume twice the memory of ints for the exact same number. However, they have a different structure and it can affect output. The result could be wrong or far more precise than necessary. Another issue is that if you get user data and do not ensure the data fits the data type you could run into a whole host of issues. Understanding the limitations of your intended data type can help avoid those problems too. Therefore even though there is plenty of memory nowadays it makes sense to take an extra second and ensure everything is correct.

If you make a purchase at Amazon using the link below I may receive a commission.
Tech Best Sellers

Leave a comment

Your email address will not be published. Required fields are marked *