python和c

python这个语言现在用的非常流行了。拥护它的人高度赞美它,认为它高效率,功能强,现代化,限于自己的水平完全不知道它有什么问题。"因为无知而完美"。这样的语言,就给这样的人用。

我一直觉得python没什么。这不过是又一个二流的计算机语言。以前只是模糊的直觉。直到我需要检查一个编译器的问题。找出python来对比。我觉得不能忍受。

如果在函数定义过程中,函数的参数出现同名,这当然是错误。这在各种语言都不会接受的。看python怎么处理这个问题的:

def f(x,x,x,x,x,x,x,x,x,x,x,x):

... s = x+x+x+x+x+x+x+x+1;

... return def;

File "", line 3

return def;

^

SyntaxError: invalid syntax

def f(x,x,x,x,x,x,x,x,x,x,x,x):

... s = x+x+x+x+x+x+x+x+1;

... return s;

...

File "", line 1

SyntaxError: duplicate argument 'x' in function definition

当然,python程序员限于自己的水平,看不出这里有什么问题。但对比c语言,就会看出区别,下面摘取c语言编译同样的东西,给出的错误信息:

int f(int x, int x, int x, int x, int x, int x, int x, int x, int x)

{

int sum;

s= x+x+x+x+x+x+x+x+1;

return s;

}

$ cc q.c

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c:1: error: redefinition of parameter 'x'

q.c:1: error: previous definition of 'x' was here

q.c: In function f': q.c:4: error: s' undeclared (first use in this function)

q.c:4: error: (Each undeclared identifier is reported only once

q.c:4: error: for each function it appears in.)

区别在于c语言在编译函数头的时候,就已经指出了参数重复的问题。而python要等到函数编译完才发现这个问题。明显python的创造者设计python的时候没有意识到会有这种问题。这是后来追加的一个补丁。限于修复水平,补丁没有打到最开始出现问题的地方,而是放到了最后。

相关推荐
郜太素7 分钟前
深度学习中的正则化方法与卷积神经网络基础
人工智能·pytorch·python·深度学习·神经网络·机器学习·cnn
蹦蹦跳跳真可爱58918 分钟前
Python----目标检测(labelimg和labelme的安装与使用,Pycharm配置教程)
人工智能·python·目标检测·计算机视觉·pycharm
Vodka~20 分钟前
服务器多用户共享Conda环境操作指南——Ubuntu24.02
服务器·python·conda
炯哈哈26 分钟前
【上位机——WPF】命名空间
开发语言·windows·c#·wpf·上位机
Murphy_lx31 分钟前
django回忆录(Python的一些基本概念, pycharm和Anaconda的配置, 以及配合MySQL实现基础功能, 适合初学者了解)
后端·python·pycharm·django
Yan_ks1 小时前
JAVA面向对象——对象和类的基本语法
java·开发语言
小叶爱吃鱼1 小时前
python-数据可视化(大数据、数据分析、可视化图像、HTML页面)
大数据·python·信息可视化·数据分析
Paddy哥1 小时前
jsmpeg+java+ffmpeg 调用摄像头RTSP流播放
java·开发语言·ffmpeg
MonkeyKing_sunyuhua1 小时前
go.mod:5: unknown directive: toolchain
开发语言·chrome·golang