How programmers use logical reasoning#
Logical reasoning plays an important role in programming. Let’s discuss some of the ways that programmers use logic in their work.
Problem-solving#
Programmers use logical reasoning for problem-solving. Before you start coding a program, you’ll have to wrestle with questions about what the program is trying to accomplish, what features it will need to have, what programming language you’ll write it in, and so on. Inductive and deductive reasoning are useful tools for answering process questions like these.
Writing code#
Coding is the process of writing instructions in a language a computer can read. These instructions direct the computer to perform a set of operations. Writing functioning code requires applying logic. Imperative programming, for instance, is a paradigm based on issuing commands for a program to follow on a step-by-step basis. Writing these commands is a logical process. It requires thinking about the relationships between parts. Do the commands interact with each other to bring about the desired outcome? If not, the code isn’t going to work.
Writing functioning code is also dependent on understanding the logic of the programming language you’re using. For example, the logical operators and,
or,
and not
in Python are derived from Boolean logic, and they’re an important part of conditional statements and other logical expressions.
Creating algorithms#
Algorithms used in machine learning and artificial intelligence also rely on logic. An algorithm is a set of instructions that tells a program what to do on the basis of certain inputs. A simple decision tree algorithm, for instance, will consist of a series of branching decisions. The logic of each branch is fairly simple: “If a certain condition is met, do A. If not, do B.” These branching decisions are repeated through later stages of the program to specify the appropriate end result based on the inputs.