Tải bản đầy đủ - 0 (trang)
Chapter 1. Introduction to Computer Science and Media Computation

Chapter 1. Introduction to Computer Science and Media Computation

Tải bản đầy đủ - 0trang

Chapter1.IntroductiontoComputer

ScienceandMediaComputation

1.1 WHATISCOMPUTERSCIENCEABOUT?

1.2 WHATCOMPUTERSUNDERSTAND

1.3 MEDIACOMPUTATION:WHYDIGITIZEMEDIA?

1.4 COMPUTERSCIENCEFOREVERYONE



ChapterLearningObjectives

Toexplainwhatcomputerscienceisaboutandwhatcomputerscientistsare

concernedwith.

Toexplainwhywedigitizemedia.

Toexplainwhyit'svaluabletostudycomputing.

Tousetheconceptofanencoding.

Toexplainwhatcomputersunderstand.







[Page2(continued)]



1.1.WhatisComputerScienceAbout?

Computerscienceisthestudyofprocess:howwedothings,

howwespecifywhatwedo,howwespecifywhatthestuffis

thatyou'reprocessing.Butthat'saprettydrydefinition.Let's

tryametaphoricalone.



ComputerScienceIdea:ComputerScienceisthe

StudyofRecipes(Programs)

They'reaspecialkindofrecipeonethatcanbeexecutedbya

computationaldevice,butthatpointisonlyofimportancetocomputer

scientists.Theimportantpointoverallisthatacomputerscience

programdefinesexactlywhat'stobedoneasshownintherecipein

(Figure1.1).



Ifyou'reabiologistwhowantstodescribehowmigrationworks

orhowDNAreplicates,orifyou'reachemistwhowantsto

explainhowanequilibriumisreachedinareaction,orifyou're

afactorymanagerwhowantstodefineamachine-and-belt

layoutandeventesthowitworksbeforephysicallymoving

heavythingsintoposition,thenbeingabletowriteaprogram

thatspecifiesexactlywhathappens,intermsthatcanbe

completelydefinedandunderstood,isveryuseful.This

exactnessispartofwhycomputershaveradicallychangedso

muchofhowscienceisdoneandunderstood.



[Page3]

Itmaysoundfunnytocallprogramsoralgorithmsarecipe,but

theanalogygoesalongway.Muchofwhatcomputerscientists

studycanbedefinedintermsofrecipes:

Somecomputerscientistsstudyhowrecipesarewritten:

Aretherebetterorworsewaysofdoingsomething?If

you'veeverhadtoseparatewhitesfromyolksineggs,you

knowthatknowingtherightwaytodoitmakesaworldof



difference.Computersciencetheoreticiansworryaboutthe

fastestandshortestrecipes,andtheonesthattakeupthe

leastamountofspace(youcanthinkaboutitascounter

spacetheanalogyworks).Howarecipeworks,completely

apartfromhowit'swritten,iscalledthestudyof

algorithms.Softwareengineersworryabouthowlarge

groupscanputtogetherrecipesthatstillwork.(Therecipe

forsomeprograms,liketheonethatkeepstrackof

Visa/MasterCardrecords,hasliterallymillionsofsteps!)

Othercomputerscientistsstudytheunitsusedinrecipes.

DoesitmatterwhetherarecipeusesmetricorEnglish

measurements?Therecipemayworkineithercase,butif

youhavetoreadtherecipeandyoudon'tknowwhata

poundoracupis,therecipeisalotlessunderstandableto

you.Therearealsounitsthatmakesenseforsometasks

andnotothers,butifyoucanfittheunitstothetaskswell,

youcanexplainyourselfmoreeasilyandgetthingsdone

fasterandavoiderrors.Everwonderwhyshipsatsea

measuretheirspeedinknots?Whynotusethingslike

meterspersecond?Thereareplaces,likeatsea,where

morecommontermsaren'tappropriateordon'tworkas

well.Thestudyofcomputerscienceunitsisreferredtoas

datastructures.Computerscientistswhostudywaysof

keepingtrackoflotsofdatainlotsofdifferentkindsof

unitsarestudyingdatabases.



[Page4]

Canrecipesbewrittenforanything?Aretheresomerecipes

thatcan'tbewritten?Computerscientistsactuallydoknow

thattherearerecipesthatcan'tbewritten.Forexample,

youcan'twritearecipethatcanabsolutelytell,forany

otherrecipe,iftheotherrecipewillactuallywork.How

aboutintelligence?Canwewritearecipethat,whena

computerfollowedit,thecomputerwouldactuallybe



thinking(andhowwouldyoutellifyougotitright)?

Computerscientistsintheory,intelligentsystems,artificial

intelligence,andsystemsworryaboutthingslikethis.

Thereareevencomputerscientistswhoworryabout

