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的时候没有意识到会有这种问题。这是后来追加的一个补丁。限于修复水平,补丁没有打到最开始出现问题的地方,而是放到了最后。

相关推荐
sduwcgg5 分钟前
kaggle配置
人工智能·python·机器学习
沐知全栈开发12 分钟前
MongoDB 创建数据库
开发语言
__lost27 分钟前
Python图像变清晰与锐化,调整对比度,高斯滤波除躁,卷积锐化,中值滤波钝化,神经网络变清晰
python·opencv·计算机视觉
ErizJ31 分钟前
Golang | 迭代器模式
开发语言·golang·迭代器模式
海绵波波10732 分钟前
玉米产量遥感估产系统的开发实践(持续迭代与更新)
python·flask
牙痛不能吃糖,哭34 分钟前
C++面试复习日记(8)2025.4.25,malloc,free和new,delete的区别
开发语言·c++
健康的猪37 分钟前
golang的cgo的一点小心得
开发语言·后端·golang
祁同伟.1 小时前
【数据结构 · 初阶】- 堆的实现
c语言·数据结构
夜夜敲码1 小时前
C语言教程(十六): C 语言字符串详解
c语言·开发语言
宋康1 小时前
C语言结构体和union内存对齐
c语言·开发语言