您的位置:首页 > 编程语言

代码风格

2014-08-03 22:09 85 查看
bool setYxCommand(const QString &sCommandCode, char value) //遥信
bool setYcCommand(const QString &sCommandCode, char value) //遥测

//下面的情况中,我曾经花费了一定的时间去找出错误:用错了函数!
f_oPlcProtocol->setYxCommand("save_bottle_manual", 0);
f_oPlcProtocol->setYxCommand("save_bottle_auto", 0);
f_oPlcProtocol->setYxCommand("save_bottle_force", 0);
f_oPlcProtocol->setYcCommand("get_bottle_manual", 0);
f_oPlcProtocol->setYxCommand("get_bottle_auto", 0);
f_oPlcProtocol->setYxCommand("get_bottle_force", 0);

//a better name
bool setYxinCmd(const QString &sCommandCode, char value) //遥信
bool setYceeCmd(const QString &sCommandCode, char value) //遥测

//////////////////////////////////////////////////////////////////////////////////1

bool *ok;

if(ok) * ok = true;
if(ok) *ok = true;

//上面第一个if, 一眼看过去还以为是(ok) * ok = true !!
//第二个if就是简明的最好范例。
//////////////////////////////////////////////////////////////////////////////////2

QString position = QString("Save to:(%s,%d,%d)").arg(x).arg(y).arg(u);
QString position = QString("Save to:(%1,%2,%3)").arg(x).arg(y).arg(u);

//QString中很容易出错的用法!
//////////////////////////////////////////////////////////////////////////////////3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: