Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Blocks Blocks Practice Build a Monster Class: Part 1

Andy Saini
Andy Saini
5,287 Points

Although a single quote wrapped string is faster, why does Jason use double quotes wrapped strings in all his videos?

Due to string extrapolation, a single quote wrapped string is supposed to be faster than the double quote wrapped counterpart. Why does Jason use the latter in all the videos?

2 Answers

rdaniels
rdaniels
27,258 Points

True, single quotes for names can suffice. Just as long as you're aware that the possible error might occur, and know how to fix it. : ) Happy coding!

rdaniels
rdaniels
27,258 Points

I always use double quotes. Using single quotes can sometimes return unwanted results, such as when your string has an apostrophe in it. Then you would need to add a back-slash before the apostrophe to tell the computer to ignore/accept the apostrophe. Using double quotes bypasses this problem and the computer interprets the string correctly. A lot of the teachers in these videos only use single quotes, but I see it as a bad practice. I always use double quotes for strings. Hope this helps!

Andy Saini
Andy Saini
5,287 Points

Ok for complex strings, but when using strings such as names, I think single quotes can suffice..