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

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

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

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


当前回答

字节码解释的语言(如c#或f#)比那些直接编译成机器代码的重置按钮慢。

好吧,当我开始有这样的信念时(在80年代),这是真的。然而,即使是在c#中,我有时也会想“把这个内循环放到一个。cpp -文件中是否会让我的应用程序运行得更快”)。

幸运的是,没有。

可悲的是,我几年前才意识到这一点。

其他回答

我需要定义所有的变量,我将使用在我的函数在其开始(Pascal风格)。

我曾经相信我需要考虑我的函数使用的所有资源,并在我开始编码之前定义它们,这可能是因为我的第一门语言是Pascal,这是要求。然后当我转移到C语言时,我会定义只在这些循环之外的循环中使用的临时变量,忽略循环内作用域,只是为了“一切都将在开始时定义”。

我花了几年时间才明白,提前定义所有资源并不是一件容易的事,而且范围本身对代码可读性非常重要。

@Kyralessa: It's worth noting that on most processors, in assembly/machine language, it's possible for functions to return someplace other than their caller while leaving the stack in good condition. Indeed, there are a variety of situations where this can be useful. One variation I first saw on the 6502, though it works even better on the Z80, was a print-message routine where the text to be printed immediately followed the call instruction; execution would resume after the zero terminator (or, as a slight optimization when using the Z80, at the zero terminator, since letting the zero byte be executed as a NOP would be cheaper than trying to avoid it).

有趣的是,在许多现代语言中,函数都有一个正常的退出点(将在调用之后恢复执行),但也可以通过抛出异常退出。即使在C语言中,也可以使用setjmp/longjmp来模拟这种行为。

人们会关心最佳实践,甚至一致性。

My co-workers were/are producing supposedly bad code because they sucked/suck. It took me a while to learn that I should first check what really happened. Most of the times, bad code was caused by lack of management, customers who didn't want to check what they really wanted and started changing their minds like there's no tomorrow, or other circunstances out of anyone's control, like economic crysis. Customers demand "for yesterday" features because they are stupid: Not really. It's about communication. If someone tells them it everything can really be done in 1 week, guess what? they'll want it in 1 week. "Never change code that works". This is not a good thing IMO. You obviously don't have to change what's really working. However, if you never change a piece of code because it's supposedly working and it's too complex to change, you may end up finding out that code isn't really doing what it's supposed to do. Eg: I've seen a sales commission calculation software doing wrong calculations for two years because nobody wanted to maintain the software. Nobody at sales knew about it. The formula was so complex they didn't really know how to check the numbers.

我曾经认为ie6的盒子模式是微软为了破坏与其他浏览器的兼容性而想出的一个邪恶的愚蠢想法。

大量的csing使我相信它更符合逻辑,并且可以使页面设计维护(更改块填充/边框/页边距)更容易。

想想现实世界:改变A4页面的边框宽度并不会改变页面宽度,只会减少内容的空间。