Programming Fundamentals
What is Programming?
Programming is writing computer code to create a program to solve a problem. Programs are created to implement algorithms. Algorithms can be represented as pseudocode or a flow chart, and programming is the translation of these into a computer program.
To tell a computer to do something, a program must be written to tell it exactly what to do and how to do it. If an algorithm has been designed, the computer program will follow this algorithm, step-by-step, which will tell the computer exactly what it should do.
Variables and Data Types
Variables are used to store data that can be used and manipulated throughout a program. Each variable has a specific data type that defines the kind of data it can hold. Common data types include:
Integer: Whole numbers (e.g., -1, 0, 1, 2).
Float: Decimal numbers (e.g., 3.14, -0.001).
String: A sequence of characters (e.g., “Hello, World!”).
Boolean: Represents true or false values.
Naming Conventions
Consistent naming conventions improve code readability and maintainability. Here are some common practices:
Variables: Use meaningful names (e.g., totalCount instead of x).
Constants: Use uppercase letters with underscores (e.g., MAX_SIZE).
Functions: Use verbs and camelCase (e.g., calculateTotal()).
Classes: Use nouns and PascalCase (e.g., ShoppingCart).
Types of Programming Languages
Programming languages can be grouped into several paradigms, each emphasizing different ways of structuring logic and solving problems.
- Imperative Programming
Focuses on describing how a program operates.
Uses statements to change a program’s state.
Examples: C, C++, Java , Python, Ruby, etc.
- Declarative Programming
Focuses on what the program should accomplish without specifying how.
Examples: SQL, HTML, CSS, etc.
- Functional Programming
Treats computation as the evaluation of mathematical functions.
Avoids changing-state and mutable data.
Examples: Haskell, Lisp, Scala, SML, F#, etc.
- Object-Oriented Programming (OOP)
Organizes code into “objects” that contain data and methods.
Promotes code reusability and modularity.
Examples: Python, Ruby, Java, C++, C#, Visual Basic .NET, etc.
- Procedural Programming
Based on the concept of procedure calls.
Structures the program as a sequence of procedures or routines.
Examples: Pascal, C, Fortran, C#, etc.
- Scripting Programming Languages
Designed for automating tasks and manipulating data.
Often interpreted rather than compiled.
Examples: JavaScript, PHP, Perl, Ruby, etc.
- Logic Programming Languages
Based on formal logic.
Programs consist of a set of sentences in logical form, expressing facts and rules about some problem domain.
Examples: PROLOG, Datalog, Absys, ALF, etc.