Compilers in Real LifeSoftware Development TimeSoftware MaintenanceLessons from Real LifeSolutions for Real LifeCelebrity EndorsementsCompilers are SoftwareCase Study 1: Search ResultsThe ProblemSolution 1: Spaghetti codeSolution 2: Write it over and overSolution 3: RecipesRecipesA Better WayRFL: Result Format LanguageReport Format LanguageRFL InterpreterSlide 18Running RFLRFL CompilerExpressivenessImplementation PerformanceUsabilityEvolution of RFLCase Study 2: Little ReportsCBL: Cash Balance LanguageError Checking in CBLError Avoidance in CBLCBL ImplementationCBL In PracticeCBL EvaluationBreakCase Study 3: UnrealScriptThe Unreal EngineCustomizing GamesSlide 36UnrealScriptSlide 38Actor StatesNetworkingErrors in UnrealScriptDynamic Error HandlingPerformanceImplementation QualitySlide 46Slide 47Slide 48Slide 49Creating Your Own LanguageGetting StartedCompilers in Real LifeDave Mandelin2 Dec 2004Software Development Time1/6Code1/2Test1/3DesignTest1/2Code1/6Design1/3From The Mythical Man-Month by Fred BrooksCan we do more error checking and less testing?Better yet, can we avoid writing bugs in the first place?Software MaintenanceMaintenance isFixing bugsEnhancing functionalityImproving performanceRefactoring60/60 Rule60% of project cost is maintenance60% of maintenance is enhancements30% of maintenance cost is reading existing codeFrom Facts and Fallacies of Software Engineering by Robert GlassLessons from Real LifeSoftware needs to beReliableMaintainableUnderstandable…especially if it’s any good.Solutions for Real LifeHow can we write reliable, maintainable, understandable software?Design a new language!A language specially designed to handle your problemProgram is short, focused on task“Junk” implementation details hiddenAnd maintainable in one placeError checkingError avoidanceCelebrity EndorsementsCompilers are SoftwareProgramming language tools need to be maintainable, understandable tooCompilers, code analyzers, debuggersWe could design special languages to help implement our languagesToo much for most projectsCan be done, though (PA3, yacc)Focus on simplicity insteadCase Study 1: Search ResultsProject SearchDepartment SearchThe ProblemMany search typesWant same look and feel for allEasy to learn, use, and understandNeed different result formatDifferent titles, linksSolution 1: Spaghetti codeif (type == PROJECT) {link1 = “project.asp?” + name;link2 = “grant.asp?” + id;} else {link1 = “dept.asp?” + id;link2 = null;}…System.out.println(link1);if (type == PROJECT) {System.out.println(link2);}Maybe it works, maybe you get firedUnmaintainableSolution 2: Write it over and overWrite each search page as a separate classMaybe Alice does departments, Bob does projects, …Hard to keep consistent look and feelSolution 3: RecipesWrite each search page as a separate classFollow a fixed recipe each timeExample: recursive descent parsingFollow a fixed recipe for each productionGood strategyBut not the best!RecipesWhat’s good about recipes?Figure out how to do it only onceAvoid bugs if the recipe is correctWhat’s wrong with recipes?Type it in many timesCan type in bugs each timeBoringA Better WayFactor out the repetitionDescribe the differences with a notationPA3: grammar fileSearch: describe result formatImplement the repeated parts with interpreters, compilers, and librariesPA3: parsing engine, table generatorSearch: interpreterRFL: Result Format LanguageColumntitle=“Dept”source_data=“dept”type=STRINGlink=“dept.asp?deptid={ID}”Columntitle=“Name”source_data=”description”type=STRINGReport Format LanguageA configuration language for reportsSyntactic sugar for the recipe codeRaises level of abstractionJava has abstraction features, toomethods, classesSometimes Java is not good enoughPA3: parsing table is unreadableNeed a new languageRFL InterpreterSearch results come from databaseRFL program is an ASTCreated programmatically – no front endRun RFL program on each result tuple340200,”Admin”340300,”Outreach”Columntitle=“Dept”source_data=“dept”type=STRINGlink=“dept.asp?deptid={ID}”Columntitle=“Name”source_data=”description”type=STRINGRFL Interpreter<tr><td><a href=…RFL InterpreterAllowed rapid development of many search pagesOne day, a user sends an email…Site is slow when displaying 5000 search resultsDon’t askWhat can we do?Running RFLInterpreterfor col in columns// Visit each columnObject data = row.getData(col.name);String s = col.format(data);if (col.hasLink()) {col.writeLink(row);}print(s);if (col.hasLink()) {print(“</a>”);}Hand-written// First columndata = row.getData(“name”);s = col.format(data);col.writeLink(row);print(s);print(“</a>”);// Second columndata = row.getData(“title”);s = col.format(data);print(s);RFL Compilera.k.a. code generatorCompile ASTs to HLL code (VBScript)Performs easy optimizationsLoop unrollingConstant propagationEasy because compiler knows which assignments it is generating10x speedupExpressivenessConfiguration languagesLittle languagesDomain-specific languages (DSLs)General-purpose languages (GPLs)Expressiveness,Maintenance EfortRFLVHDL, PostScript, UnrealScriptJava, Perl, Decafmake, PA2 lexer specImplementation PerformanceInterpreterBasic CompilerOptimizing CompilerFancy Optimizing CompilerExecution Speed,Development EfortRFL Interpreterjavac, RFL CompilerPA6, gccPA4UsabilityAuthorHackersProgrammersUsersUsability,Language Design Efortone-of code generatorsJava, Perl, DecafRFL, X configuration scriptsUnrealScriptEvolution of RFLConfig LanguageLittle LanguageDSLGPLInterpreter Compiler Fancy Compilerv0.001InterpreterCompilerCase Study 2: Little ReportsRevenue 60,000Deferred Revenue 14,000Expenses 70,000Profit 4,000CBL: Cash Balance Language‘Profit’=GROUP((REV + DEF) + EXP)‘title’=GROUP(…) is CBL syntaxREVLike a primitive zero-argument functionEvaluated using a database queryWhat happens if we need values from a web site?Need extensibilityCBL has an interface for implementing new primitives by writing a simple classError Checking in CBLDebits and credits are confusingWhich is right, REV – DEF or REV + DEF?“That’s like asking the square root of million. No one will
View Full Document