domain specific languages
DESCRIPTION
Design Patterns and methodologies for implementing DSL.TRANSCRIPT
Domain Specific LanguagesDesign Patterns and Methodologies
Lakshan Perera ([email protected])
Faculty of Information TechnologyUniversity of Moratuwa
“Our understanding of the nature of language and the mental processes and structures that underlies its use and acquisition”
Noam ChomskyCartesian Linguistics
What is Domain Specific Language(DSL) ?
“(DSL) is a computer language that'stargeted to a particular kind of problem,rather than a general purpose languagethat's aimed at any kind of softwareproblem.”
Martin Fowler
4th Generation of Programming Languages
Evolution
➣ APT (1957 – 1958)
➣ COBOL, FORTRAN and PERL
➣ Unix Mini-languages (yacc, lex, make)
➣ Lisp (Bottom-up design)
Advantages of using DSL
Direct Involvement of Domain Expert
Improved Productivity
Runtime Efficiency
Considerations
➣ Cost
➣ Language of choice
➣ Complexity of Design
➣ Scope
Developing a DSL
Domain Analysis
Designing DSL
➣ Piggyback
➣ Language Extension
➣ Language Specialization
Implementing DSL
Internal vs External
External DSL
➣ Interpreter
➣ Compiler/application generator
➣ Preprocessor
➣ Extensible compiler or preprocessor
Internal DSL
➣ Method Chaining
➣ Expression Builder
➣ Closures
➣ Literal Collections
➣ Object Scoping
➣ Open Classes
Real World Examples
SELECT books .title, count(*) AS AuthorsFROM booksJOIN book_authors ON books .is bn = book_authors .is bnGROUP BY books .title;
class Category < ActiveRecord::Base has_many :articles validates_presence_of :name validates_uniqueness_of :name def url_param self.name.downcase.gsub(/\s/,'_') endend
employee John Doecompensate 500 dollars for each dealclosed in the past 30 days
compensate 100 dollars for each active dealthat closed more than 365 days ago
compensate 5 percent of gros s profits ifgross profits are greater than 1,000,000dollars
compensate 3 percent of gros s profits ifgross profits are greater than 2,000,000dollars
Future(Everyone is a programmer)
Questions?