标签 英语 下的文章

那些代码中的“中国式”命名

10月中旬,有人在Quora网站上发起一个调查:“程序员职业生涯中最难的事是什么?”,调查结果让人实感意外。世界范围内的程序员同胞们普遍认为: “命名是让大家感觉最困难的事情”。对于主流的欧美程序员尚且如此,对于英文非母语的中国程序员来说,苦逼程度可想而知了:(。

虽说中国程序员大多也都学了10年以上的英语了,但能“地道”的表达和书写甚至是选词的程序员们比例却不高。而在编写程序的过程中,给变量、常量以及函数命名即意味着我们要选择恰当地道的词汇或缩写。

事实证明,任何事情经过中国人民的加工,就会呈现出意想不到的效果,于是我们有了Chinglish,有了“中国式”的命名。就此,我特地花了些时间翻阅了下面几个项目组的源码,总结出了一些“中国式”命名的门道,这里也说道说道^_^。

一、万能的动词

通过阅读代码中的一些命名,我发现了代码中经常出现的一些动词堪称“万能”,这些动词包括:handle、do、process、check、collect等。无论对象是什么,你只要像如下这么命名,中国程序员基本都能看懂或猜个八九不离十:

    process_xx  处理xx
    do_yy       做yy
    handle_zz   处理zz
    check_xx    检查/校验xx
    collect_xx 收集xx

二、标志/类型代言人

在项目源码文件中,你会变量声明或结果体声明中看到太多的xx_flag或xx_type。xx_flag被大家“公认为”各种标志的代言人了;xx_type也好不到哪去。

    route_flag
    protocol_flag
    msg_flag
    session_flag

    msg_type
    check_type
    command_type
    session_type

三、字面意直译式

比如我们要声明两个变量,一个的意思是“是否打开消息过滤”,另外一个“是否关闭消息过滤”。对于中国人来说,打开/关闭最直接对应的就是open/close,于是就有了这样的变量命名:

    is_message_filter_open
    is_message_filter_close

其实一般认为更地道的方式应该是:

    is_message_filter_on
    is_message_filter_off

再举个例子,我们的系统要处理一种中文名为“长短信”的对象,于是直译过来就是:long_sms。但其真正的英文术语应该是Concatenated SMS

四、中文拼音式

在国内做行业解决方案,不可避免会遇到各种领域词汇,比如我们处理的一种业务称为农信通。估计是开发人员没能找到其对应的英文翻译,于是乎用上了我们的看家本领 – 拼音。

    nxt_url  农信通地址

这样的例子是否似曾相识呢!

五、单词“选秀”

采用这种方式的程序员应该是更具“责任心”的,至少他/她知道去查查英文词典^_^。

于是乎有了dispense_message、cache_overstock等变量命名。显然他是在字典的单词选秀中随意找到一个“顺眼”的、意思还算相近的单词就挑了出来。显然dispatch 、overflow要比dispense、overstock更地道和准确。

六、尾声

以上的“实例”确是从我们项目的代码中“挖掘”出来的,希望只是个案。面对这样的命名bad smell,我们是否有解决方法呢?没有捷径,语言的感觉是要一点点的去找的,个人觉得一个最行之有效的方法就是去看那些英语地道的程序员编写的代码,留 意他们是如何命名的。比如看一些著名欧美程序员的开源项目代码。另外对于行业特定领域,尽量用经过认可的英文翻译结果来命名。

不可否认,英语是编程领域的主流语言,包括中文在内的以其他语言为编码语言的编程语言十分罕见。对于欧美程序员来说,这是天然的优势;而对于其他非欧美国家的程序员,尤其是中国程序员来说,在走向“地道”的路上还要付出很多才行。

突破英语句型之'不耻下问篇'

脱口而出,’不耻下问’乃英语学习之真精神也,这里我们要学习一些经典的’问句’。

一、How …?

1、How about …?
How about taking a walk?
How about parking here?
How about going for a trip?

2、How do you like … ?
How do you like living in China?
How do you like your new job?
How do you like my new car?

3、How much should I pay for …?
How much should I pay for the hotel room?
– Actually, it’s free.

4、How often do you …?
How often do you go on a vocation?
– I never had a chance to go on a vocation.

How often do you eat out?
– I eat out all the time. I hate to cook.

5、How can you …? (带有强烈个人感情色彩)
How can you stand such terrible weather?
How can you stand her nagging all the time?
How can you stand the pressure here?

How can you treat me like that?
How can you do such a stupid thing?
– I don’t know. I wasn’t thinking I guess.

6、How come …? (!其后接正常语序)
How come he failed the exam ? Isn’t he the best student in the class?
How come you never visit us any more?
How come I have to go to bed so early?

7、How long have you been …?
How long have you been learning English?
How long have you been in China?
How long have you been feeling like this?

How long have you been married?
How long have you been working here?
How long have you been a computer programmer?
How long have you been having this dream?
How long have you been waiting here?
How long have you been collecting stamps?
How long have you been a football fan?

8、How long will it take …?
How long will it take to get there?
How long will it take to make a million dollars?
How long will it take to rebuild New York city?
How long will it take to finish the project?
How long will it take to conquer English?
How long will it take to fly from Beijing to New York?

9、How do you know … ?
How do you know I can’t do it?
How do you know it won’t work?
How do you know which stocks to buy?
How do you know my name?

10、How are you getting along with …?
How are you getting along with your roommate?
How are you getting along with your colleagues?
How are you getting along with your new girlfriend?
How are you getting along with your new boss?
– OK, I guess. I really don’t see him that much.

二、What …?

1、What about …?
What about your future?
What about the new restaurant?
What about going together?

2、What else …?
What else can I do for you?
What else have you heard?
What else do yo want to know?

3、What kind of …?
What kind of person do you think you are?
What kind of fool do you think I am?
What kind of movie do you like?

What kind of girl do you like?
– I like a loving, considerate, intelligent girl who is confident and knows what she want to do with her life.

4、What do you think … ?
What do you think I should do ?
What do you think you wants?
What do you think America will do to fight the terrorism?

What do you think the chances are of my passing the TOEFL exam?
– I think that your chances are good. You’ve been preparing for a long time and I’ve noticed a big improvment in your spoken English.

5、What would you like to…?
What would you like to know?
What would you like to do next?
What would you like to drink?

6、What do you think of …?
What do you think of China so far?
– Amazing!/Pretty good!

What do you think of her new boyfriend?
– I think he is easy-going, handsome, but stupid.

7、What’s wrong with …?
What’s wrong with George W. Bush?
What’s wrong with this world?
What’s wrong with your phone?

What’s wrong with the computer?
– It’s a cheap piece of junk.

8、What’s your favorite … ?
What’s your favorite food?
What’s your favorite kind of music?

9、What seems to be the problem with … ?
What seems to be the problem with your sister? She looks very upset this morning.

10、What makes/made you … ?
What made you so angry?
What makes you think he did it?
What makes you so motivated?

What makes you say that?
– I’ve been studying English for years. I know what I am talking about.

What makes you do such stupid things?
– I don’t know. I can’t control myself. I don’t want to do stupid things but I just can’t help it.

三、Why …?

1、Why didn’t you …?
Why didn’t you wait for me?
Why didn’t you tell me?
Why didn’t you buy it?

Why didn’t you say something earlier?
Why didn’t you call me?
– I’m terribly sorry. I slipped my mind.

2、Why don’t we just … ?
Why don’t we just have dinner together somewhere this Saturday?

3、Why do you think …?
Why do you think(What makes you think) Guangzhou is a bad place to live?

4、Why do you have to …? (有质问的语气)
Why do you have to tell her the truth?
Why do you have to leave so early?
– I have an early appointment tomorrow morning.

5、Why is it that…?
Why is it that I have had nightmares all these nights?
– Maybe you shouldn’t eat so much chocolate before bedtime.

四、When …?

1、When are you going to …?
When are you going to buy a new house?
When are you going to ask your boss for a raise?

2、When would you like to …?
When would you like to place an order?
– I’m not sure. I still need some time to think it over.

3、When do you want me to …?
When do you want me to have ready for you?
When do you want me to report for work tomorrow?

4、When could you possibly …?
When could you possibly finish this?
When could you possibly let me know the result?
– We will let you know the result as soon as possible.

5、When will it be convenient for you to …?
When will it be convenient for you to arrange an interview for me?
When will it be convenient for you to come to my office?

如发现本站页面被黑,比如:挂载广告、挖矿等恶意代码,请朋友们及时联系我。十分感谢! Go语言第一课 Go语言精进之路1 Go语言精进之路2 商务合作请联系bigwhite.cn AT aliyun.com

欢迎使用邮件订阅我的博客

输入邮箱订阅本站,只要有新文章发布,就会第一时间发送邮件通知你哦!

这里是 Tony Bai的个人Blog,欢迎访问、订阅和留言! 订阅Feed请点击上面图片

如果您觉得这里的文章对您有帮助,请扫描上方二维码进行捐赠 ,加油后的Tony Bai将会为您呈现更多精彩的文章,谢谢!

如果您希望通过微信捐赠,请用微信客户端扫描下方赞赏码:

如果您希望通过比特币或以太币捐赠,可以扫描下方二维码:

比特币:

以太币:

如果您喜欢通过微信浏览本站内容,可以扫描下方二维码,订阅本站官方微信订阅号“iamtonybai”;点击二维码,可直达本人官方微博主页^_^:
本站Powered by Digital Ocean VPS。
选择Digital Ocean VPS主机,即可获得10美元现金充值,可 免费使用两个月哟! 著名主机提供商Linode 10$优惠码:linode10,在 这里注册即可免费获 得。阿里云推荐码: 1WFZ0V立享9折!


View Tony Bai's profile on LinkedIn
DigitalOcean Referral Badge

文章

评论

  • 正在加载...

分类

标签

归档



View My Stats