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.
对于代码和程序你会有一种本能的讨厌,这是因为这些代码和程序看起来很丑陋,并且不容易维护。
In fact, this example would compile because you can use curly braces in this way to encapsulate lines of code, but realize for now, that, not good.
实际上,这个例子可以编译,因为你可以用这种方式来压缩代码行,但是请认识到,那个,不太好。
I can, oh, these have got some remnants which we really don't need.
我可以,哦,这里有些我们用不上的代码。
Once your programs get fairly complex, it becomes harder and harder to find things and to tweak things if you're not being organized.
一旦代码稍微复杂点,而你又不规范你的代码,那么你想找什么东西就很困难了。
Because if I don't specify a name for this input, I have no way of actually referring to it in subsequent lines of code.
因为如果我不给这个输入定义一个名字,在随后的代码中,我就没有办法使用它。
So if you're coming from prior background, your code might work a little differently on a different system if you don't use those flags.
如果你来自一个先前的背景,如果你们没有使用这个版本标志的话,在一个不同的系统中,你的代码可能运行地不太一样。
So I actually don't need the curly braces because I only have a single line of code.
所以我实际上不需要那个花括号,因为我只有一行代码。
- Writing code that just looks-- I'm not even sure what this is supposed to look like, a little flower or pinwheel or something like that.
这代码写出来有点像-,我不确定这像什么,像朵花,或纸风车,或其他什么东西。
Today, I'm gonna start writing C code with you but I can't just write it and expect it to do anything.
现在,我和大家一起写C语言代码,但我不指望写出来后就能跑起来。
OK? And in fact, if you look at the code up here, and it's on your handout, the very first one, x 1, right here- if I could ask you to look at it-- is a piece of code to do it. And I'm less interested in the code than how we're going to analyze it, but let's look at it for a second.
实际上,如果你看看,你们课堂发的材料上面的代码,第一页上的,就是那-,大家请看看实现的这一部分代码,我不太关心,我们会怎么解释这个代码,首先让我们先看看。
Pseudo code. Now, you're all linguistic majors, pseudo means false, this sounds like code that ain't going to run, and that's not the intent of the term. When I say pseudo code, what I mean is, I'm going to write a description of the steps, but not in a particular programming language.
伪代码,基于你们都是学语言的,伪代码意味着不正确,这听起来就像是没法运行的代码,这可不是我们学这个的目的,当我说到伪代码的时候,我的意思是要对步骤进行一个描述,而不是某种特定的编程语言。
Things generally break and this is also not very readable.
一切都改变了,而且这样写出的代码可读性也不高。
Code is different in the handout.
那上面的代码是不一样的。
Because as you'll soon find, when you're writing programs 0 that aren't just four lines long but are 40 or 400 which very quickly becomes easy, you'll find that even you the next morning have no idea what this code does for whatever reason, and just having some English comments is a huge boon to comprehension for yourself and others.
你们自己写程序时就会发现,用40行甚至400行代码来代替繁杂拥挤的4行代码0,将会让事情简化许多,你会发现,即使由于某些原因,你不知道如何写代码,先写些注释,于人于己,都是好事,易于理解嘛。
So now, in this case, this code is going to, when we get here, check, and if you haven't seen that strange thing there, that exclamation point in bang computer-ese called a bang, it says x if ANS star ANS is not equal to x, all right?
那么现在,在这个例子中,当我们执行到这里,代码会去检查,如果你没有看到过这个奇怪的东西,这个感叹号在计算机学中被叫做,代码的意思是如果ANS的平方不等于?
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的编辑器,这个跟写字板和记事本差不多-,非常简单的,只是通过一种有用的方法而进行精简了的,所以你们可以把注意力集中在编写代码上,而不需要学习一些新的界面操作。
We began here so at this point in the story the next thing that's going to happen is this line called Print F that says swap exclamation point, right?
我们从这里开始,在这里,下一步将要发生了的事情是,这行叫做printf的代码,打印:“交换完成!“对不?
As an aside, if you ever just have one line of code that you want to execute, one puzzle piece in Scratch terminology, ; you actually don't need the curly braces; you only need the curly braces if you have two or more lines of code that you want to execute if that condition is true.
此外,如果你只有一行代码,需要执行,在Scratch,术语中叫做,一句代码,你就不需要使用花括号了;,如果那个条件成立,你有两行或更多行的代码时需要执行时,你就需要花括号。
应用推荐