計算機專業外文文獻論文翻譯1_第1頁
計算機專業外文文獻論文翻譯1_第2頁
計算機專業外文文獻論文翻譯1_第3頁
計算機專業外文文獻論文翻譯1_第4頁
計算機專業外文文獻論文翻譯1_第5頁
已閱讀5頁,還剩7頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

外文文獻:EvolvingJavaWithoutChangingtheLanguageIn"TheFeelofJava"JamesGoslingstatedthat:Javaisabluecollarlanguage.It'snotPhDthesismaterialbutalanguageforajob.JavafeelsveryfamiliartomanydifferentprogrammersbecauseIhadaverystrongtendencytopreferthingsthathadbeenusedalotoverthingsthatjustsoundedlikeagoodidea.TheextraordinarysuccessofJavaoffersweighttothenotionthatthiswasasensibleapproach,andifitremainsanimportantgoalforJavatoday,thenitmakessensethatthelanguageshouldcontinuetoevolverelativelyslowly.Inadditiontothis,thefactthatJavaisamature,widelyusedlanguagecausesitsevolutiontobefraughtwithdifficulty.Foronething,eachfeatureaddedtothelanguagecanchangethewayitfeelsinsubtleandoftenunpredictableways,riskingalienatingdeveloperswhohavealreadyadopteditastheirlanguageofchoice.Foranother,afeaturethatmakesperfectsenseonitsownmayinteractwithotherfeaturesofthelanguageinawkwardorunexpectedways.Worse,oncealanguagefeaturehasbeenaddeditisallbutimpossibletoremoveevenifitturnsouttobedetrimentaltothelanguageasawhole.Tojustifyaddinganewfeature,alanguagedesignermustbehighlyconfidentthatitwillbeoflongtermbenefittothelanguageratherthanashorttermorfashionablesolutiontoaproblemthatrapidlybecomesredundant.Tomitigatetheriskalanguagedesignerwilltypicallyexperimentbycreatingaseparatelanguageorbranch,suchasthePizzalanguageusedtoexperimentwithJava'sgenerics,priortotheirimplementation.Theproblemwiththisapproachisthattheaudienceforsuchexperimentsisbothsmallandself-selecting;obviouslytheywillallbeinterestedinlanguagefeatures,andmanymaybeacademicsorresearchers.Anideawhichplayswelltosuchanaudiencemaystillplaybadlywhenitisincorporatedintothemainlanguageandgeneralprogrammersstarttoworkwithit.Togetasenseofthis,considertheclosuresdebatethatbecamesoheatedforJava7.Implementationsforthemainproposals(andsomeothers)havebeenavailableforsometimebutnoconsensushasemerged.InconsequenceSundecidedthatJDK7willnotgetfullclosuressupport.ThecoreargumentcamedowntowhetherJavahadbecomeascomplexasitcouldaffordtobewhengenerics(andinparticularthewildcardsyntax)wereaddedtoJava5;andwhethertheadditionoffullsupportforclosureswasjustifiedwhenJavaalreadyhasamorelimitedformthroughanonymousinnerclasses.Twoimportantusecasesforaddingfullclosuressupportweretosimplifyworkingwiththefork/joinAPIthatisbeingaddedtoJDK7toimprovemulti-coreprogramming,andtohelpwithresourceclean-up.JoshBloch'sARMblockproposal,whichisnowexpectedtobeinJDK7viaProjectCoin,offersanalternativesolutiontothelatterproblem.Dr.CliffClick'sresearchonascalable,non-blockingprogrammingstyleforJavaoffersanalternativeapproachtofork/jointhatmaybemoreappropriateasthenumberofprocessorcoresincreases.Ifthisweretohappen,thentheusesforclosuresinJavamayarguablybetoolimitedtojustifytheirinclusion.Itremainsimportantthoughthataprogramminglanguagecontinuestodevelopatsomelevel.ThisarticlethereforeexaminesthreealternativetechniquesforaddingnewlanguagefeaturestoJavathatdon'trequirechangestothelanguageitself-usingacustomDomainSpecificLanguage,exploitingtheJava6annotationprocessortoaddoptionallanguagefeaturesviaalibrary,andmovingthesyntacticsugarfromthelanguagetotheIDE.Eachoffersthepotentialtoallowawideaudienceofmainstreamdeveloperstoexperimentwiththenewfeaturesoverthemediumterminanon-invasivemanner,andthebestideascanthenfilterdownforinclusioninthecorelanguage.CustomDSLsThemostwidelydiscussedofthethreeistheDomain-SpecificLanguageorDSL.Thereissomedisagreementonexactlywhatthetermmeans,butforthepurposesofthisdiscussionwe'llrefertoitsimplyasalanguagethathasbeencreatedwithanarrowfocustosolveaparticularproblem,ratherthanasageneralpurposelanguagedesignedtosolveeverycomputingproblem.AssuchwewouldexpectaDSLtobenon-Turingcompleteandforthemostpartthisisthecase.Thereareedgecasesofcourse.Postscript,forexample,isaTuringcompletelanguagebutalsoqualifiesasaDSLusingourdefinition.Astheaboveexamplealsoillustrates,theideaofaDSLisnotnew.OtherfamiliarDSLsincludeRegularExpressions,XSLT,Ant,andJSP,allofwhichrequiresomesortofcustomparsertoprocessthem.MartinFowleralsosuggeststhatfluentinterfaces/APIscanbeconsideredasecondtypeofDSL,whichhereferstoasaninternalDSL.HisdefinitionisthataninternalDSLisdevelopeddirectlywithinthehostlanguage.ThiswasacommonpracticeamongstbothLispandSmalltalkprogrammers,andmorerecentlytheRubycommunityhasbeenpopularisingthetechnique.Whilstmanywell-knownDSLsarecommerciallydevelopedandmaintained,someenterprisedevelopmentteamshaveusedthetechniquetocreatealanguagethatallowsthemtorapidlyexploreaspectsoftheirproblemdomain.Itisn'thoweverascommonasitmightbe,perhapsbecauseDSLshaveafairlyintimidatingbarriertoentry.Theteamhastodesignthelanguage,buildtheparserandpossiblyothertoolstosupporttheprogrammingteam,andtraineachnewdeveloperthatjoinstheteamonhowtheDSLworks.HeretheemergenceoftoolstospecificallysupportDSLdevelopmentcouldsignificantlychangethelandscape.IntentionalSoftware'sIntentionalDomainWorkbench,whichhasbeenindevelopmentlongerthanJavahasbeenaround,isthefirstsignificantimplementationofsuchatool.TheprojectstartedlifeatMicrosoftResearch,andDr.CharlesSimonyi's1995paper"TheDeathofComputerLanguages,theBirthofIntentionalProgramming"describeshisvision.In2002SimonyifoundedIntentionalSoftwaretocontinueworkingonhisideasandahugelyimpressivevideodemoofthesystemisavailable.Theproductitselfisat1.0status,butaccessisrestrictedtoverylimitedpartners.Othersoftwarehousesarealsoexploringtheconcepts,amongstthemJetBrains,wellrespectedfortheirIntelliJIDEAJavaIDE,whohaverecentlyreleasedthe1.0versionoftheirMetaProgrammingSystem(MPS).MPSdoesn'tuseaparser,insteadworkingwiththeAbstractSyntaxTree(AST)directly.Itprovidesatext-likeprojectionaleditorwhichallowstheprogrammertomanipulatetheAST,andisusedtowritelanguagesandprograms.Foreachnodeinthetreeatextualprojectioniscreated-astheprogrammerworkswiththeprojection,thechangeisreflectedinthenode.Thisapproachallowsyoutoextendandembedlanguagesinanycombination(oftenreferredtoaslanguagecomposing)promotinglanguagere-use.JetBrainsareusingtheproductinternallyandhaverecentlyreleasedYouTrack,abugtrackingproductdevelopedusingthesystem.TheJava6AnnotationProcessorWhilstDSLsarelesscommoninmoremainstreamlanguagessuchasJavathantheyareinRuby,SmalltalkandLisp,recentdevelopmentsintheJavalanguage,inparticulartheannotationprocessorwhichwasaddedinJava6,offernewpossibilitiesfordeveloperslookingtousetheminJava.TheJPA2.0criteriaAPIthatwillshipaspartofJavaEE6,itselfaDSL,offersanexample.Heretheannotationprocessorbuildsupametamodeltypeforeachpersistentclassintheapplication.WhilstitwouldbeperfectlypossibleforthedevelopertohandcraftthemetamodelinJava,itwouldbebothtediousanderrorprone.Theuseoftheannotationprocessoreliminatesthatpainand,sincetheannotationprocessorisbuiltintoJava6,theapproachrequiresnospecificIDEsupport-anIDEdelegatestotheannotationprocessortriggeredbythecompiler,andthemetadatamodelisgeneratedonthefly.Usingtheannotationprocessoritisalsopossibleforalibrarytoaddanewlanguagefeature.BruceChapman'sprototype"noclosures"proposal,forexample,usesthetechniquetoprovideamechanismforcastingamethodtoaSingleAbstractMethod(SAM)typewhichcompilesontopofJava6.DuringourconversationChapmanpointedoutthattheSAMtypealsosupportsfreevariables,akeyaspectofaclosure:ThemethodbodycandeclareadditionalparametersbeyondthoserequiredfortheSingleAbstractMethodusingthe@As.Additionalannotation.TheseparameterscanhavevaluesboundtothematthepointwhereyouobtainaninstanceoftheSAMtype,andarethenpassedtothemethodeachtimeitisinvoked.ChapmanalsosetuptheRaptprojecttoexploreotherusesofthetechnique,andhasaddedimplementationsfortwolanguagechanges-MultilineStringsandXMLliterals-thatwereconsideredforJDK7butwon'tnowmakeitintothefinalrelease.Javacouldevengetaformofclosuressupportusingthisapproach.Whenaskedaboutthis,Chapmansaid:WearejustfinishingaSwingprojectwhichweuseditfor.Wehavefoundacoupleofminorbugsaroundgenerictypes,onerecentlydiscoveredremainstobefixedbutotherthanthatitseemsquitenicetouse,andnobodyhasbeenwantingtorushbacktouseconventionalanonymousinnerclasses.ProjectLombok,anotherprojectexploringthetheannotationprocessor,pushesthetechniquestillfurther.IneffectLombokusesannotationprocessingasahooktorunaJavaagentthatre-writesvariousjavacinternalsbasedontheannotations.Sinceitismanipulatinginternalclassesitisprobablynotsuitedtoproductionuse(internalclassescanchangeevenbetweenminorreleasesoftheJVM)buttheprojectisaneye-openingexampleofjustwhatcanbedoneusingtheannotationprocessor,including:Supportforpropertiesusingapairof@Getterand/or@Setterannotationswithvaryingaccesslevels,e.g.@Setter(AccessLevel.PROTECTED)privateStringname;The@EqualsAndHashCodeannotation,whichgenerateshashCode()andequals()implementationsfromthefieldsofyourobjectThe@ToStringannotation,whichgeneratesanimplementationofthetoString()methodThe@datamethod,whichisequivalenttocombining@ToString,@EqualsAndHashCode,@Getteronallfields,and@Setteronallnon-finalfieldsalongwithaconstructortoinitializeyourfinalfieldsOtherlanguageexperimentation,suchasremovingcheckedexceptionsfromJava,canalsobedoneusingthisapproach.Whilsttheannotationprocessortechniqueopensupawelcomenewroutetolanguageexperimentation,careneedstobetakenthatthegeneratedcodecanbeeasilyreadbydevelopers,notjustbythemachine.Chapmanmadeanumberofsuggestionsduringourconversation:Generatesourcecodenotbytecode,andpayattentiontoformatting(indentingespecially)inthegeneratedcode.Thecompilerwon'tcarewhetheritisallononelineornot,butyouruserswill.Ievensometimesaddcommentsandjavadocinthesourcecodegeneratedbymyannotationprocessorswhereappropriate.HopefullyifthetechniquebecomesmoreprevalentIDEswillalsomakeiteasiertoviewthecodethatistobegeneratedatcompiletime.SyntacticSugarintheIDEBruceChapmanalsotouchesonourthirdtechnique-movingthesyntacticsugarfromthelanguagetotheIDE-inhisblogandheelaboratedonhisideasduringourconversation.ItisalreadyroutineforJavaIDEstocreateportionsofboilerplatecodeforyousuchasthegettersandsettersofaclass,butIDEdevelopersarebeginningtopushtheconceptfurther.JetBrains'IntelliJ9offersatersecodeblocksyntaxforinnerclassessimilartoaclosure,whichadevelopercanalsotype.Actinglikecodefolds,thesecanthenbeexpandedintothefullanonymousinnerclasseswhichthecompilerworkswith-thisallowsdeveloperswhoprefertostickwiththestandardanonymousinnerclasssyntaxtodoso.Asimilarplug-inforEclipsealsoexists.Thekeypointhereisthatthe"alternate"syntaxisjustaviewoftheactualcodewhichthecompilerandanysourcemanagementtoolscontinuetoworkwith.Thusthedevelopershouldbeabletoswitchviewsbetweeneitherform(likeexpandingorcollapsingacodefold),andanyonewithoutaccesstothedefinitionofthesugarjustseesthenormalJavacode.Chapmanwrites:Therearemanydetailstoworkoutinordertomakethiseasilyaccessible,butlongtermIseedevelopersrelativelyeasilydefiningatwowaysugaring/desugaringtransformation(jackpotisagoodstartforhowthismightbedone),tryingthemout,evolvingthemandsharingthegoodoneswithcolleaguesandthecommunity.Theadvantagesofthisarealmostthesameasforalanguagechange,withoutthedisadvantages.Theverybestcouldbecomeubiquitousandthenformthebasisofanactuallanguagechangeifnecessarytogetridofanyremaining"noise"notpossiblewiththisapproach.Sincesyntacticsugarhastomaptoanother(moreverbose)languagefeatureitcannotoffercompleteclosuresupport;therearesomefeaturesofBGGAclosuresforexamplethatcannotbemappedtoanonymousinnerclasses,andsotheycouldn'tbeimplementedthroughthisapproach.Neverthelesstheideaopensupthepossibilityofhavingvariousnewsyntaxesforrepresentinganonymousinnerclasses,similartoBGGAsyntaxorFCMsyntax,andallowingdeveloperstopickthesyntaxtheywanttoworkwith.Otherlanguagefeatures,suchasthenull-safeElvisoperator,couldcertainlybedonethisway.ToexperimentfurtherwiththeideathisNetBeansmodulealsodevelopedbyChapman,iswhathedescribesasa"barelyfunctional"prototypeforPropertiesusingthisapproach.ConclusionInlanguagedevelopmentthereisalwaysatrade-offbetweenstabilityandprogress.Theadvantagethatallofthesetechniquesbringisthattheydon'taffecttheplatformorthelanguage.Inconsequencetheyaremoretoleranttomistakesandarethereforemoreconducivetorapidandradicalexperimentation.Withdevelopersfreelyabletoexperimentweshouldbegintoseemorepeopleseparatelytacklingthepoorsignaltonoiseratioofsomecommonboilerplatesuchastheanonymousinnerclasssyntax,mixingandevolvingtheseideastosomeoptimumformthataddsthemostvalueinthemostcases.ItwillbefascinatingtoseehowdevelopersusethesedifferentapproachestopushtheJavaplatforminnewdirections.中文譯文:不改變語言的前提下推進Java演進JamesGosling在“TheFeelofJava”中說過:Java是一種藍領語言,它并不是博士的論文材料而是可以完成工作上的語言。很多不同的程序員都非常熟悉Java,因為我有一種趨勢去選擇普及的東西,這是一個不錯的選擇。Java的這種成功證明了它的這種方法是正確的,如果Java今天仍然以這個為目標,那么它的語言演進將變得很緩慢。Java作為一個成熟,使用廣泛的語言也將導致其演進過程充滿了困難。一方面,每個特性添加到語言中都有可能造成不可預知到后果,這么做會疏遠那些熟悉)@丫@的人,另一方面,本身很完美的特性可能在與其他特性進行交互時產生未知的影響。更糟的是,一旦增加了某個語言特性,幾乎就不可能再將它移除,即使這個特性會對整個語言產生危害也沒辦法。語言設計者為了證明某個特性是正確的,應該從長遠的角度來考慮,不應該在短期內解決這個問題,而之后就變成了多余的。為了降低風險,語言設計者一般會創建單獨的一種語言或者分支來進行試驗,比如Pizza語言就是在完成前用來測試Java泛型的。這種方式的問題在于試驗的參與者是比較少的人群,并且是自愿的。他們對語言特性很感興趣,很多人是學者或者研究員。但是,在普通的程序員使用這些特性時,那些學者或是研究員認為很好的特性可能變得很糟。為了感受一下這種情況,請考慮Java7閉包特性的激烈爭論。很長時間以來有人在提案中給出了閉包的實現,但最終卻還是沒有達成共識。然后,$口口公司不在JDK7中添加完整的閉包支持。爭論的焦點轉向為添加泛型會不會導致Java變得越來越復雜,在Java中已經通過匿名內部類部分實現該功能的情況下,完整閉包還是正確的嗎。需要完整閉包支持的是簡化fork/joinAPI(添加到了JDK7中以改進多核編程)的使用以及清理資源。JoshBloch的ARMblock提案對第二個問題給出了另一種解決方案。CliffClick博士在面向Java的可擴展,非阻塞變成風格的研究中給出了關于fork/join的另一種方案,這種方案隨著核心處理器的不斷增加看起來也很合理,如果這種成為可能的話,那么Java中使用閉包的地方將會很少了,語言就不需要提供這個特性了。雖然這樣,但是對編程語言來說。不斷的平穩發展還是非常重要的。因此下面講了3種技術,向Java中增加新的語言特性而又不改變語言本身,他們是客戶化領域特定語言(DSL)、Java6的注解處理器(用庫來添加可選擇的語言特性)以及將語法糖從語言般向IDE。每個技術都能讓主流開發者用非侵入方式體驗這些新特性,好的想法可以融合到語言核心當中。客戶化DSL在這3個技術中,討論最多的還是特定領域語言或者說是DSL。關于DSL的定義有很多爭議,但是為了方便我們討論,我們把它當作一個簡單的語言而不是一個解決計算機問題的語言。那樣DSL就不是圖靈完備的了。當然也有邊緣情況,例如,Postscript是圖靈完備的語言但是也可以作為DSL來定義。正如上面的例子,一個DSL也不是新的想法。其他熟悉的DSL包括正則表達式,XSLT,Ant和JSP,所有這樣都需要一個定制的分析器排序,來處理他們。MartinFowler也指出interfaces/API可以被認為是一個第二種類型的內部DSL。他認為一個內部DSL應該被開發語言直接開發,這是Lisp和Smalltalk程序員普遍的做法,以及最近Ruby社區也一直致力推廣這一技術。雖然很多知名的DSL是為了商業上的開發和維護,但是一些企業已經使用這項技術來創造一種語言,但還是小部分人,可能是DSL門檻較高吧。這個小組必須設計語言,建立解析器和其他可能的工具來支持這個程序,以及培養一個新加入者如何用DSL。這是出現來可以支持DSL開發的工具,這大大的改變了局面。IntentionalSoftware所開發的IntentionalDomainWorkbench比Java還要久,它首先實現了該工具的功能。該項目開始于微軟研究院,CharlesSimonyi博士在1995年所發表的論文“TheDeathofComputerLanguages,theBirthofIntentionalProgramming”中描繪了其愿景。2002年,Simonyi創建了IntentionalSoftware以繼續實現他的想法,一個巨大的系統中獲得的令人印象深刻的視頻。該產品現在是1.0版本,但訪問權僅限于有限合伙人。其他的一些公司也開始研究這項技術,其中包括一IntrelliJIEDAJavaIDE而出名的JetBrains,它最近發布了MetaProgrammingSystem(MPS)1.0版。MPS并沒有使用分析器,而是直接使用AbstactSyntaxTree(AST)。他提供了一個可以允許程序員來操作的AST以及可以編寫語言和程序的文本編輯器。當程序員使用投影時就會為樹上的每個借點創建一個文本,這樣變化就會反映到節點當中。開發者能通過這樣的方法開任意組合。JetBrains正在內部使用這個產品,最近發布了bug追蹤產品YouTrack就是使用該系統開發的。Java6注解處理器在很多主流語言像Java中,DSL遠不如RubySmalltalk和Lisp普遍,最近在Java語言中出現的變化特別是Java6中新增的注解處理器為開發者提供了新的機遇去使用Java。JavaEE6中的JPA2.0,某些API本身就是DSL,這就是一個例子。這種處理器會在應用中建立一個持久的元模型。雖然開發者可以很好的用手工去處理Java元模型,但是它會很枯燥無味而且容易出現錯誤。注解處理器的使用解決了這種痛苦,因為這種處理器是建立在Java內部,而且不需要特殊的IDE支持一IDE會代理處理器自己建立元模型。使用這種注解處理器也可以為程序庫增加新的語言特性。舉個例子來說,BruceChapman的原型“noclosures”提案就是憑借這種技術將方法轉換為SingleAbstractMethod(SAM)類型,然后在Java6上編譯。在我們的會話中Chapman指

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論