whetherpeoplelikewhattherecipesproduce,likethe

restaurantcriticsforthenewspaper.Someoftheseare

humancomputerinterfacespecialistswhoworryabout

whetherpeoplelikehowtherecipeswork(those"recipes"

thatproduceaninterfacethatpeopleuse,likewindows,

buttons,scrollbars,andotherelementsofwhatwethink

aboutasarunningprogram).

Justassomechefsspecializeincertainkindsofrecipes,like

crepesorbarbecue,computerscientistsalsospecializein

specialkindsofrecipes.Computerscientistswhoworkin

graphicsaremostlyconcernedwithrecipesthatproduce

pictures,animations,andevenmovies.Computerscientists

whoworkincomputermusicaremostlyconcernedwith

recipesthatproducesounds(oftenmelodicones,butnot

always).

Stillothercomputerscientistsstudytheemergent

propertiesofrecipes.ThinkabouttheWorldWideWeb.It's

reallyacollectionofmillionsofrecipes(programs)talking

tooneanother.WhywouldonesectionoftheWebget

sloweratsomepoint?It'saphenomenathatemergesfrom

thesemillionsofprograms,certainlynotsomethingthat

wasplanned.That'ssomethingthatnetworkingcomputer

scientistsstudy.What'sreallyamazingisthatthese

emergentproperties(thatthingsjuststarttohappenwhen

youhavemany,manyrecipesinteractingatonce)canalso

beusedtoexplainnon-computationalthings.Forexample,

howantsforageforfoodorhowtermitesmakemoundscan

alsobedescribedassomethingthatjusthappenswhenyou

havelotsoflittleprogramsdoingsomethingsimpleand



interacting.

Therecipemetaphoralsoworksonanotherlevel.Everyone

knowsthatsomethingsinarecipecanbechangedwithout

changingtheresultdramatically.Youcanalwaysincreaseallthe

unitsbyamultiplier(say,double)tomakemore.Youcan

alwaysaddmoregarlicororeganotothespaghettisauce.But

therearesomethingsthatyoucannotchangeinarecipe.Ifthe

recipecallsforbakingpowder,youmaynotsubstitutebaking

soda.Ifyou'resupposedtoboilthedumplingsthensaute'

them,thereverseorderwillprobablynotworkwell(Figure

1.1).

Figure1.1.Acookingrecipetheorderofthestepsis

important.

(Thisitemisdisplayedonpage3intheprintversion)

CHICKENCACCIATORE



3whole,bonedchickenbreasts



1(28oz)canchoppedtomatoes



1mediumonion,chopped



1(15oz)cantomatosauce



1tbspchoppedgarlic



1(6.5oz)canmushrooms



2tbspandlater1/4coliveoil



1(6oz)cantomatopaste



11/2cflour



1/2of(26oz)jarofspaghetti

sauce



1/4cLawry'sseasoningsalt

3tbspItalianseasoning

1bellpepper,chopped(optional)

anycolor



1tspgarlicpowder(optional)



Cutupthechickenintopiecesabout1inchsquare.Sautetheonion

andgarlicuntiltheonionistranslucent.MixtheflourandLawry'ssalt.

Youwantabout1:41:5ratioofseasoningsalttoflourandenoughof

thewholemixturetocoatthechicken.Putthecutupchickenand

seasonedflourinabag,andshaketocoat.Addthecoatedchickento

theonionandgarlic.Stirfrequentlyuntilbrowned.

You'llneedtoaddoiltokeepfromstickingandburning;Isometimes

addupto1/4cupofoliveoil.Addthetomatoes,sauce,mushrooms,

andpaste.(Andtheoptionalpeppers,too.)Stirwell.AddtheItalian

seasoning.Ilikegarlic,soIusuallyaddthegarlicpowder,too.Stir

well.Becauseofalltheflour,thesaucecangettoothick.Iusuallycut



itwiththespaghettisauce,upto1/2jar.Simmer2030minutes.



Similarly,forsoftwarerecipes(programs),thereareusually

thingsyoucaneasilychange:Theactualnamesofthings

(thoughyoushouldchangenamesconsistently),someofthe

constants(numbersthatappearasplainoldnumbers,notas

variables),andmaybeevensomeofthedataranges(sections

ofthedata)beingmanipulated.Buttheorderofthecommands

tothecomputer,however,almostalwayshastostayexactlyas

stated.Aswegoon,you'lllearnwhatcanbechangedsafely,

andwhatcan't.



[Page5]

Computerscientistsspecifytheirprogramswithprogramming

languages(Figure1.2).Differentprogramminglanguagesare

usedfordifferentpurposes.Someofthemarewildlypopular,

likeJavaandVisualBasic.Othersaremoreobscure,like

