我讨厌C ++的事情 [英] Things I hate about C++
问题描述
好的,我们走了,我觉得这是关于人们谈论C ++废话的时间(包括从C提出的废话) 。我会以自己的一些不满为开头:
1)整个函数声明与对象定义 fiasco,其中
导致以下(临时创建)语法:
Blah poo = Blah();
2)字符串文字如何不是const(即使它们是!),例如:
void Blah(char * const p_k)
{
* p_k ='''4''; // Opps!
}
int main()
{
Blah("你好);
}
3)数组如何衰减到指针...
以下是可能的:
unsigned& r = * new unsigned;
但以下不是:
unsigned(& r)[10] = * new unsigned [10];
这就是我现在所能想到的全部!
-JKop
Okay here we go, I feel it''s about time people conversed about the bullshit
aspects of C++ (including the bullshit stuff brought forward from C). I''ll
begin with a few of my own grievances:
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:
Blah poo = Blah();
2) How string literals are not const (even though they are!), for instance:
void Blah(char* const p_k)
{
*p_k = ''4''; //Opps!
}
int main()
{
Blah("Hello");
}
3) How arrays decay to pointers...
The following is possible:
unsigned &r = *new unsigned;
But the following is not:
unsigned (&r)[10] = *new unsigned[10];
That''s all I can think of right now!
-JKop
推荐答案
JKop写道:
JKop wrote:
好的,我们走了,我觉得这是关于人们谈论
废话的时间C ++的各个方面(包括从C提出的废话)。我会以自己的一些不满开始:
哦,亲爱的。你没有表现出很多尊重C ++的承诺,但你希望C ++
尊重你。
1)整个函数声明对象定义 fiasco,它导致以下(临时创建)语法:
Blah poo = Blah();
A>你不需要这样做。
B>编译器可以优化暂时的分离
C>编译器无法优化= away,所以如果它是
private不应该在Blah'
内部范围之外编译。
2)字符串文字不是const(即使它们是!),对于
实例:
void Blah(char * const p_k)
{
* p_k ='' 4 ''; // Opps!
}
int main()
{
Blah(你好);
}
这是为了避免破坏质量差的C代码(就像我以前写的那样)。
3)数组如何衰减到指针......
以下是可能的:
unsigned& r = * new unsigned;
但以下不是:
unsigned(& r) [10] = * new unsigned [10];
本周的侍从问题:
这是为了什么?
模板< ; class foo,size_t max>
inline size_t
get_count(foo const(& array)[max])
{
返回最大值;
}
你在哪里可以使用它?你哪里不能用它?你怎么能改善它?
这就是我现在能想到的全部!
Okay here we go, I feel it''s about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I''ll
begin with a few of my own grievances:
Oh, dear. You have not shown much promise respecting C++, yet you want C++
to respect you.
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:
Blah poo = Blah();
A> you don''t need to do that.
B> the compiler can optimize the temporary away
C> the compiler cannot optimize the = away, so if it''s
private that should not compile outside Blah''s
internal scope.
2) How string literals are not const (even though they are!), for instance:
void Blah(char* const p_k)
{
*p_k = ''4''; //Opps!
}
int main()
{
Blah("Hello");
}
That''s to avoid breaking poor quality C code (like I used to write).
3) How arrays decay to pointers...
The following is possible:
unsigned &r = *new unsigned;
But the following is not:
unsigned (&r)[10] = *new unsigned[10];
Acolyte of the Week question:
What''s this for?
template<class foo, size_t max>
inline size_t
get_count(foo const (&array)[max])
{
return max;
}
Where can you use it? Where can''t you use it? How can you improve it?
That''s all I can think of right now!
除了这些之外还有很多严重的问题那些人可以''lint''
离开。
例如,你写的''new''会泄漏。
< br $>
(我知道我知道 - 操作系统内存仙子会清理它......)
-
Phlip
http://industrialxp.org/community/bi ... UserInterfaces
* JKop:
1)整个函数声明与对象定义 fiasco,它导致以下(临时创建)语法:
Blah poo = Blah();
一个优秀的编译器不会在这里创建一个临时的,但你是对的:
C语法是一个惨败,而且IIRC通过创造者。
2)字符串文字不是const(即使它们是!),
对。这对你来说是旧的C兼容性。
例如:
无效Blah(char * const p_k)
{
* p_k ='''4''; // Opps!
}
int main()
{
Blah(你好);
}
不正确。函数Blah的论证应该是
void Blah(char const * p_k)
用于预期的const''ness效果。 />
3)数组如何衰减到指针......
以下是可能的:
unsigned& r = * new unsigned;
但以下情况并非如此:
unsigned(& r)[10] = * new unsigned [10];
更好(或更糟!)的例子可能是
typedef unsigned UnsignedArray [10];
UnsignedArray & r = *(新的UnsignedArray);
再次,这是C传承。
这就是我能想到的全部权利现在!
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:
Blah poo = Blah();
A good compiler will not create a temporary here, but you''re right: the
C syntax is a fiasco, and IIRC acknowledged as such by the creators.
2) How string literals are not const (even though they are!),
Right. That''s old C compatibility for you.
for instance:
void Blah(char* const p_k)
{
*p_k = ''4''; //Opps!
}
int main()
{
Blah("Hello");
}
Incorrect. The argument of function Blah should be
void Blah( char const* p_k )
for the intended const''ness effect.
3) How arrays decay to pointers...
The following is possible:
unsigned &r = *new unsigned;
But the following is not:
unsigned (&r)[10] = *new unsigned[10];
A better (or worse!) example is perhaps
typedef unsigned UnsignedArray[10];
UnsignedArray &r = *(new UnsignedArray);
Again, that''s the C heritage.
That''s all I can think of right now!
嗯,嗯,还有更多。这是兼容性的代价。
如果没有兼容性,我怀疑C ++会非常成功。
-
答:因为它弄乱了人们通常阅读文字的顺序。
问:为什么这么糟糕?
A:热门发布。
问:usenet和电子邮件中最烦人的是什么?
Uhm, well, there''s much more. That''s the price for compatibility.
Without the compatibility I doubt that C++ would have been very
successful.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
哦,亲爱的。你没有表现出很多尊重C ++的承诺,但你希望C ++能够尊重你。
我既不尊重,也不希望得到尊重,而不是
才有资格成为有机体。
Oh, dear. You have not shown much promise respecting C++, yet you want
C++ to respect you.
I neither give respect to, nor wish to receive respect from, what does not
qualify as an organism.
1)整个函数声明与对象定义 fiasco,它导致以下(临时创建)语法:
Blah poo = Blah();
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:
Blah poo = Blah();
A>你不需要这样做。
A> you don''t need to do that.
没有评论。不,实际上,评论:废话。
B>编译器可以优化临时值
编译器*可以*优化临时值。
C>编译器无法优化= away,所以如果它是私有的,那么不应该在Blah'
内部范围之外编译。
如果什么是私人的?我认为你是关于复制构造函数的。
如果你指的是=,就像在赋值运算符中那样,那就不要了/>
响应。
No comment. No, actually, comment: Bullshit.
B> the compiler can optimize the temporary away
The compiler *may* optimize the temporary away.
C> the compiler cannot optimize the = away, so if it''s
private that should not compile outside Blah''s
internal scope.
If "what" is private? I presume you''re on about the copy contructor.
If you''re referring to "=", as in the assignment operator, then don''t
respond.
2)字符串文字不是const(即使它们是!),对于
实例:
void Blah(char * const p_k)
{
* p_k ='''4''; // Opps!
}
int main()
{
Blah(你好); }
2) How string literals are not const (even though they are!), for
instance:
void Blah(char* const p_k)
{
*p_k = ''4''; //Opps!
}
int main()
{
Blah("Hello"); }
这是为了避免破坏质量差的C代码(就像我以前写的那样)。
That''s to avoid breaking poor quality C code (like I used to write).
.. 。这使得它不废话,因为?
例如,你写的''new''会泄漏。
.. . .and this makes it non-bullshit because?
For example, the ''new'' you wrote will leak.
请不要不是傻瓜。我在上一篇文章中也没有提到我在过去3天里喝过水b
。这是否意味着我即将离开?
-JKop
Please don''t be stupid. I also didn''t mention in my last post that I''d drunk
water in the last 3 days. Does that mean I''m on my way out soon?
-JKop
这篇关于我讨厌C ++的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!