当前位置:网站首页>What is a multi paradigm programming language and what does "multi paradigm" mean?
What is a multi paradigm programming language and what does "multi paradigm" mean?
2022-06-29 18:37:00 【Kingston】
Reprinted address :https://www.zhihu.com/question/20428688#:~:text=%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80%E4%B8%AD,%E8%8C%83%E5%BC%8F%E6%9D%A5%E6%92%B0%E5%86%99%E7%A8%8B%E5%BA%8F%E3%80%82
Programming paradigm refers to the guiding ideology of programming . In the programming language , It represents the design direction of this language , That is to say, language is to follow a certain , Or some kind of thought programming .
Multi paradigm in multi paradigm programming languages , It means that this language supports users to use many different programming paradigms to write programs .
C Language is a procedural programming language ;Java、C# Is an object-oriented programming language ;Haskell It's a functional programming language ; and C++ Is a multi paradigm programming language .
A few chestnuts :
Process type :[C/C++]
#define COUNT_OF(ARR) (sizeof(ARR) / sizeof(*(ARR)))
int square(int x)
{
return x * x;
}
int main(void)
{
int numbers[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int results[COUNT_OF(numbers)];
int i = 0;
for (; i < COUNT_OF(numbers); ++i)
{
results[i] = square(numbers[i]);
}
return 0;
}
object-oriented :[C#]
interface CalcI
{
int Square(int x);
}
class Calculate : CalcI
{
public int Square(int x)
{
return x * x;
}
}
class Iteration
{
public int[] ForEach(int[] arr, CalcI cc)
{
int[] results = new int[arr.Length];
for (int i = 0; i < arr.Length; ++i)
{
results[i] = cc.Square(arr[i]);
}
return results;
}
}
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[] {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] results;
Calculate cc = new Calculate();
Iteration it = new Iteration();
results = it.ForEach(numbers, cc);
}
}
Generic :[C++]
template <typename T>
auto square(T x)
{
return x * x;
}
template <typename T, std::size_t N, typename F>
auto array_map(const T(& arr)[N], F fr)
{
std::array<T, N> res;
for (size_t i = 0; i < N; ++i)
{
res[i] = fr(arr[i]);
}
return res;
}
int main(void)
{
int numbers[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto results = array_map(numbers, square<std::remove_extent_t<decltype(numbers)>>);
return 0;
}
Functional expression :[F#]
let square x = x * x
let numbers = [1 .. 10]
let squares = List.map square numbers
Template element :[C++]
template <size_t X>
struct square
{
enum : size_t {
value = X * X };
};
template <size_t... N>
struct array
{
enum : size_t {
count = sizeof...(N) };
};
template <typename Arr, template <size_t> class F>
struct array_map;
template <template <size_t...> class Arr, size_t... N, template <size_t> class F>
struct array_map<Arr<N...>, F>
{
using type = Arr<F<N>::value...>;
};
int main(void)
{
using numbers = array<1, 2, 3, 4, 5, 6, 7, 8, 9, 10>;
using results = array_map<numbers, square>::type;
return 0;
}
You can see ,C++ Very flexible , Not stuck to a particular programming methodology .
A programming language belongs to a certain type , It doesn't mean that the language can only be programmed with that kind of thought . such as C Language , Although it is a process , But we can still use struct Abstract out class The concept of , Use function pointers and algorithms to simulate polymorphic features in object-oriented , It's just a lot of trouble . However, multi - paradigm language can freely switch between these paradigms it supports , There will be no reluctant astringency . Of course , The cost is that multi paradigm languages are generally more complex .
边栏推荐
- WBF: new method of NMS post filter frame for detection task?
- 第02章_MySQL的数据目录
- Adobe Premiere Foundation - réglage du son (correction du volume, réduction du bruit, tonalité téléphonique, changement de hauteur, égaliseur de paramètres) (XVIII)
- Programmer Resource Recommendation Guide
- Request header field XXXX is not allowed by access control allow headers in preflight response
- 【TcaplusDB知识库】TcaplusDB运维单据介绍
- Know that Chuangyu has helped the energy industry in asset management and was selected into the 2021 IOT demonstration project of the Ministry of industry and information technology
- Adobe Premiere基礎-聲音調整(音量矯正,降噪,電話音,音高換擋器,參數均衡器)(十八)
- MySQL数据库每日备份并定时清理脚本
- Data-* attribute usage
猜你喜欢

Adobe Premiere foundation - time remapping (10)

Servlet学生管理系统(萌新练手版)

Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题

Anaconda安装并配置jupyter notebook远程

Adobe Premiere foundation - opacity (matte) (11)

报错Failed to allocate graph: MYRIAD device is not opened.
![Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket

对强缓存和协商缓存的理解

Proxmox VE Install 7.2

Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
随机推荐
[how the network is connected] Chapter 3 explores hubs, switches and routers
熊猫跑酷js小游戏代码
Adobe Premiere基础-常用的视频特效(边角定位,马赛克,模糊,锐化,手写工具,效果控件层级顺序)(十六)
【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
对强缓存和协商缓存的理解
JDBC knowledge
shell教程之循环语句for,while,until用法
jdbc认识上手
Application and practice of DDD in domestic hotel transaction -- Theory
Shell基本语法--流程控制
什么是多范式编程语言,其中的“多范式”是什么意思?
数据仓库模型分层ODS、DWD、DWM实战
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket
Adobe Premiere foundation - opacity (matte) (11)
Configure the local domain name through the hosts file
Adobe Premiere foundation - time remapping (10)
Request header field XXXX is not allowed by access control allow headers in preflight response
Cannot retrieve repository metadata processing records
3H proficient in opencv (V) - perspective transformation
Interview question 10.10 Rank of digital stream