Program? Definition
Programming = telling a computer exactly what to do A sequence of instructions written in a
Computers only do what they are explicitly instructed programming language:
Problem solving: make computers do useful tasks Syntax: rules for writing instructions
Creativity: multiple solutions → choose the best one Semantics: meaning of instructions
Modeling: represent real systems in simplified form
Abstraction: focus on important features, ignore details Programs are models of systems:
Concrete execution: give precise step-by-step instructions Model = simpli ed representation
System = components working together
Good program Functional: does what it’s supposed to do
Robust: reliable, few bugs
Flexible: easy to adapt or extend
Efficient: good performance
Maintainable: easy to update and fix
User-friendly: easy to learn and use
User-centered: good design and experience
Programming paradigms
Imperative / Task-oriented Object-oriented Functional / declarative
Break problems into steps Break problem into objects Uses expressions and functions.
Focus on how to do things Objects interact with each other Focus on what should be done
Data + behavior
Task-oriented Object-oriented
sprochdure
berhavor (hinse
, >
-
Example: Focus on actions taslss Focus on things( nouns)
Written us "sequene of steps" Built from "objects that interact"
Playing poker game → Poker: shuf e cards, distrbute → poker: one card, deck of cards,
cards, play the game players
Object-oriented programming (OOP)
Write programs by modeling problems as a set of collaborating objects.
Objects: Represent real-world entities
Have properies (data) and capabilities (methods)
Key benefits:
Example: Objects: piece, board Abstractions
Capabilities: Encapsulation (black box)
Tetris Better control of complexity
Piece: create, fall, rotate, stop on collision
Properties:
Piece: shape, position, orientation, color
Board: size, rows
fl fi