2007IEEE.
Personaluseofthismaterialispermitted.
However,permissiontoreprint/republishthismaterialforadvertisingorpromotionalpurposesorforcreatingnewcollectiveworksforresaleorredistributiontoserversorlists,ortoreuseanycopyrightedcomponentofthisworkinotherworksmustbeobtainedfromtheIEEE.
Formoreinformation,pleaseseewww.
ieee.
org/web/publications/rights/index.
html.
www.
computer.
org/softwareDoesBeautifulCodeImplyBeautifulDesignRebeccaJ.
Wirfs-BrockVol.
24,No.
6November/December2007Thismaterialispresentedtoensuretimelydisseminationofscholarlyandtechnicalwork.
Copyrightandallrightsthereinareretainedbyauthorsorbyothercopyrightholders.
Allpersonscopyingthisinformationareexpectedtoadheretothetermsandconstraintsinvokedbyeachauthor'scopyright.
Inmostcases,theseworksmaynotberepostedwithouttheexplicitpermissionofthecopyrightholder.
Intheshortpiece,"TreatingCodeasanEs-say,"YukijiroMatsumoto,chiefdesigneroftheRubyprogramminglanguage,com-pareswritingprogramstowritingessays:AccordingtoMatsumoto,themostimportantquestionacodereaderasksis,"Whatdoesitdo"Ifaprogram'spurposeisn'tclear,itisn'tgood,letalonebeautiful.
And,Matsumotoclaimsbrevityisoneofthemostimportantcon-tributorstobeautifulcode.
Althoughbrevitycancontributetocodebeauty—clarityofpurpose,expressiveuseoftheprogramminglanguage,anddesignelegancealsoplayapart.
ButistheremoretogooddesignthanbeautifulcodeBeautifulcode:Brevityvs.
fluencyToillustratehispointaboutprogrambrevity,Matsumotocontrasted"helloworld"aswritteninRuby(aswellasPerlandPython)—println"HelloWorld"—withtheequivalentJavacode(seefigure1).
TheJavaprogramisbulkierbecauseitin-cludestypeandclassdeclarationsandsyntac-ticelementsforspecifyingaccessrightstomethodsandvariables.
ButI'veseenplentyofJavacodethatreadswell.
ContrastingJavacodewithRubyillustratesthatstronglytypedlanguagescarrymorepro-grammingconstructsandrequirethatmorede-tailsbespecified.
Mostprogrammers,however,quicklyenoughbecomefamiliarwiththecom-plexitiesofthelanguagestheyprograminandcancreatereasonablecodeintheirlanguageofchoice.
Ofcourse,whenIfirstwanderintoanynewprogramminglanguage,myprogramslackelegancebecauseofmylimitedfluencyinthelan-guage.
Fluencydemandspracticeandobserva-tionofotherfluentprogrammerswhocansharewithyoutheircodeandreasonsforprogram-mingthewaytheydo.
Ifyou'rearoundotherswithmoreskillandpracticeinthatlanguage,andyoureadalotofgoodcode,youcanpickupalanguage'snuances.
Thishelpsyoudevelopaprogrammingstylethatfitswithinthelanguage'sconstraintsandexploitsitsstrengths.
AgreatC++programmightnotmatchmySmalltalksenseofaesthetics,butitstillcanbebeautiful.
Beautifuldesign:AddingcontextRecently,IparticipatedinagrandexperimentrunbyMichaelFeathersandEmmanuelGaillottoexplorewhetherso-calledexperts(thoseat-tendingaconference'sdiscoverysession)couldagreeonthemeritsofvariouscodesnippets.
Evenmoreambitiously,FeathersandGaillotwantedtodeterminehowtostructurecodeex-amplestohelpnovicesmorequicklydevelopanintuitivefeelforwhenasolutionisappropriate.
Afterscanningover100smallprogram-Forbothessaysandcomputercode,it'salwaysimportanttolookathoweachoneiswritten.
Eveniftheideaitselfisgood,itwillbedifficulttotransmittothedesiredaudienceifitisdifficulttounderstand.
Thestyleinwhichtheyarewrittenisjustasimportantastheirpurpose.
(BeautifulCode,O'Reilly,2007)18IEEESOFTWAREPublishedbytheIEEEComputerSociety0740-7459/07/$25.
002007IEEEdesignEditor:RebeccaJ.
Wirfs-BrockWirfs-BrockAssociatesrebecca@wirfs-brock.
comDoesBeautifulCodeImplyBeautifulDesignRebeccaJ.
Wirfs-BrockWhatbeautyis,Iknownot,thoughitadherestomanythings.
—AlbrechtDurerNovember/December2007IEEESOFTWARE19DESIGNmingsamplesinanhour,Ifounditin-creasinglydifficulttojudgewhetheranyparticularcodingexamplehadmerit.
SpottingquirkypartsthatwouldmakemegrumbleifIhadtomaintainthecodewasmucheasier.
Codethatlackedexpressivevariableandargu-mentnames,hadhardwiredconstants,hadpoorindentation,orwasfilledwithobscureprogramminghacksre-allyirritatedme.
WhatIfoundmostdisconcerting,however,wasthelackofanydesigncon-textforthecodeIread.
Withoutanymeaningfuldesigndiscussion,Ifeltadrift.
Ididn'tfeelconfidentratingasampleasgoodifIwasn'tcertainwhatitwasdoing.
AndanybadprogramminghabitsIspottedprovedincreasinglyan-noying.
Infact,mostcodesamplesweredevoidofmeaningfulcommentsthatcouldhaveshedsomelightonthede-sign.
Commentsthatwerepresentwerebanalorprivateasides.
Afterawhile,IbeganwonderingwhetherIwasharshwithmyjudgmentssimplybecauseIdidn'tunderstandthecode'spurpose.
OrmaybeIdidn'tlikethecodebecauseIwashopingtospotsomeineffableelegantcodingpatterns.
Thisexperimentconfirmedmybeliefthatoneofthebiggestmythsisthatwell-structuredcodeisself-document-ing.
Ifyoucan'tunderstandthesur-roundingdesigncontext,thepurposeofmostcodesnippetsisn'tobvious.
HabitablecodeRichardGabriel,inPatternsofSoft-ware(Oxford,1996),arguesagainstclarityorbeautyasanoverarchingsoftwaregoalandsuggestsinsteadthatweshouldstriveforhabitability:"thecharacteristicofsourcecodethaten-ablesprogrammers,coders,bug-fixers,andpeoplecomingtothecodelaterinitslifetounderstanditsconstructionandintentionsandtochangeitcom-fortablyandconfidently.
"Habitablecodeprovidesaplacewhere,Gabrielsays,"developerscanfeelathome,[and]placetheirhandsonanyitemwithouthavingtothinkdeeplyaboutwhereitis.
"Hebelievesthatclarityoftenprovestooelusiveandthatmostprogrammersandwrit-ersrarelydemonstratebrilliance.
Hesaysthatintricatelybeautifulcodeof-tenprovestooconstrainingtothemaintainerwhohastosustainallthatbeautyandelegancewhileaddingtoitafteritscreatorhasmovedon.
Havingworkedwithoverlyzealousframeworkdevelopers,Icanattesttosimilarfrustrationswithwhatseemedtomeunnecessarydesignembellishments.
ButI'veseenelegantframeworkstoo.
Theyusuallyaren'toverreachingintheirgoals;rather,theyprovidetheaffor-dancesneededtoextendandusethemwithoutmuchmentaleffort.
Inthechapter"FrameworkforInte-gratedTest:BeautythroughFragility"ofBeautifulCode,FeathersdiscussesthebeautyoftheflexibleyetconciseFITFramework.
Insteadofsupportingmul-tipleformatsfortests,FITsupportsjustHTML.
Eachframeworkclassisrela-tivelysimplebutdesignedtoletsome-oneeasilychangeit.
Allmethodsarepublicandthuschangeable.
FeathersclaimsthatthebeautyofFITisaconse-quenceofitbeingsmall,useful,andun-derstandable,yetopentochange.
That'sanexampleofsimplebeauty,butwhataboutinherentlymorecom-plexsystemsCancomplexsystemsbebeautifulForthelastcoupleofmonths,I'vebeenhelpingasmallteamrefactortheircode.
Theydidn'twanttobetheonlyoneswhocouldsustainit.
Theirsoftwareperformsexceedinglycom-plexcalculations,and,tocompoundtheirdesignchallenge,they'recon-stantlyaddingnewspecialcases.
Noth-Figure1.
"HelloWorld"writteninJava.
publicclassHelloWorld{publicstaticvoidmain(Stringargs[]){System.
out.
println("HelloWorld");}}20IEEESOFTWAREwww.
computer.
org/softwareDESIGNingevergoesaway,andtherequiredprocessingcomplexitykeepsincreas-ing.
Consequently,overtheyears,theircodehadgrownincrediblydenseandtangled.
Andtheyfounditincreasinglydifficulttoaddnewfunctionality.
Anybeauty,ifithadeverbeenpresent,hadbecomeobscured.
Althoughtheycouldn'tsimplifytheirprocessingre-quirements,theyhopedtosimplifyhowtheircodeworked.
First,theycleanedupaclasshierar-chythathadgrownsomewhatarcanebecauseofapreviousdesigner'sstylisticconventionthatresultedinextraneousclasses.
Next,theyreworkedthecodethatcontrolledtheprocessingtoclarifydecisionmakingandmaketheprocess-ingstepsmoreexplicit.
Finally,theytackledanovergrownclass,refactoringitintoacoupleofsmallerservicepro-viderclasseswithcarefullychosen,ex-pressiveclassandmethodnames.
Theresponsibilitiesofeachofthesesimplerclassesweremucheasiertounderstand.
Thedeveloperswerepleasedwiththeirefforts,becausetheyfeltthedesignintentwasmoreevidentintheirrefac-toredcode.
Whiletheresultingredesignwasn'tperfectlybeautiful(westoppedwhentheydeemeditgoodenough),thecodecertainlybecamemorehabitableasaresultofdesignreworkthatmadein-dividualclasses'responsibilitiessimpler,morestraightforward,andconsistent.
And,asanaddedbonus,theyreducedthenumberoflinesofcode.
Yettheirimplementationwasstillverycomplex.
Cancomplexdesignsthatareimple-mentedbycomplexcodeeverbecon-sideredbeautifulMostofusrecognizesimplebeautywhenweseeit.
Butfind-ingbeautyincomplexsystemsseemsmoredifficult.
Ittakestimetoappreci-atethecodebaseandunderstandthedesign.
Andifthereareglimmersofbeautyinplaces,thatbeautifulcodeisn'tnecessarilyunderstoodorappreciatedbythecasualreader.
It'shardtoscalefunctionality,pre-serveadesigner'sintent,andkeepasys-tembeautiful(ifindeediteverwas)whencontinuallyaddingbehaviors.
Butwhenthedesigner'sintentbecomeslost,it'shardtofindmuchbeauty,evenifthere'sabrilliantlycodedmethodortwo.
Aglimmerofdesignbeautyispreservedincomplexsystemswhenresponsibilitiesarereasonablyfactoredamongdesignel-ementsandthebehaviorofanyindivid-ualclassormethodiscomprehensible—givenyouknowthedesigncontext.
IlooktocreatedesignsolutionsthatreflecttheneedsofthosewhowillsustainthecodeafterImoveon.
Agooddesignismorethancleanly,clearly,andconsistentlyexpressedcode.
Beautifulcodeisbeautifulonlyifitpreservesandmakesevidentthede-signer'sintent.
Whatwasonceagooddesignoftendegradesasnewfunction-alityisadded.
Itwouldbegreattothrowcodeawayandrebuilditaneweveryfewyears,butthat'snotpracti-cal.
Instead,weshouldstrivetomakeourcodehabitable.
Ifwedo,we'llpre-servethebeautyandelegancethatdoesexistinourdesignsawhilelonger.
Arecomplex,pragmaticsolutionstocom-plexproblemseverbeautifulIsup-poseitalldependsonwhataestheticsyouapplyinjudgingbeauty.
RebeccaJ.
Wirfs-BrockispresidentofWirfs-BrockAssociates.
Contactheratrebecca@wirfs-brock.
com;www.
wirfs-brock.
com.
搬瓦工和Vultr哪个好?搬瓦工和Vultr都是非常火爆的国外VPS,可以说是国内网友买的最多的两家,那么搬瓦工和Vultr哪个好?如果要选择VPS,首先我们要考虑成本、服务器质量以及产品的售后服务。老玩家都知道目前在国内最受欢迎的国外VPS服务商vultr和搬瓦工口碑都很不错。搬瓦工和Vultr哪个稳定?搬瓦工和Vultr哪个速度快?为了回答这些问题,本文从线路、速度、功能、售后等多方面对比这两...
RAKsmart机房将于7月1日~7月31日推出“年中大促”活动,多重惊喜供您选择;爆款I3-2120仅30美金秒杀、V4新品上市,活动期间5折抢购、爆款产品持续热卖、洛杉矶+硅谷+香港+日本站群恢复销售、G口不限流量产品超低价热卖。美国VPS、日本VPS及香港VPS享全场7折优惠;爆款VPS $ 1.99/月限量秒杀,10台/天,售完即止, VPS 7折优惠码:VPS-TP-disRAKsmar...
WordPress专业外贸企业网站搭建模版,特色专业外贸企业风格 + 自适应网站开发设计 通用流行的外贸企业网站模块 + 更好的SEO搜索优化和收录 自定义多模块的产品展示功能 + 高效实用的后台自定义模块设置!采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器: IE 6+(以及类似360、遨游等基于IE内核的)、Firefox、Google Chrome、Safari、Opera...
www.dizhi1.com为你推荐
原代码什么叫源代码,源代码有什么作用月神谭求男变女类的变身小说www.qq530.com谁能给我一个听歌的网站?777k7.comwww.777tk.com.怎么打不 开haole16.com玛丽外宿中16全集在线观看 玛丽外宿中16qvod快播高清下载www.zjs.com.cn怎么查询我的平安信用卡寄送情况百度指数词百度指数是指,词不管通过什么样的搜索引擎进行搜索,都会被算成百度指数吗?www.kaspersky.com.cn卡巴斯基杀毒软件有免费的吗?稳定版的怎么找?www.ca800.com西门子plc仿真软件有什么功能javlibrary.comImage Library Sell Photos Digital Photos Photo Sharing Photo Restoration Digital Photos Photo Albums
哈尔滨域名注册 游戏服务器租用 域名备案中心 zpanel 国外bt 免费cdn加速 京东云擎 电子邮件服务器 phpmyadmin配置 qq云端 免费智能解析 免费phpmysql空间 免费私人服务器 东莞idc 独享主机 下载速度测试 主机管理系统 德讯 万网主机 zcloud 更多