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.
近日华纳云发布了最新的618返场优惠活动,主要针对旗下的免备案香港云服务器、香港独立服务器、香港高防御服务器等产品,月付6折优惠起,高防御服务器可提供20G DDOS防御,采用E5处理器V4CPU性能,10Mbps独享CN2 GIA高速优质带宽,有需要免备案香港服务器、香港云服务器、香港独立服务器、香港高防御服务器、香港物理服务器的朋友可以尝试一下。华纳云好不好?华纳云怎么样?华纳云服务器怎么样?...
CloudCone是一家成立于2017年的国外VPS主机商,提供独立服务器租用和VPS主机,其中VPS基于KVM架构,多个不同系列,譬如常规VPS、大硬盘VPS等等,数据中心在洛杉矶MC机房。商家2021年Flash Sale活动继续,最低每月1.99美元,支持7天退款到账户,支持使用PayPal或者支付宝付款,先充值后下单的方式。下面列出几款VPS主机配置信息。CPU:1core内存:768MB...
HostKvm又上新了,这次上架了2个线路产品:俄罗斯和香港高防VPS,其中俄罗斯经测试电信CN2线路,而香港高防VPS提供30Gbps攻击防御。HostKvm是一家成立于2013年的国外主机服务商,主要提供基于KVM架构的VPS主机,可选数据中心包括日本、新加坡、韩国、美国、中国香港等多个地区机房,均为国内直连或优化线路,延迟较低,适合建站或者远程办公等。俄罗斯VPSCPU:1core内存:2G...
www.dizhi1.com为你推荐
摩拜超15分钟加钱首次 微信扫 摩拜单车 需要 付压金吗特朗普取消访问丹麦特朗普专机抵达日本安保警力情形如何?刘祚天你们知道21世纪的DJ分为几种类型吗?(答对者重赏)7788k.comwww.k6320.com 大家给我看看这网站是真是假...杰景新特谁给我一个李尔王中的葛罗斯特这个人物的分析?急 ....先谢谢了月神谭求男变女类的变身小说同一ip网站同一个IP不同的30个网站,是不是在一个服务器上呢?51sese.comwww.51xuanh.com这是什么网站是骗人的吗?www.5ff.comhttp://www.940777.com/网站,是不是真的网投六合杨丽晓博客明星的最新博文
jsp虚拟空间 vps安全设置 域名主机基地 拜登买域名批特朗普 edgecast justhost liquidweb 私服服务器 私人服务器 香港托管 iisphpmysql gateone 远程登陆工具 韩国名字大全 南通服务器 后门 国外免费网盘 japanese50m咸熟 中美互联网论坛 百度新闻源申请 更多