Readability
Here's another fundamental difference. Objective C is inherently more readable than C++ because method parameters are built into the name of the method. Consider:
// Objective C
[layer addChild:sprite z:1];
// C++
layer->addChild(sprite, 1);
You see the difference in readability?
Objective C is a bit easier to read because the 2nd parameter to the addChild method is clearly a z value. In C++, it's anyone's guess what "1" means.
Modern day Integrated Development Environments (IDEs) like Xcode mitigate the issue when you are writing code because of auto-completion. You start typing addChild and it gives you the parameter types and names. This makes it clear what the parameters are when you are writing the code. However, if you take some time off from the project and come back later, you might be a little perplexed when you glance at that addSprite call and wonder about the second parameter.
You can make C++ more readable by changing up your style a little bit. Like this:
int z = 1;
layer->addChild(sprite, z);
本文探讨了Objective-C与C++在代码可读性方面的差异,特别是通过方法参数内置到方法名称中来提高Objective-C的可读性。文章通过具体的代码示例展示了这种差异,并讨论了现代IDE如何缓解C++中可能遇到的问题。
139

被折叠的 条评论
为什么被折叠?



