Skip to content

Instantly share code, notes, and snippets.

@jesseract
Last active August 29, 2015 14:16
Show Gist options
  • Save jesseract/640280bfb253033de475 to your computer and use it in GitHub Desktop.
Save jesseract/640280bfb253033de475 to your computer and use it in GitHub Desktop.
3/9_challenge
Detailed Ruby Questions
What is the difference between a hash and an array?
A hash is an unordered collection of key/value pairs.
Arrays are ordered, integer-indexed collections of any object
Both are enumerables
No .first on a hash
No .keys on an array
What is the difference between a string and a symbol?
Quotations for string vs colon for a symbol
Use a symbol to refer to methods
Symbol always points to the same code, only has one reference in memory at a time
The same content can be stored in lots of different strings
Can usually use the two interchangeably
When would you use composition instead of inheritance?
Chains for inheritance are much longer
Composition is like including an array with an instance variable inside. Composition is like wrapping. (odd_array)
Inheritance is more general -- it's more ubiquitous, classic object-oriented approach
Composition is often preferred -- it's a little faster to summon something in an instance variable
Can only have one pairing in ruby inheritance
Big Picture Questions
Is it better to make a single large application, or to make many smaller applications? If you do ever take the second approach, how do you make them talk to each other?
When you have a code base that interacts with and can run on its own, that's an app
Self-contained project that can run without other things being turned on
Some will talk to each other by talking to the same database
File-systems that are shared, or APIs, command line interface
Which is better depends on what you're trying to do
-larger is better if your app is tiny
-smaller is better because of encapsulation, for enterprise-scale apps it would make the logs easier to read and help security
-one large app is faster than dealing with apis and stuff
-making a lot of small apps is called service-oriented architecture
Do you think that there are any downsides to Object-Oriented Programming?
I don't know if this is specific to OOP or to Ruby, but there's a lot of "magic" that happens where something works, but you don't know why or how or how to reproduce it. I think other languages require more specificity and prevent that from happening.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment