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

相关推荐
qetfw1 分钟前
Bash 基础:脚本执行、引号与命令替换验证
linux·开发语言·chrome·bash
杜 硕21 分钟前
从零开始的C++生活——第四讲
开发语言·c++·生活
云和数据.ChenGuang26 分钟前
Python 集合(set)常用函数详解与实战案例
开发语言·python·深度学习·langchain
梯度下降者36 分钟前
python在哪些方面有应用,python可以用在哪些方面
人工智能·python·web开发·科学计算·应用领域
隔窗听雨眠38 分钟前
从PHP2Shell回望:PHP内核漏洞的二十年演进与AI时代的攻防转折
开发语言·人工智能·php
lisw0542 分钟前
分岔论揭示演化突变密码
开发语言·算法·数学建模
hunteritself43 分钟前
AI 挖出 PHP「致命漏洞」!欧洲政府连夜关站,日本首相紧急喊话
开发语言·人工智能·php
烂蜻蜓1 小时前
Pandas入门教程(十二):读取 HTML 表格——read_html 参数详解与网页数据清洗
python·html·pandas
H.莓飛1 小时前
【数据结构】快速排序专题
linux·服务器·c语言·数据结构·visual studio
2601_967979121 小时前
Opteryx Python库 macOS版本0.0.0a12
python·macos·1024程序员节·wheel·opteryx·alpha