w1d2: "Paths that end in trouble are all the same – they only appear different when you don't know where they lead."
What does @stacks[0].empty? && @stacks[1..2].any?(&:empty?) do?
the &:method created the block { |element| element.method }
How can I get out of a long array in pry without killing terminal?
No idea... but the terminal only broke once today.
What is the deal with Array.new(dimension) {Array.new(dimension)} is new executing a block?
This allows the array to take a block and run the block to create every entry, use it for strings and arrays. Numbers are immutable so you don't have to worry so much. Hashes can also take a block but theirs looks like { |h,k| h[k]=[] }
What does it mean to use Standard input? is that like ARGV?
Any input is standard input. $stdin allows you to get input from the command line. It works with like calculators and simple text editors. Usually you will use ARGV, gets, or a file.
This is my first post in markdown. I'm not sure that I 100% know what that means it will do, but I'm hoping practice will help me figure it out.
Today was another good day. The pair worked out really well. We got through every exercise. Jonathan and the TA's have been really helpful at least once a day Jonathan and Constance have done a code review for us each day. We requested someone come over today and Constance came immediately which was really nice. I appreciated it because we needed to have someone look over the code and that allowed us to ask her questions, and left time to fix any code she thought could look better. I was happy that today we heard a lot less about space around operators and newlines in methods. I think a lot of that was the fact that we were pretty obsessive about making sure we thought our code look code when we wrote it.
We wrote Tic Tac Toe, a guessing game, and some IO methods today. I got to the office early and mentioned to Angela that I didn't understand who $stdin worked and she was great and explained how to use it. Jake and I were able to implement it to create a pretty cool comandline Reverse Polish Notation Calculator. It works like a regular calculator, you give it each number and operation and it keeps a running total for you. You can also give it a file through ARGV and it will evaluate an entire equation from the lines in the file.
p>Some of the most important stuff I learned in class.
Any time you are iterating through something and returning true or false early you should use any? or none? for code clarity.
If you are using a method that ends in a question make for a true or false value and you have a method that checks and returns a value you can call that method with a bang bang for the true or false explicit value.
ARGV can be accessed at any level of a program.
After doing the reading I am again seeing a lot of things that I could have done better. I think that I am going to work through refactoring some code when I finish this, then go to sleep early at 11pm as coding all day is making me way tired(I'm very together till about noon, then it gets progressively harder, which seems to be true for most people, I believe there are actually statistics on this, I saw them linked to on Quora a while back, I brought more caffeine today which was definitely helpful). Some of the things that I want to go through old code to work through:
Make data clumps into a class
If you are using the same variables together all the time explicitly connect them by putting them together in a variable (eg. start_date, end_date should be class date_range)
You know when to do this, if one variable is useless without the other
A method should not know what is going on inside another method.
A method should not reach through another method to get the value from a method being called within the second method (see even explaining it is confusing proof you shouldn't do it)
A method should only have access to itself, it's parameters, objects created within it, it's direct component objects, global variables
If altering the internal workings of another method break a method than there is something wrong with the method
Try to use one dot. Do not make longs chains of methods if possible
Classes: Minimize coupling etc
Changing one class should not break another
Feature Envy: A class should not be overly interested in data within another class.
Tell don't ask: ask an object to do something, don't ask the object to give another object the information to manipulate
Classes should be small, then they should be smaller
Classes should have one responsibility
Avoid a lot of if statements
Create parallel classes that allow you to call the same methods so you are not constantly checking if a value is nil (eg. Contact, NullContact)
Avoid a lot of if else statements.
Make code seem simpler than it is.
Most of an object should be private
if you are already changing the code: if fixing the code is hard refator until fixing the code will be easy(this will not be), then do the easy fix
product vs consulting is different.
if you need to make a change refactor the code so the change will be easy. This will be hard, then make the change easy.
What should you refactor?
God Objects - everything interacts with rails usually 2(user, what app is about) don't add code to them
High churn files. if you change it a lot gem churn
code that requires shotgun surgery
p>I always want to just start code over and do it better, but I think I want to practice taking existing code and fixing it since that is real life. I think I want to try writing with explicit code skeletons (comment what is the goal of the method second goal means that we need two methods). I think to start I am going to refactor hanoi, tic-tac-toe, and my personal sudoku program. I want to do fun programs so that I don't get bored because that certainly won't help. I might also find a simple game to build with really explicit skeletons to start to practice thinking about methods, that's a thing right?
What is Struct.new(:start_date, :end_date)