SqueakandT.Othersaredesignedtomakecomputerscience

ideasveryeasytolearn,likeSchemeorPython,butthefact

thatthey'reeasytolearndoesn'talwaysmakethemvery

popularnorthebestchoiceforexpertsbuildinglargerormore

complicatedprograms.It'sahardbalanceinteachingcomputer

sciencetopickalanguagethatiseasytolearnandispopular

andusefulenoughthatstudentsaremotivatedtolearnit.



Figure1.2.Comparingprogramminglanguages:A

commonsimpleprogrammingtaskistoprintthe

words"Hello,World!"tothescreen.



Python/Jython



defhello():

print"HelloWorld"

Java

publicclassHelloWorld

{

publicstaticvoidmain(String[]args)

{

System.out.println("HelloWorld!");

}

}

C++

#include

main(){

cout<<"HelloWorld!"<
return0;

}

Scheme

(definehelloworld

(lambda()

(display"HelloWorld")

(newline)))



Whydon'tcomputerscientistsjustusenaturalhuman

languages,likeEnglishorSpanish?Theproblemisthatnatural

languagesevolvedthewaythattheydidtoenhance

communicationsbetweenverysmartbeings,humans.Aswe'll

gointomoreinthenextsection,computersareexceptionally

dumb.Theyneedalevelofspecificitythatnaturallanguage

isn'tgoodat.Further,whatwesaytooneanotherinnatural

communicationisnotexactlywhatyou'resayingina

computationalrecipe(program).Whenwasthelasttimeyou

toldsomeonehowavideogamelikeDoomorQuakeorSuper

MarioBrothersworkedinsuchminutedetailthattheycould

actuallyreplicatethegame(say,onpaper)?Englishisn'tgood

forthatkindoftask.



[Page6]



Therearesomanydifferentkindsofprogramminglanguages

becausetherearesomanydifferentkindsofprogramstowrite.

ProgramswrittenintheprogramminglanguageCtendtobe

veryfastandefficient,buttheyalsotendtobehardtoread,

hardtowrite,andrequireunitsthataremoreaboutcomputers

thanaboutbirdmigrationsorDNAorwhateverelseyouwantto

writeyourprogramabout.TheprogramminglanguageLisp

(anditsrelatedlanguageslikeScheme,T,andCommonLisp)is

veryflexibleandiswellsuitedtoexploringhowtowrite

programsthathaveneverbeenwrittenbefore,butLisplooksso

strangecomparedtolanguageslikeCthatmanypeopleavoidit

andthereare(naturalconsequence)fewpeoplewhoknowit.If

youwanttohireahundredprogrammerstoworkonyour

project,you'regoingtofinditeasiertofindahundred

programmerswhoknowapopularlanguagethanalesspopular

onebutthatdoesn'tmeanthatthepopularlanguageisthebest

oneforyourtask!

Theprogramminglanguagethatwe'reusinginthisbookisJava

(http://java.sun.comformoreinformationonJava).Javaisa

verypopularprogramminglanguage.Deltausesittohandleits

website(http://www.delta.com).NASAuseditontheMars

Rover"Spirit"

(http://www.sun.com/aboutsun/media/features/mars.html).It

hasbeenusedintouchscreenkiosksforSuperBowlfans

(http://java.sun.com/features/1998/01/superbowl.html).

Javaisknownforbeingobject-oriented,platformneutral(runs

onmanycomputersandelectronicdevices),robust,andsecure.

AnearlydrawbacktoJavawasthatprogramswritteninJava

oftenhadaslowerexecutiontimethanoneswritteninCor

C++.However,currentJavacompilersandinterpretershave

substantiallyreducedthisproblem.

Let'smakeclearsomeofthetermsthatwe'llbeusinginthis

book.Aprogramisadescriptionofaprocessinaparticular

programminglanguagethatachievessomeresultthatisuseful

tosomeone.Aprogramcouldbesmall(likeonethat



implementsacalculator),orcouldbehuge(liketheprogram

thatyourbankusestotrackallofitsaccounts).Analgorithm

(incontrast)isadescriptionofaprocessapartfromany

programminglanguage.Thesamealgorithmmightbe

implementedinmanydifferentlanguagesinmanydifferent

waysinmanydifferentprogramsbutitwouldallbethesame

processifwe'retalkingaboutthesamealgorithm.



ComputerScienceIdea:ProgramsversusAlgorithms

Aprogramiswritteninaprogramminglanguageandcanbeexecuted

byacomputer.AnalgorithmcanbewritteninEnglishandisa

descriptionofaprocess.Manyprogramscanimplementanalgorithmin

manydifferentprogramminglanguages.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 1. Introduction to Computer Science and Media Computation

Tải bản đầy đủ ngay(0 tr)

×