我正在对初级(也许是高级)软件工程师所犯的常见错误和错误假设进行一些研究。

你坚持时间最长、最终被纠正的假设是什么?

例如,我误解了整数的大小不是标准的,而是取决于语言和目标。说起来有点尴尬,但事实就是这样。

坦率地说;你有什么坚定的信念?你大概坚持了多长时间?它可以是关于一种算法、一种语言、一个编程概念、测试,或者任何关于编程、编程语言或计算机科学的东西。


当前回答

:

for (int i = 0; i < myObj.variable; i = i + 1)

优化为:

int j = myObj.variable; 
for (int i = 0; i < j; i = i + 1)

哇,当我意识到它们每次都在运行时,我停止在j的地方放入函数调用!

原因:

for (int i = 0; i < myObj.variable; i = i + 1){ 
    if (function_argument == NULL){ 
        myObj.variable++; 
    } else { 
        printf("%d", myObj.variable);
    }
}

并不等同于:

int j = myObj.variable;
for (int i = 0; i < j; i = i + 1){ 
    if (function_argument == NULL){ 
        myObj.variable++; 
    } else { 
        printf("%d", myObj.variable);
    }
}

任意的例子,但是您可以看到优化将如何改变执行。

其他回答

代码越少越好。现在我知道,有时候如果代码行数更多,就更容易阅读/理解,这是值得的

我相信创建程序就像在课堂上教的一样……你和一群人坐在一起,讨论一个问题,想出一个解决方案,等等。相反,现实世界是“这是我的问题,我需要解决它,开始”,十分钟后你又遇到了另一个问题,让你没有真正的时间来有效地计划解决方案。

该条件检查如下:

if (condition1 && condition2 && condition3)

以不确定的顺序执行…

在c++中,很长一段时间我都在想编译器在给纯虚方法定义时拒绝你。

当我意识到我错了时,我很吃惊。

很多次,当我告诉别人为其抽象类提供其纯虚析构函数的默认实现时,他/她都用大大的眼睛看着我。我知道接下来会有一场长时间的讨论……这似乎在c++初学者中是一个普遍的信念(我认为我自己也是如此)。我目前还在学习!)

Wikipedia链接到c++的纯虚拟方法

我仍然对以下的一些误解感到困扰——尽管我知道这些误解是正确的,但我仍然试图抓住它们不放:

All stakeholders will make decisions about software design objectively. Those that aren't embroiled in writing the code make all sorts of decisions based entirely on emotion that don't always make sense to us developers. Project budgets always make sense - I've seen companies that are quite happy to drop [just for example] $50,000 a month for years rather than pay $250,000 to have a project completed in 6 months. The government for one loses their annual budget if they don't spend it - so spend it they will, come hell or high water. It astounds me at how many project dollars are wasted on things like this. You should always use the right tools for the right job - sometimes this decision is not in your hands. Sometimes it comes down from on high that "thou shalt use X technology" for this project, leaving you thinking "WTF! Who came up with that ridiculous idea?"... the guy paying your paycheque, that's who, now get it done. Programming ideology comes first and foremost, everything else is secondary. In reality, deadlines and business objectives need to be met in order to get your paycheque. Sometimes you make the worst decisions because you just don't have time to do it the right way... just as sometimes that word is on the tip of your tongue but the minute it takes to recall it makes you choose a different and less ideal word. There isn't always time to do it right, sometimes there is only time to do it - however that may be. Hence oft' seen anti-patterns used by so called experienced developers who have to knock out a solution to a problem 10 minutes before the presentation deadline for the software being delivered to your best client tomorrow.