Programming Languages

The programming ideas engineers use most: choosing a language, Python and C essentials, numbers and floating point, bits and data formats, numerical methods, filters and PID, data and files, and software practice.

Engineers write code to read instruments, control machines, process data, run calculations and glue tools together. You do not need to be a software specialist, but a handful of ideas (how numbers are stored, how to work with bits, how to write small testable functions, how to check a numerical answer) prevent most of the expensive mistakes. This guide gathers those ideas in nine pages with short, tested examples in Python and C: choosing a language, the essentials of Python and of C, numbers and floating-point, bits and data formats, numerical methods, filters and control code, data and files, and software practice. The examples are small enough to read in a minute and every worked number is computed, so you can check your own code against them.

Start here: what do you need?

I need to…Go to
pick a language for a project or a platformChoosing a Language
analyze data, plot it, or talk to an instrumentPython for Engineers
write firmware or fast code, or read C written by othersC and C++ Essentials
understand why 0.1 + 0.2 is not 0.3, or why a total driftsNumbers and Floating Point
work with hex, masks, byte order or a binary file formatBits, Bytes and Data Formats
solve an equation, integrate a log, fit a curve or simulate a systemNumerical Methods
smooth a noisy reading, write a PID loop or find a frequencyFilters, PID and Signal Code
read CSV, JSON or serial messages, or handle time stamps and unitsData, Files and Parsing
organize a project, test it, find a bug or make it fasterSoftware Practice, Testing and Debugging

A suggested order

If you are new to programming, start with Choosing a Language and the page for your first language, then read Numbers and Floating Point and Bits, Bytes and Data Formats: they explain most “impossible” results. The remaining pages are tools you reach for as the job needs them.

  1. Choosing a Language: Python, C, C++, MATLAB, Rust, JavaScript, SQL, shell and PLC languages compared, with how to pick one and set up the tools.
  2. Python for Engineers: The Python an engineer needs: data types, functions, NumPy and Matplotlib, instruments over serial, units, speed and virtual environments.
  3. C and C++ Essentials: Types and sizes, pointers and arrays, structures, the preprocessor, bit operations, undefined behavior and safe habits.
  4. Numbers and Floating Point: Integers and overflow, IEEE 754 floats, rounding error, cancellation, summing, comparing, units and significant figures.
  5. Bits, Bytes and Data Formats: Binary and hex, bit masks, two’s complement, byte order, packing fields, text encodings and reading binary data.
  6. Numerical Methods: Solving equations, integrating, differential equations, interpolation and curve fitting, with the error of each method.
  7. Filters, PID and Signal Code: Moving average and exponential filters, discrete PID with anti-windup, sampling, the Fourier transform and tuning by simulation.
  8. Data, Files and Parsing: CSV, JSON and binary files, parsing serial messages, time stamps, units, pandas, SQL and keeping raw data.
  9. Software Practice, Testing and Debugging: Version control, tests, reading and writing code others can use, how work grows with data, profiling, common bugs and a review checklist.

Why engineers write code

The traps that cause most problems

TrapWhat happensWhere it is explained
Float equality0.1 + 0.2 == 0.3 is falseNumbers and Floating Point
Integer overflow and divisionA counter wraps; 7 / 2 is 3Numbers and Floating Point and C and C++ Essentials
Byte orderA sensor reading looks plausible but is wrongBits, Bytes and Data Formats
UnitsA result is out by a constant factorNumbers and Floating Point and Data, Files and Parsing
Unequal time stepsA filter or PID behaves differently from the planFilters, PID and Signal Code
Off-by-oneA loop runs one time too manySoftware Practice, Testing and Debugging
Tests skippedA change breaks something nobody noticesSoftware Practice, Testing and Debugging

Quick reference

TopicRule or formulaPage
Float precisionfloat ≈ 7 digits (ε = 1.19 × 10−7); double ≈ 16 digits (ε = 2.22 × 10−16)Numbers and Floating Point
Integer rangesn bits unsigned 0 to 2n − 1; signed −2n−1 to 2n−1 − 1Bits, Bytes and Data Formats
Set / clear / toggle a bitr |= 1<<n; r &= ~(1<<n); r ^= 1<<nBits, Bytes and Data Formats
Newton stepx ← x − f(x) ÷ f′(x)Numerical Methods
Trapezoid ruleh [ ½ f0 + f1 + … + ½ fn ]Numerical Methods
Exponential filtery += α (x − y), α = Δt ÷ (τ + Δt)Filters, PID and Signal Code
Discrete PIDu = Kp e + Ki ∫e dt + Kd de/dtFilters, PID and Signal Code
Nyquistsample at more than twice the highest frequencyFilters, PID and Signal Code

Related guides and tools

Safety

  • Code that moves things can hurt. A program that controls a motor, heater or valve needs hardware limits and an independent stop that does not depend on the software, and tests before it meets the real machine.
  • Never trust input, from a sensor, a file or a network: check ranges and handle missing or garbled data.
  • Safety-related control code (machine guarding, medical, vehicles) follows standards and needs certified tools and review; a script is not a safety system (see System Integration).
  • Secrets and credentials do not belong in source code that you share.

FAQ

Which language should I learn first?

Python for analysis, automation and quick tools; C if your goal is microcontrollers and firmware. The ideas (variables, loops, functions, numbers, bits) are the same, so the second language is much easier than the first. See Choosing a Language.

Do I need to know object-oriented programming?

Not to start. Functions and a few data structures carry most engineering scripts. Classes help in larger programs and are standard in libraries you will use.

Why does my calculation give a slightly wrong answer?

Almost always because floating-point numbers are approximations, or because of a unit, a rounding or an integer-division mistake. Numbers and Floating Point explains how to tell which.

Where did the old Programming Languages sections go?

All of them are in this guide, with much more depth: numbers, bits, numerical methods, filters and the workflow each have their own page.

References

  • Kernighan, B. W. and Ritchie, D. M., The C Programming Language; Matthes, E., Python Crash Course; the Python and NumPy documentation.
  • IEEE 754-2019, Standard for Floating-Point Arithmetic; Goldberg, D., “What every computer scientist should know about floating-point arithmetic”, 1991.
  • Press, W. H. et al., Numerical Recipes; Burden, R. L. and Faires, J. D., Numerical Analysis.
  • Hunt, A. and Thomas, D., The Pragmatic Programmer.

Last reviewed: October 2026. Library versions and tool names change: check the current documentation for the language you use.