Data Types
Data type is not a detail. Data type is meaning.
If you choose the wrong type, the software may still run. It just runs crooked.
This is where many classic bugs begin:
- price stored with the wrong precision
- age treated as text
- confusing status fields
- broken comparisons
- inconsistent validation
What a data type really is
Section titled “What a data type really is”A data type defines:
- which values make sense
- which operations are valid
- how the value is interpreted
- which kinds of errors are likely
Simple examples:
42may be an integer"42"is text42.0may be decimaltrueis a logical state
Looks simple. But many business rules break exactly because systems mix these ideas.
What you should master first
Section titled “What you should master first”Integer
Section titled “Integer”Use when there is no fractional part.
Examples:
- number of users
- retry count
- age
- rank position
Decimal
Section titled “Decimal”Use when fractions matter.
Examples:
- weight
- temperature
- distance
But careful: not every decimal choice is good for money.
String
Section titled “String”Use for textual information.
Examples:
- name
- masked document ID
- alphanumeric identifier
Boolean
Section titled “Boolean”Use for binary states.
Examples:
- active or inactive
- paid or unpaid
- valid or invalid
Null / absence of value
Section titled “Null / absence of value”You also need to understand when the system is saying:
- “I do not know yet”
- “it was not informed”
- “it does not exist”
Many beginners treat absence as empty string, zero, or false. That is where the mess starts.
Classic mistake: “it looks like a number, so it is a number”
Section titled “Classic mistake: “it looks like a number, so it is a number””This matters a lot:
"10"is not10"true"is nottrue"3.14"is not3.14
When data comes from forms, APIs, or storage, validation and conversion are almost always required.
Practical rule:
validate first, convert second
Money deserves special care
Section titled “Money deserves special care”If you store prices as a generic floating-point value and just keep calculating, precision issues will eventually bite you.
In real systems, common approaches are:
- a proper decimal type
- integer cents
Mental model:
$10.99can be stored as1099cents
That alone avoids many financial bugs.
Date and time are traps too
Section titled “Date and time are traps too”Date is not “just a nice string.”
If you save everything as loose text, later you suffer when trying to:
- sort
- filter
- compare
- deal with timezone
Use a proper date/time type whenever possible. If serialization is needed, choose a consistent format.
ID is not necessarily a number
Section titled “ID is not necessarily a number”This is an important mindset shift:
- phone number is not a mathematical number
- ZIP code is not a mathematical number
- document identifier is not a mathematical number
- order code may look numeric, but still be an identifier
If you are not going to calculate with it, it may not belong in a numeric type.
How to choose the right type
Section titled “How to choose the right type”Before creating a variable, field, or database column, ask:
- Is this quantity, state, text, date, or identity?
- Will I calculate with it or only store and display it?
- Can it be absent?
- Does precision matter?
- Does exact comparison matter?
Those questions already improve most type choices.
Practical modeling examples
Section titled “Practical modeling examples”name: stringage: integeremail: stringactive: boolean
orderId: string or integer, depending on domain rulestotalAmount: proper decimal or centspaid: booleancreatedAt: date/time
Product
Section titled “Product”sku: stringstock: integerprice: proper decimal
Common beginner mistakes
Section titled “Common beginner mistakes”- using strings for everything
- comparing number and text
- converting without validation
- using
0to mean “not informed” - using
falseto hide missing data - ignoring precision in money calculations
Signs your modeling is weak
Section titled “Signs your modeling is weak”- you keep converting the same field again and again
- business rules are full of weird conditionals
- the same value changes format in different layers
- bugs keep showing up in forms, filters, and ordering
High-value exercises
Section titled “High-value exercises”- Model a user registration with name, age, email, and active state.
- Model an order with amount, date, and payment status.
- Receive data as text and convert it safely.
- Reject invalid input without crashing the flow.
Quick checklist
Section titled “Quick checklist”- Do you know when to use integer vs decimal?
- Do you understand that IDs are not always numbers?
- Do you treat absence of value carefully?
- Do you know money needs serious modeling?
- Do you validate before conversion?
If yes, your base is already much stronger than the average beginner’s.
Next actions
Section titled “Next actions”- Continue to Data Structures
- Then consolidate with Programming Logic