• You should acquire overtime this instinctive aversion to just code or programs that just look ugly because things that look ugly generally are not easy to maintain.

    对于代码和程序你会有一种本能的讨厌,这是因为这些代码和程序看起来很丑陋,并且不容易维护。

    哈佛公开课 - 计算机科学课程节选

  • And so you'll learn over time both by seeing and by doing that there are generally some good ways, some okay ways, and some bad ways of actually writing code.

    久而久之,你们将通过看实践来学习到,这里通常有很好的方法,还行的方法,很烂的方法来编写代码

    哈佛公开课 - 计算机科学课程节选

  • This chunk of code and this chunk of code, they're really doing the same thing.

    这一块代码和这一块代码,它们实际上是相同的功能。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • The idea of a "code walkthrough" refers to the process of walking through your code verbally or visually with or without other people.

    代码走查“的概念是单独或者别人一起,通过查看或讨论学习你们的代码,的一个过程。

    哈佛公开课 - 计算机科学课程节选

  • This little set of code here from create insert and number. What's create do?

    这一小段代码是创建插入编号的,创建是做什么的?

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • You want to write the specs so that everybody does in fact know what this piece of code is doing, and you're writing it each time around.

    但是你得养成良好的习惯编程风格,你得撰写规范说明从而保证,每个人都知道这段代码是干什么的。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • So let's actually see how we solve this with this function with actual code.

    然我们看看怎样用,这个函数代码解决这个问题。

    哈佛公开课 - 计算机科学课程节选

  • Today, I'm gonna start writing C code with you but I can't just write it and expect it to do anything.

    现在,我大家一起写C语言代码,但我不指望写出来后就能跑起来。

    哈佛公开课 - 计算机科学课程节选

  • Remember last time, I said that there's different kinds of complexity in our code, and I suggested for simple branching programs, the amount of time it takes to run that program is, in essence, bounded by the number of instructions, because you only execute each instruction at most once.

    但是这里有个很重要的点,记得上节课,我提过在我们的代码中,有不同种类的复杂度,而且我还说了对于简单的分支程序,运行这种程序需要的总体时间,大体上,是指令的数目相关的,因为每个指令只会被执行最多一次。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • So, summarizing better, assert is something you put in to say to the user, make sure you're giving me input of this type, but I'm going to guarantee you the rest of the code works correctly. Exceptions and exception handlers are saying, here are the odd cases that I might see and here's what I'd like to do in those cases in order to try and be able to deal with them.

    所以更好的总结下,断言就是你放在那里告诉用户,保证你输入的是这种类型的,但我能保证剩下的代码运行正确,异常异常处理做的事,这里有些我能预期的异常情况,并且这里有些情况,我能尝试处理。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Even though this looks like what the out-- this looks like the output you want, "Oh, hi world" and then everything else should go on the next line.

    即使这样看起来你-,想要的输出“Oh,hi,world“没啥两样“,仅仅只是把其他代码往下挤了一行。

    哈佛公开课 - 计算机科学课程节选

  • I want to talk a little bit about how you use the things we've been building in terms of functions to help you structure and organize your code.

    第一件事情就是我要谈下,怎么利用我们,所做的能在方法方面,帮助你们组织优化代码

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • or at least one mechanism, I shouldn't say -- the only one-- one mechanism for doing that is going to be to add functions is that it's going to provide both of these things, so the first thing it's going to do is, it's going to let us break up into modules.

    我们处理这些的机制--至少一种机制,我不会说只有一种,一种机制是在我们的语言中增加函数,函数的关键是它要提供分解抽象,所以第一件要做的事,就是将代码分解为模块。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • But here, if I decide I'm going to store things not in x and y, but with some other set of names, for example, I've gotta go back into these pieces of code that use the points, and change them. So I've lost modularity.

    除了要改下借口,但是这里,如果我决定,我不把值放在xy中,而是其他一些变量名进行绑定,例如这样的话,我就得回到使用这个点的代码,那儿去做更改了。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • This code does swap the two values, A and B. However, when I run this program, something happens.

    这个代码没有交换那两个值,AB,但是,当我运行这个程序时,有些事情发生了。

    哈佛公开课 - 计算机科学课程节选

  • And I originally decided I was going to have as points, it's going to have internal values of an x and a y.

    写了一堆代码,然后我以开始决定,是要把值放到点里面的,点有内部的x坐标y坐标。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • It becomes a 13 and that is consistent with the code and it also doesn't crash because now y has been assigned to the correct value.

    它变成了一个13,这个代码是一致的,程序也不会崩溃,因为现在y被赋了正确的值。

    哈佛公开课 - 计算机科学课程节选

  • You open what we call the "text editor," the specific one we used on Wednesday was called Nano, -- which is similar to Notepad or TextEdit -- totally simple, kind of dumbed down but in a useful way so that you can just focus on writing code and not learning some new interface.

    你先打开那个“文本编辑器“,就是我们周三用过的叫做Nano的编辑器,这个跟写字板记事本差不多-,非常简单的,只是通过一种有用的方法而进行精简了的,所以你们可以把注意力集中在编写代码上,而不需要学习一些新的界面操作。

    哈佛公开课 - 计算机科学课程节选

  • OK, so how can I code this up? Well, you might think, let's just jump in and write some code, I don't want to quite do that though, because I want to show you another tool that's valuable for thinking about how to structure the code, and that is a something called a flow chart. Now.

    好,那么我怎么把这个以代码实现呢,你可能会想,让我们进去直接写代码把,但是我不想这么做,因为我想教给大家另外一项很有价值的,用来组织代码的工具,叫做流程图,现在,像Guttag教授,我这么大岁数的人。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • So in other words, if you terminate these lines early, if you terminate the four loop early, if you terminate an if condition early with that semicolon, the code may very well work; and this is a common source -- of frustration and conundrum because you don't -- because your code looks right and yet it's misbehaving, but that semicolon means stop looking for subsequent lines of related code.

    换句话说,如果你用分号过早的终止了这些代码行,如果你过早地终止了那个for循环,如果如此,一个if条件,代码可能可以运行,这就是,挫折问题产生的源头,因为你没有-,因为你的代码看起来是正确的,但是运行是错误的,那个分号的意思是,停止寻找后面相关的代码

    哈佛公开课 - 计算机科学课程节选

  • But notice what this does. The first thing it does is, it says, let's check and make sure x is greater than or equal to 0. If it isn't, notice what's going to happen. None of that block is going to get executed, and it's going to come down here and print out a useful piece of information, which says, hey, you gave me a negative number. I don't know how to do this.

    做的是以前一样的事情,但是注释它做了什么,第一件做的事情就是,程序说,要去检查并且确信x是大于等于0的,如果不是的话,请注意会发生什么,下面的代码都不会被执行,程序会到这里来然后显示一些有用的信息,信息会说,嘿,你给了我一个负数,我不知道该怎么弄这个了。

    麻省理工公开课 - 计算机科学及编程导论课程节选

$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定