Skip to content

Instantly share code, notes, and snippets.

@katiebuilds
Created March 9, 2015 13:19
Show Gist options
  • Save katiebuilds/a6dbded10368426f0936 to your computer and use it in GitHub Desktop.
Save katiebuilds/a6dbded10368426f0936 to your computer and use it in GitHub Desktop.
Detailed Ruby Questions
What is the difference between a hash and an array?
A hash (enclosed with {}) stores information in pairs: there is always a key and a value. In order to pull information out of a hash, you have to call it with its key. Information in the hash is not stored in any particular order. Arrays (enclosed with []) store a set of values in a certain order. You can access a particular value in an array with its index, which is a number that refers to a value's position in the array.
What is the difference between a string and a symbol?
"This is a string." :this_is_a_symbol Both are used to store text. There can't be spaces in a symbol. Often, you can choose which to use, although conventionally, there are certain places where you use one or the other.
When would you use composition instead of inheritance?
You would use composition when you want to define an object's behavior with certain methods, but you don't want it to inherit all the methods of a certain class.
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?
It is better to make many small applications. That way, it is easy for different developers to work on the project at the same time. If something breaks, or if changes need to be made, the entire application is not affected. The usual way that applications talk to each other is with APIs. The data and a lot of the logic are there, in a format that is easily accessible to each application. Then, it is just a matter of creating the user interface on top of that.
Do you think that there are any downsides to Object-Oriented Programming?
There are some. An object can only inherit from one class. I know people grumble about OOP but I don't remember the other reasons...
@katiebuilds
Copy link
Author

both are enumerables....map, .each...can't do .first on a hash, or .keys on an array

symbols are stored differently than strings...symbols all point to the same place, but different strings with the same content are stored in memory again and again. as soon as you use a symbol, it exists in memory, whether you save or store it or not. can do :"Michael Byrd" and store spaces, but you wouldn't want to...can use anything for a hash key and anything for a hash value...(mason: "Awesome", jonathan: "Slightly more awesome", rocky: "No comment"} {1=>"I have one"} can take objects as keys too

inheritance, composition (having an array inside of a class and calling its methods), modules. every class uses inheritance...inheriting from object. composition is wrapping @array = params...in [email protected], let @array do the firsting or reversing, using an instance variable to do what you might do with a class. inheritance is more general. some frowning upon it...just one parent, but you need more flexibility sometimes

smaller applications...modular, can use it again. think in terms of a repository...if it's in one repository, it's one application. stand alone. can't take a controller out of a rails app and put it on a server and have it do anything. self-contained project. besides APIs, some talk by hitting the same database. command line interface...one can call the system and so on. small...security...limit access...encapsulation

large might be better...if you have a tiny app: why break it up? or, if it's a prototype, you just want to see how it works, just whip it out, one thing, see what happens. APIs do add some slowdown. With millions of records, sometimes you need raw speed. but, don't always throw out the baby with the bathwater...maybe make 2 parts work together, and separate everything else. small...service-oriented architecture.

OOP...if you don't use objects, you can write faster code, and use less memory...no extra wrapper stuff and surplus methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment