Monday, February 13, 2012

Donald Knuth answered my question!

In American writing, when quoting something in a sentence, the punctuation comma or period which ends the sentence always goes inside the quotation marks, such as the following:


Whitman famously said "I contain multitudes."


However, I always wondered what if I'm writing a computer science paper and quoting a variable name, putting the punctuation inside the quotation marks seem strange and can appear confusing to the reader -- is the comma or period part of the variable name?

Alas, Donald Knuth answered my question in his Mathematical Writing


The normal style rules for English say that commas and periods should be placed in-side quotation marks, but other punctuation (like colons, semicolons, question marks, exclamation marks) stay outside the quotation marks unless they are part of the quotation. It is generally best to go along with this illogical convention about commas and periods, because it is so well established, except when you are using quotation marks to describe some text as a specific string of symbols. For example,

Good: Always end your program with the word "end".


So my intuition is right, in computer science writing, leave the symbols alone!

Wednesday, February 1, 2012

Comma (,) generates a newline in Ruby "puts"

ruby-1.9.2-p290 :010 > first = "ruby"
=> "ruby"
ruby-1.9.2-p290 :011 > second = "rails"
=> "rails"
ruby-1.9.2-p290 :012 > puts first + second
rubyrails
=> nil
ruby-1.9.2-p290 :013 > puts first, second
ruby
rails
=> nil

Test code inside Rails Console

11:13 AM ~/{application dir}/ $ rails console
Loading development environment (Rails 3.0.5)
ruby-1.9.2-p290 :001 > Gsm::Modem.convert_string_from_ascii_to_char("6900500068006F006E00650d0a")
=> "iPhone"