知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

      • Theory:Functional decomposition
      • Theory:Paradigms
        • Imperative paradigm
          • Procedural programming paradigm
          • Object-oriented programming
          • Parallel processing approach
        • Declarative paradigm
          • Logic programming paradigm
          • Functional programming paradigm
          • Database programming paradigm
        • Conclusion
      • Theory:Overloading
      • Theory:Write, compile, and run
      • Theory:Annotations basics
      • Theory:JVM, JRE, and JDK
      • Theory:Jave Archive
      • Theory:Running programs on your computer
      • Theory:Enums in Java
      • Theory:Fields and methods in enum
      • Theory:StringBuilder
      • Theory:Immutability
      • Theory:Boxing and unboxing
      • Theory:Introduction to generic programming
      • Theory:Generics and Object
      • Theory:What are collections
      • Theory:The collections Framework overview
      • Theory:ArrayList
      • Theory:The List interface
      • Theory:Comparable
      • Theory:Processing strings
      • Theory:Initialization blocks
      • Theory:Introduction to API
      • Theory:Generic methods
    • 扩展

    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

    • Web

    • Spring boot

  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • 应知
Jim
2022-04-30
目录

Theory:Paradigms

Different programming tasks can be solved in different ways: you might need to write a function, or create a separate class with methods, and so on. All such variants are combined into different programming approaches, which are also called paradigms. Below we will analyze two main paradigms: imperative and declarative and their types.

Almost all modern languages are multi-paradigm. They easily combine the capabilities of the imperative and declarative approaches. Nevertheless, in the section about each paradigm, we will give a list of languages where, among other paradigms, the one discussed in the section is also implemented.

# Imperative paradigm

The imperative paradigm is one of the oldest programming paradigms. It is closely related to machine architecture. The imperative program is similar to the orders expressed by the imperative mood in natural languages. It is a sequence of instructions that the processor must execute step by step. The main focus of this paradigm is on how to achieve the goal. The paradigm consists of several statements, and after executing them all, the result is stored.

For example, you want to display the phrase "Hello, !" on the screen. How should the program do it? Through the following steps:

  • ask the username
  • read and remember the username
  • display the result

Imperative programming is divided into three broad categories: Procedural programming paradigm, Object-oriented programming, and Parallel processing approach. Let's talk about them in more detail.

# Procedural programming paradigm

The procedural programming paradigm is based upon the concept of procedure calls, in which statements are structured into procedures also known as subroutines or functions. They are a list of instructions to tell the computer what to do step by step. In other words, the computer takes input data and changes it sequentially, remembering each new change. There is no difference between procedural and imperative approaches.

Procedural Programming is suitable for general-purpose programming in order to complete common tasks. So, this can be a small computational problem, such as calculating a factorial, or finding the area of a figure, or displaying some information/phrase like "Hello, world!". Also, the code can be reused in different parts of the program, without the need to copy it.

The algorithm written in this paradigm is very simple to implement, but it is rather slow and cannot solve a complex problem.

Programming languages that have implemented the Procedural Programming paradigm are C, Java, C++, ColdFusion, Pascal.

# Object-oriented programming

Object-oriented programming or OOP is the paradigm where the program is written as a collection of classes. Each class has its instances called objects.

A class is a way of describing an entity in general, defining the usual state and behavior that depends on that state, as well as the usual rules for interacting with this entity. Formally, a class is viewed as a set of data like fields, attributes, class members, and functions, i.e. methods for working with them.

For example, we have an entity cat and we want to describe it using a class. So, the cat will be an object of the corresponding Cat class. A cat has some attributes, for example, a tail, paws, claws, muzzle, ears, whiskers. A cat's behavior is what it usually does, for example, it can run, jump, meow, eat, and rip off the wallpaper. All of these will be cat methods.

OOP can handle almost all kinds of common real-life problems where you need to model typical objects and work with them.

Programming languages that have implemented the OO paradigm are Ruby, Java, C++, Python, Simula (the first OOP language), Smalltalk, Visual Basic .NET, Objective-C.

# Parallel processing approach

Parallel processing helps reduce instruction execution time. It does this by sharing or parallelizing instructions across multiple processors. The meaning of the approach can be summarized in one phrase: "divide and conquer". Examples are NESL (one of the oldest) and C / C ++ (also supported due to some library functions).

# Declarative paradigm

Declarative programming is a programming paradigm in which it is important to specify the problem and the expected result of its solution. That is, in contrast to the imperative paradigm, where it is necessary to answer the question "how to do this?" you need to ask the questions "What needs to be done?" and "What will be the result of the work?". So, rather than providing step-by-step instruction, you tell the system what you need and let it try to come up with a solution.

Declarative programming is divided into Logic, Functional, and Database paradigm types. We will describe them below.

# Logic programming paradigm

Logic programming is a programming paradigm that is heavily based on formal logic. Any program written in a logical programming language is a set of sentences in a logical form that express facts and rules about a certain problem area.

So, the basic statements of logic programming are as follows:

  • Facts are fundamental assertions about the problem domain, like "Socrates is a man."
  • Rules are inferences about the facts in the domain ("All men are mortal.")
  • Queries are questions about that domain ("Is Socrates mortal?")

In general, the task here is to find the answer to the query based on facts and rules.

The major families of logic programming languages include Prolog, Answer Set Programming (ASP), and Datalog.

# Functional programming paradigm

Functional programming is a programming paradigm, in which the computation process is interpreted as the computation of the values of functions. The function, in this case, is similar to a mathematical one. That is, a function in which input is an array that is not changed, and the output is a new array with new data. This makes a mathematical function different from a function in procedural programming, where a function is a sequence of actions that change the original data.

Here's a simple example: you might have a function that takes a list of numbers as input and returns a new list with the squares of those numbers. This does not change the original list of numbers.

Programming languages that have implemented the Functional programming paradigm are JavaScript, Haskell, Scala, Erlang, Lisp, ML, Clojure, OCaml, Common Lisp, and F#.

# Database programming paradigm

This programming methodology is based on working with data. The data is stored in the database and queries are made to this database in a special language, for example, SQL. With these languages, you can access the data for filtering, transformations, calculating statistics, and so on. Program statements are data-defined rather than a hard-coded series of steps.

The database program is the heart of the business information system, allowing for file creation, data entry, updating, querying, and reporting functions.

# Conclusion

To sum up,

  • Different approaches to creating programs are called paradigms.
  • There are two main programming paradigms: imperative and declarative.
  • The imperative paradigm focuses on achieving a result using step-by-step instructions that change the data sequentially.
  • Imperative paradigm includes Procedural programming paradigm, Object-oriented programming, and Parallel processing approach.
  • The declarative paradigm focuses on the task and tries to get an expected result.
  • Declarative paradigm includes Logic, Functional, and Database paradigms.
编辑 (opens new window)
#Programming
上次更新: 2022/09/26, 16:55:15
Theory:Functional decomposition
Theory:Overloading

← Theory:Functional decomposition Theory:Overloading→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式