Knowledgebase

Variables, Types and Data Structures Print

  • programminglanguages, programming, performance, troubleshooting, guide, howto, solution, zillionkinghost
  • 0

The building blocks.

WHAT A VARIABLE IS

A named reference to a value.

WHAT DIFFERS BETWEEN LANGUAGES

Whether the type is declared Whether the reference can be reassigned Whether the value can be changed

WHAT THAT LAST DISTINCTION MEANS

A constant reference may still point at something changeable.

WHAT PRIMITIVE TYPES USUALLY EXIST

Integers, of various sizes Floating point numbers Boolean values Characters and text A representation of absence

WHAT COLLECTIONS USUALLY EXIST

Ordered sequences Key and value mappings Sets, holding unique values Fixed-size groupings

WHAT TO CHOOSE BY

What operations you perform most.

WHY

Looking up by key in a sequence requires examining every item; in a mapping it does not.

WHAT THAT MEANS

The wrong structure turns fast code into slow code, at scale.

WHAT TO BE CAREFUL WITH

Integer overflow, in languages that permit it Floating point for money, in every language Comparing floating point values for equality

WHAT TO UNDERSTAND FOR YOUR LANGUAGE

Which types are copied and which are referenced.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot