This preview shows page 1. Sign up to view the full content.
Unformatted text preview: or Module), but can be freely passed around and attached to other objects at will. 3. Syntax a. Python has nice functional features such as list comprehension and generators. Ruby doesn’t have these. b. However, Ruby gives you more freedom in how you write your code: parenthesis are optional and blocks aren’t whitespace delimited like they are in Python 4. Speed a. Python generally executes code faster than Ruby 5. Applications a. Python sees use in automating system administration and software development, web application development, analyzing scientific data (with help of numpy, scipy, and matplotlib modules), biostatisics, and teaching introductory computer science and programming. b. Ruby sees use in web application development, and general programming.
Topic 3: Lexical Conventions of Ruby 1. White Space a. Whitespace characters such as spaces and tabs are generally ignored in Ruby code, except when they appear in strings. 2. Line Endings a. Ruby interprets semicolons and newline characters as the ending of a
statement. However, if Ruby encounters operators, such as +, - , or backslash at the 2 end of a line, they indicate the continuation of a statement. b. Be careful when dealing with expressions spanning multiple lines. Remember to always append a ‘+’ at the end of a line if the expression is continued on the line below it. c. Ex: a = ( 4 + 5 ) //prints out 9 d. Ex: a = ( 4 + 5 ) //prints out 5 [NOTE THE DIFFERENCE] The reason this happens is because the expression is treated as a = (4; +5). That is, it evaluates a “4” and then evaluates a “+5” (which then is the resultant value, as it was the last evaluated). e. Ex: a = ( 4 + 5 ) //prints out 9 3. Comments a. Comments are lines of annotation within Ruby code that are ignored at runtime. Comments extend from # to the end of the line. b. Ex: # This is a comment c. Ruby code can also contain embedded documents too. Embedded documents extend from a line beginning with =begin to the next line beginning with -end. =begin and =end must come at the beginning of a line. d. Ex: =begin This is an embedded document. =end 4. Identifiers a. Identifiers are names of variables, constants, and methods b. Ruby distinguishes between identifiers consisting of uppercase characters and those of lowercas...
View Full Document
This document was uploaded on 03/18/2014 for the course EECS 6.170 at MIT.
- Spring '13