Michaelwww.dizhi1.com

www.dizhi1.com  时间:2021-04-08  阅读:()
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.

pia云低至20/月,七折美国服务器

Pia云是一家2018的开办的国人商家,原名叫哔哔云,目前整合到了魔方云平台上,商家主要销售VPS服务,采用KVM虚拟架构 ,机房有美国洛杉矶、中国香港和深圳地区,洛杉矶为crea机房,三网回程CN2 GIA,带20G防御,常看我测评的朋友应该知道,一般带防御去程都是骨干线路,香港的线路也是CN2直连大陆,目前商家重新开业,价格非常美丽,性价比较非常高,有需要的朋友可以关注一下。活动方案...

RackNerd新上圣何塞、芝加哥、达拉斯、亚特兰大INTEL系列,$9.49/年

racknerd怎么样?racknerd商家最近促销三款美国便宜vps,最低只需要9.49美元,可以选择美国圣何塞、西雅图、纽约和芝加哥机房。RackNerd是一家成立于2019年的美国高性价比服务器商家,主要从事美国和荷兰数据中心的便宜vps、独立服务器销售!支持中文工单、支持支付宝和微信以及PayPal付款购买!点击直达:racknerd官方网站INTEL系列可选机房:加利福尼亚州圣何塞、芝加...

亚州云-美国Care云服务器,618大带宽美国Care年付云活动服务器,采用KVM架构,支持3天免费无理由退款!

官方网站:点击访问亚州云活动官网活动方案:地区:美国CERA(联通)CPU:1核(可加)内存:1G(可加)硬盘:40G系统盘+20G数据盘架构:KVM流量:无限制带宽:100Mbps(可加)IPv4:1个价格:¥128/年(年付为4折)购买:直达订购链接测试IP:45.145.7.3Tips:不满意三天无理由退回充值账户!地区:枣庄电信高防防御:100GCPU:8核(可加)内存:4G(可加)硬盘:...

www.dizhi1.com为你推荐
哈利波特罗恩升级当爸哈利波特2为啥赫敏只抱哈利波特不抱罗恩。只是握手!!!这……巨星prince去世作者为什么把伏尔泰的逝世说成是巨星陨落百度关键词价格查询百度推广里怎么查指定的关键字参与竞价的价位呢冯媛甑夏如芝是康熙来了的第几期?同ip网站同IP网站9个越来越多,为什么?51sese.com谁有免费电影网站ip在线查询我要用eclipse做个ip在线查询功能,用QQwry数据库,可是我不知道怎么把这个数据库放到我的程序里面去,高手帮忙指点下,小弟在这谢谢了www.mywife.ccmywife哪部最经典ww.66bobo.com这个WWW ̄7222hh ̄com是不是真的不太易开了,换了吗?www.99vv1.comwww.in9.com是什么网站啊?
日本私人vps 过期域名抢注 buyvm 美国主机推荐 webhosting godaddy优惠码 流媒体服务器 国外空间服务商 私有云存储 qingyun 空间出租 柚子舍官网 idc是什么 美国独立日 域名dns 万网主机管理 东莞idc 阿里云官方网站 百度云空间 德讯 更多