默认值 - 好的,坏的和丑的 [英] default values - the good, the bad and the ugly

查看:80
本文介绍了默认值 - 好的,坏的和丑的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


一些线程我有一些关于默认值的聊天。我正在开始这个

线程因为我想听到更多关于

函数参数的默认值的意见。有人说他们看不到使用它们。其他人说他们说他们b $ b很糟糕。我喜欢他们。那么,有谁可以告诉我他们为什么符合标准?

他们不好吗?


我不打算开始战争。我也不是一个巨魔。


/ dan


交换名称/域名通过邮件回复

Hi there,

A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they see no use of them. Others say thar they
are bad. I like them. So, could anyone tell me why they are in the standard?
Are they bad?

I do not intend to start war. Nor am I a troll.

/dan

swap name/domain to reply by mail

推荐答案

" Dan Cernat" < CE **** @ dan.com>写了...
"Dan Cernat" <ce****@dan.com> wrote...
一些线程我聊了一下默认值。我正在开始这个
线程,因为我想听到更多关于
函数参数的默认值的意见。有人说他们看不到使用它们。其他人说他们是坏的b
。我喜欢他们。那么,谁能告诉我为什么他们处于
标准?它们不好吗?
A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they see no use of them. Others say thar they are bad. I like them. So, could anyone tell me why they are in the standard? Are they bad?




我认为那些称任何语言功能的人都是坏的需要找到关于狐狸和葡萄的旧寓言。另一个比喻

在于一句老话:坏舞者的腿总是妨碍他的舞蹈。

$ b例如,如果我们没有默认参数,$ b我就不能想象代码会更加繁琐。如果有
是需要做一些小的行为调整一些

函数全部使用代码,我可以轻松添加额外的

参数,给它一个默认值,从而保持调用

代码不变。只有我的新代码才会使用非默认参数

值。这只是一个例子。


Victor



I think those who call any language feature "bad" need to find
the old fable about the fox and the grape. Another analogy
lies in an old saying "Bad dancer''s legs always in the way of
his dancing".

I, for one, cannot imagine how much more tedious would code
maintenance be if we didn''t have default arguments. If there
is a need to make some minor behaviour adjustment of some
function used all over the code, I can easily add an extra
argument, give it a default value and thus leave the calling
code untouched. Only my new code will use non-default argument
values. That''s only one example.

Victor


" Dan Cernat" < CE **** @ dan.com>写了...
"Dan Cernat" <ce****@dan.com> wrote...
一些线程我聊了一下默认值。我正在开始这个
线程,因为我想听到更多关于
函数参数的默认值的意见。有人说他们看不到使用它们。其他人说他们是坏的b
。我喜欢他们。那么,谁能告诉我为什么他们处于
标准?它们不好吗?
A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they see no use of them. Others say thar they are bad. I like them. So, could anyone tell me why they are in the standard? Are they bad?




我认为那些称任何语言功能的人都是坏的需要找到关于狐狸和葡萄的旧寓言。另一个比喻

在于一句老话:坏舞者的腿总是妨碍他的舞蹈。

$ b例如,如果我们没有默认参数,$ b我就不能想象代码会更加繁琐。如果有
是需要做一些小的行为调整一些

函数全部使用代码,我可以轻松添加额外的

参数,给它一个默认值,从而保持调用

代码不变。只有我的新代码才会使用非默认参数

值。这只是一个例子。


Victor



I think those who call any language feature "bad" need to find
the old fable about the fox and the grape. Another analogy
lies in an old saying "Bad dancer''s legs always in the way of
his dancing".

I, for one, cannot imagine how much more tedious would code
maintenance be if we didn''t have default arguments. If there
is a need to make some minor behaviour adjustment of some
function used all over the code, I can easily add an extra
argument, give it a default value and thus leave the calling
code untouched. Only my new code will use non-default argument
values. That''s only one example.

Victor


" Dan Cernat" < CE **** @ dan.com>在消息中写道

新闻:vq ************ @ corp.supernews.com ...
"Dan Cernat" <ce****@dan.com> wrote in message
news:vq************@corp.supernews.com...
你好,

有几个线程我聊了一下默认值。我正在开始这个
线程,因为我想听到更多关于
函数参数的默认值的意见。有人说他们看不到使用它们。其他人说他们是坏的b
。我喜欢他们。那么,谁能告诉我为什么他们处于
标准?他们不好吗?

我不打算开战。我也不是一个巨魔。

/ dan

交换名称/域名通过邮件回复
Hi there,

A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they see no use of them. Others say thar they are bad. I like them. So, could anyone tell me why they are in the standard? Are they bad?

I do not intend to start war. Nor am I a troll.

/dan

swap name/domain to reply by mail




好吧,让我们说我们取消默认参数。然后不要说:


void f(int x,int y = 0){..}


我们不得不说:


void f(int x,int y){...}

void f(int x){f(x,0);}


所以默认参数基本上只是一个过载的简写符号。

对于恕我直言几乎不值得过度换气。


-

Cy
http:// home.rochester.rr.com/cyhome/


这篇关于默认值 - 好的,坏的和丑的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