当前位置:网站首页>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 .
边栏推荐
- Interview question 10.10 Rank of digital stream
- C Primer Plus 第12章_存储类别、链接和内存管理_代码和练习题
- Adobe Premiere基础-常用的视频特效(边角定位,马赛克,模糊,锐化,手写工具,效果控件层级顺序)(十六)
- Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题
- [tcapulusdb knowledge base] tcapulusdb system user group introduction
- /usr/bin/ld: warning: **libmysqlclient. so. 20**, needed by //usr/
- Shell基本语法--流程控制
- When easycvr deploys a server cluster, what is the reason why one is online and the other is offline?
- Markdown common fonts
- jdbc认识上手
猜你喜欢
随机推荐
Goldfish rhca memoirs: do447 building advanced job workflow -- using fact cache to improve performance
【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
AMAZING PANDAVERSE:META”无国界,来2.0新征程激活时髦属性
如何在树莓派上使用OAK相机?
Request header field XXXX is not allowed by access control allow headers in preflight response
C Primer Plus 第12章_存储类别、链接和内存管理_代码和练习题
Apache Doris 基本使用总结
How to use an oak camera as a webcam?
Adobe Premiere foundation - cool text flash (14)
VMware installation esxi
美法官裁定,被控掩盖黑客行为的Uber前安全主管必须面对欺诈指控
Apache InLong百万亿级数据流处理
SD6.23集训总结
Adobe Premiere基礎-聲音調整(音量矯正,降噪,電話音,音高換擋器,參數均衡器)(十八)
Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
Chapter 02_ MySQL data directory
源码安装MAVROS
Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)
《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26
Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)







