
CMSC330 Midterm I
• Syntax: keywords, formatting expectations, and “grammar” for the language
• Semantics: defines what the program means and does
• Operational semantics: semantics written in math
• Paradigm: chooses which way to do it out of the various options
• Imperative language (procedural/van Neumann): building blocks are procedures and statements
• Functional (applicative) languages: favors immutability and high-order functions
• Immutability: variables are never ref-defined so new variables a function of old ones
• Higher-order functions: passed as arguments and returned as results
• Logic-programming languages (rule-based/constraint-based): program rules constrain possible
results
• Object-oriented languages: programs built from objects
• Dynamic (scripting) languages: rapid prototyping languages for common tasks
• For implementation, two broad ways:
• Compilation: source program translated to another language
• Interpretation: executes each instruction in source program one step at a time
Ruby
• Ruby: object-oriented, dynamically typed language
• No declaration of variables as recognized automatically = implicit declaration
• In command line, to run script
• ruby -w path/file.rb
• implicit vs. explicit
Implicit Explicit
Rapidly type code Would automatically complain about errors in
variable declaration
• static type vs dynamic type
Static type checking (C, Java) Dynamic type checking(Ruby)
Cannot use certain types throws errors
automatically
More possibility for mistakes
• control statements: one that affects which instruction is executed next
• while loops
■Example: