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.
收到好多消息,让我聊一下阿里云国际版本,作为一个阿里云死忠粉,之前用的服务器都是阿里云国内版的VPS主机,对于现在火热的阿里云国际版,这段时间了解了下,觉得还是有很多部分可以聊的,毕竟,实名制的服务器规则导致国际版无需实名这一特点被无限放大。以前也写过几篇综合性的阿里云国际版vps的分析,其中有一点得到很多人的认同,那句是阿里云不管国内版还是国际版的IO读写速度实在不敢恭维,相对意义上的,如果在这...
阿里云国际版注册认证教程-免绑卡-免实名买服务器安全、便宜、可靠、良心,支持人民币充值,提供代理折扣简介SunthyCloud成立于2015年,是阿里云国际版正规战略级渠道商,也是阿里云国际版最大的分销商,专业为全球企业客户提供阿里云国际版开户注册、认证、充值等服务,通过SunthyCloud开通阿里云国际版只需要一个邮箱,不需要PayPal信用卡就可以帮你开通、充值、新购、续费阿里云国际版,服务...
百纵科技怎么样?百纵科技国人商家,ISP ICP 电信增值许可证的正规公司,近期上线美国C3机房洛杉矶独立服务器,大带宽/高配置多ip站群服务器。百纵科技拥有专业技术售后团队,机器支持自动化,自助安装系统 重启,开机交付时间 30分钟内交付!美国洛杉矶高防服务器配置特点: 硬件配置高 线路稳定 洛杉矶C3机房等级T4 平价销售,支持免费测试,美国独服适合做站,满意付款。点击进入:百纵科技官方网站地...
www.dizhi1.com为你推荐
云爆发云瀑现象多发生在山地的什么坡?安徽汽车网中国汽车十大品牌杨紫别祝我生日快乐周杰伦的祝我生日快乐这首歌有什么寓意或者是在什么背景下写的甲骨文不满赔偿劳动法员工工作不满一个月辞退赔偿标准www.119mm.comwww.993mm+com精品集!www.javmoo.comjavimdb怎么看抓站工具抓鸡要什么工具?www.ijinshan.com在电脑看港台电视台那个网站最好而又不用钱速度又快555sss.comms真的是500万像素?机器蜘蛛尼尔机械纪元机械蜘蛛怎么过 机械蜘蛛打法攻略解析
域名是什么 二级域名查询 查询ip地址 阿里云os buyvm singlehop 香港主机 mediafire下载工具 鲜果阅读 40g硬盘 web服务器的架设 91vps vip购优惠 免费申请个人网站 搜索引擎提交入口 常州联通宽带 云服务器比较 申请免费空间 学生服务器 存储服务器 更多