@@ -875,12 +875,12 @@ Optional 的世界中取出来只是为了强调它们
875
875
176
876
876
00:09:25,532 --> 00:09:27,432
877
877
because there's a lot in the reading that you're doing
878
- // todo
878
+ 因为这有很多你已经阅读过的关于 Optional 的东西了
879
879
880
880
177
881
881
00:09:27,501 --> 00:09:29,934
882
882
about optional, but these are kind of the highlights.
883
- // todo
883
+ 但是还是有一些强调点的
884
884
885
885
178
886
886
00:09:30,003 --> 00:09:32,437
@@ -2011,7 +2011,7 @@ But they're new to a lot of you, and so I'm gonna try and
2011
2011
403
2012
2012
00:21:58,886 --> 00:22:01,119
2013
2013
ease you in with these ones that are more familiar,
2014
- // todo
2014
+ 等你们更熟悉时你们就会更方便地理解它
2015
2015
2016
2016
404
2017
2017
00:22:01,188 --> 00:22:03,855
@@ -2202,7 +2202,7 @@ it means you can't call any of its mutable functions, So
2202
2202
441
2203
2203
00:23:52,199 --> 00:23:55,800
2204
2204
you can't do perform operation on it. Now in assignment two,
2205
- 你不能对它进行操作。现在在任务二中
2205
+ 你不能对它进行操作。在任务二中
2206
2206
2207
2207
442
2208
2208
00:23:55,869 --> 00:23:58,704
@@ -2212,222 +2212,277 @@ I'm gonna have you add a method to the calculator brain
2212
2212
443
2213
2213
00:23:58,772 --> 00:24:01,539
2214
2214
that is gonna let you use the calculator brain when it's
2215
+ 那使你们在当 CalculatorBrain 是不可改变的时候
2215
2216
2216
2217
444
2217
2218
00:24:01,608 --> 00:24:04,843
2218
2219
immutable, which is kinda cool. You still wouldn't be
2220
+ 使用它,这很酷。你依然不能
2219
2221
2220
2222
445
2221
2223
00:24:04,912 --> 00:24:07,545
2222
2224
able to perform operation but you can be able to something
2225
+ 操作它但是你可以做一些重要的
2223
2226
2224
2227
446
2225
2228
00:24:07,614 --> 00:24:12,350
2226
2229
very important, immutably. Now because of this, this kind of
2230
+ 不可改变的事情。因此,值类型的
2227
2231
2228
2232
447
2229
2233
00:24:12,419 --> 00:24:15,487
2230
- copyright-on-write behavior of value types, you must,
2234
+ copy-on-write behavior of value types, you must,
2235
+ 写入时复制的行为,你必须
2231
2236
2232
2237
448
2233
2238
00:24:15,556 --> 00:24:18,957
2234
2239
of course, mark all the functions that are going to
2240
+ 标记所有函数
2235
2241
2236
2242
449
2237
2243
00:24:19,026 --> 00:24:23,094
2238
2244
modify it as mutating. And that's how the Swift knows,
2245
+ 并且这也是 Swift 知道
2239
2246
2240
2247
450
2241
2248
00:24:23,163 --> 00:24:27,299
2242
2249
"Oops, I've gotta make a copy of this, an actual real copy,
2250
+ “哦,我得到了它的一个拷贝,一个真正的拷贝
2243
2251
2244
2252
451
2245
2253
00:24:27,368 --> 00:24:31,135
2246
2254
if someone writes to it". Now a reference class is pretty
2255
+ 如果有人往它里面写数据的话。“引用类型是很
2247
2256
2248
2257
452
2249
2258
00:24:31,204 --> 00:24:34,639
2250
2259
different in that it gets stored in the heap somewhere
2260
+ 不同的,它被储存在一个堆中
2251
2261
2252
2262
453
2253
2263
00:24:34,708 --> 00:24:37,909
2254
2264
with a pointer to it, and when you pass it around to
2265
+ 有一个指针指向它,当你把它传送到
2255
2266
2256
2267
454
2257
2268
00:24:37,978 --> 00:24:41,713
2258
2269
a function or to assign it to another variable or something
2270
+ 函数中或将它分配给另一个变量之类的东西时
2259
2271
2260
2272
455
2261
2273
00:24:41,782 --> 00:24:46,618
2262
2274
like that, you're just passing a pointer around to it.
2275
+ 你只是在传送指向它的指针
2263
2276
2264
2277
456
2265
2278
00:24:46,687 --> 00:24:51,089
2266
2279
Now, by the way, when you say, let x equal a reference type,
2280
+ 现在,顺带一提,当你写,let x = 一个引用类型时
2267
2281
2268
2282
457
2269
2283
00:24:51,158 --> 00:24:54,626
2270
2284
you can still send it messages that will mutate it.
2285
+ 你依然可以给它发送使它转变的信息
2271
2286
2272
2287
458
2273
2288
00:24:55,996 --> 00:24:58,764
2274
2289
All you're saying is the pointer can't change, but
2290
+ 你们都被告知指针是不能改变的,但是
2275
2291
2276
2292
459
2277
2293
00:24:58,833 --> 00:25:01,533
2278
2294
what it points to can always be changed.
2295
+ 指针指向的东西在任何时候都能改变
2279
2296
2280
2297
460
2281
2298
00:25:01,601 --> 00:25:05,137
2282
2299
Now reference types are what you're used to.
2300
+ 引用类型是你们习惯的
2283
2301
2284
2302
461
2285
2303
00:25:05,205 --> 00:25:08,974
2286
2304
Most languages that have object-oriented reference
2305
+ 大部分语言都有面向对象的引用
2287
2306
2288
2307
462
2289
2308
00:25:09,043 --> 00:25:15,213
2290
2309
types. Reference types are a little bit Wild West- I
2310
+ 类型。引用类型有点狂野——我
2291
2311
2292
2312
463
2293
2313
00:25:15,282 --> 00:25:17,816
2294
2314
don't have time to teach you this, I hope you'll get to see
2315
+ 没时间给你们讲这个,我希望你们在斯坦福的时光里可以
2295
2316
2296
2317
464
2297
2318
00:25:17,885 --> 00:25:19,651
2298
2319
this sometime in your career at Stanford, but
2320
+ 可以见到它
2299
2321
2300
2322
465
2301
2323
00:25:19,720 --> 00:25:21,820
2302
2324
there is a different way of thinking about programming
2325
+ 有一种不同的编程思想,它与你们之前
2303
2326
2304
2327
466
2305
2328
00:25:21,888 --> 00:25:23,988
2306
2329
than you're used to: it's called functional programming.
2330
+ 接触到的不同:它叫做函数式编程
2307
2331
2308
2332
467
2309
2333
00:25:24,057 --> 00:25:25,089
2310
2334
How many people have heard the phrase,
2335
+ 有多少人曾经听说过这个词
2311
2336
2312
2337
468
2313
2338
00:25:25,158 --> 00:25:29,227
2314
2339
functional programming? So about half of you. The idea
2340
+ 函数式编程?有一半左右。函数式编程
2315
2341
2316
2342
469
2317
2343
00:25:29,296 --> 00:25:31,663
2318
2344
of functional programming is: you don't want this Wild West
2345
+ 的思想是:你不想要这样的狂野
2319
2346
2320
2347
470
2321
2348
00:25:31,732 --> 00:25:34,599
2322
2349
where you've got these objects with multiple people pointing
2350
+ 你得到这些有多人指向它们的对象
2323
2351
2324
2352
471
2325
2353
00:25:34,668 --> 00:25:37,936
2326
2354
at them, any of whom could modify it at any time.
2355
+ 它们中任何一个在任何时间都能修改它
2327
2356
2328
2357
472
2329
2358
00:25:38,004 --> 00:25:41,105
2330
2359
That leaves you open to a lot of difficulty in verifying
2360
+ 这给你核实你的程序的正确性
2331
2361
2332
2362
473
2333
2363
00:25:41,174 --> 00:25:42,975
2334
2364
the correctness of your program.
2365
+ 带来了不小的困难
2335
2366
2336
2367
474
2337
2368
00:25:43,043 --> 00:25:46,278
2338
2369
Whereas if you have a lot of objects that are immutable,
2370
+ 然而如果你有一大堆不可改变的对象
2339
2371
2340
2372
475
2341
2373
00:25:46,346 --> 00:25:49,715
2342
2374
you know they can't change, and their APIs are basically
2375
+ 你知道它们不可能被改变,并且它们的 API 基本上
2343
2376
2344
2377
476
2345
2378
00:25:49,783 --> 00:25:52,718
2346
2379
like mathematical functions where data goes in and
2380
+ 类似于数学函数,数据输入后
2347
2381
2348
2382
477
2349
2383
00:25:52,786 --> 00:25:55,520
2350
2384
predictable data comes out, because there's
2385
+ 可预计的数据输出,因为
2351
2386
2352
2387
478
2353
2388
00:25:55,588 --> 00:25:59,291
2354
2389
not all this side-effecting, data-effecting other objects
2390
+ 不是所有 // todo
2355
2391
2356
2392
479
2357
2393
00:25:59,359 --> 00:26:02,194
2358
2394
that someone else is pointing to in all this.
2395
+ // todo
2359
2396
2360
2397
480
2361
2398
00:26:02,262 --> 00:26:04,595
2362
2399
It's this really well-contained little thing.
2400
+ 这是个非常好的东西
2363
2401
2364
2402
481
2365
2403
00:26:04,664 --> 00:26:08,433
2366
2404
Now iOS was not developed with functional programming in mind
2405
+ iOS 完全不是由函数式编程
2367
2406
2368
2407
482
2369
2408
00:26:08,502 --> 00:26:11,603
2370
2409
at all. But the people who invented Swift,
2410
+ 开发的。但是发明 Swift 的这群人
2371
2411
2372
2412
483
2373
2413
00:26:11,671 --> 00:26:15,074
2374
2414
they were thinking about functional programming, So
2415
+ 它们用函数式编程思考,所以
2375
2416
2376
2417
484
2377
2418
00:26:15,142 --> 00:26:17,009
2378
2419
you can kind of mix a lot of the elements of
2420
+ 你可以混合很多函数式编程
2379
2421
2380
2422
485
2381
2423
00:26:17,077 --> 00:26:19,244
2382
2424
functional programming into your application,
2425
+ 的元素到你的应用程序中
2383
2426
2384
2427
486
2385
2428
00:26:19,312 --> 00:26:22,080
2386
2429
if you're building an iOS application. Now that's a new
2430
+ 如果你正在开发一款 iOS 应用程序。现在它是 iOS 的
2387
2431
2388
2432
487
2389
2433
00:26:22,149 --> 00:26:26,051
2390
2434
frontier in iOS, because for however long, 20 years,
2435
+ 新边界,因为不管多久,20年
2391
2436
2392
2437
488
2393
2438
00:26:26,119 --> 00:26:28,120
2394
2439
really, or 30 years, really, if you consider all the way
2440
+ 或是30年,如果你考虑到
2395
2441
2396
2442
489
2397
2443
00:26:28,188 --> 00:26:31,723
2398
2444
back to the invention of the technology that led to iOS,
2445
+ 所有的引领 iOS 的技术的发明
2399
2446
2400
2447
490
2401
2448
00:26:31,792 --> 00:26:36,028
2402
2449
people have been programming with basically
2450
+ 人们已经基本上只在
2403
2451
2404
2452
491
2405
2453
00:26:36,096 --> 00:26:39,831
2406
2454
reference types only, for their object-orienting.
2455
+ 面向对象时用引用类型编程
2407
2456
2408
2457
492
2409
2458
00:26:39,900 --> 00:26:42,534
2410
2459
But when you do this programming with structs and
2460
+ 但当你用结构体和枚举,特别是协议
2411
2461
2412
2462
493
2413
2463
00:26:42,603 --> 00:26:46,104
2414
2464
enums, and especially when you throw in protocols, ( which I
2465
+ (就是我给你说的那个可重要的,但是
2415
2466
2416
2467
494
2417
2468
00:26:46,173 --> 00:26:47,939
2418
2469
told you I was gonna tell you that are very important, but
2470
+ 现在不能给你讲的那个东西,以及泛型)
2419
2471
2420
2472
495
2421
2473
00:26:48,008 --> 00:26:51,843
2422
2474
I cannot explain to you yet, and generics),
2475
+ 编程时,当你开始完全掌握
2423
2476
2424
2477
496
2425
2478
00:26:51,912 --> 00:26:54,579
2426
2479
when you start throwing those things all in there, you can
2480
+ 这些所有的东西时,你就
2427
2481
2428
2482
497
2429
2483
00:26:54,648 --> 00:26:58,216
2430
2484
really do a good job of doing real functional programming.
2485
+ 真的可以把函数式编程做的很好了
2431
2486
2432
2487
498
2433
2488
00:26:58,285 --> 00:27:02,153
0 commit comments