Skip to Content
深入理解運算原理|從簡單的機器到無所不能的程式
book

深入理解運算原理|從簡單的機器到無所不能的程式

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
第9章
Toyland 程式設計
程式設計就是要以語法傳達想法給機器。編寫程式時,我們要讓機器在執行程式時,能
完成我們的想法,並且因為我們的程式語言語意可以讓機器瞭解程式每個小片段的意
涵,因而信任我們所使用的程式語言。
但是複雜的電腦程式大於個別陳述式和運算式的總和。只要我們連接眾多小零件,讓它
變成更大且完整的個體,它就能檢查整個程式是不是真的完成了我們原本想要它完成的
工作;這會非常有用。舉例來說,我們可能想要知道它始終會傳回某些結果,或者執行
它會對檔案系統或網路有一定的副作用,又或者它只是沒有包含會讓它因為意料外的輸
入而當機的明顯錯誤。
事實上,我們可能希望我們的程式能有各式各樣的特性,如果我們可以檢查特定程式的
語法來查看它有沒有這些特性,那真的是非常方便,但是我們知道從檢視其原始碼來預
測程式行為的萊斯定理,不一定能給我們正確的答案。想要找出程式將會完成什麼,最
直接的方式當然就是執行它,雖然有時候這種方式的確可行(藉著已知的輸入來執行程
式,並且檢查實際輸出是否一如預期,可以完成許多軟體測試),但是執行程式碼可能
不是可以接受的調查方法,這有幾個原因。
首先,任何有用的程式都可能處理到執行階段才會知道的資訊:與使用者互動的輸入、
傳入作為引數的檔案、讀自網路的資料,等諸如此類的事情。我們當然可以試著以虛構
的輸入來執行程式,進而瞭解它的作用,但這只是讓我們知道程式對這些輸入的行為;
若實際的輸入有所不同,其結果為何?針對所有可能的輸入組合執行程式,通常都不切
實際或不可能,而且以一組特定的輸入測試程式一次,就算那些輸入是真的,也未必能 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JSON實務手冊

JSON實務手冊

Tom Marrs

Publisher Resources

ISBN: 9789864766000