erikamaker / pickaxe

Study notes and exercises from Programming Ruby 3.2
0 stars 0 forks source link

Chapter 1 Notes Feedback #1

Closed ianterrell closed 1 year ago

ianterrell commented 1 year ago

rbenv

rbenv version management. ... I didn't see a version as new as yours though! How'd you get 3.1?

You should see if you're running rbenv:

❯ rbenv --version
rbenv 1.2.0

If I try to install a version I don't have, say the very latest 3.2.1, I get:

❯ rbenv install 3.2.1
ruby-build: definition not found: 3.2.1

See all available versions with `rbenv install --list'.

If the version you need is missing, try upgrading ruby-build:

  brew update && brew upgrade ruby-build

That final command is Mac OS X specific; if you're on Linux you'll likely see something else. But following those instructions I can get new Ruby builds.

It is probably worth it to spend a little time trying to upgrade to 3.2, as it introduces some features the book is almost certainly going to use.

Symbols

Briefly Googling tells me I've misinterpreted it, though. A symbol is generally used to reference a resource.

Symbols are neat. (Many programming languages don't have equivalents, but some do, although they call them different things.)

For the moment, it might be useful just to think of symbols as labels. It can be a label, or it can label data.

Feedback on notes

For instance, in my game's state manager, I could have just had the scene use a boolean check, since that's what it was pretty much doing anyway (except needlessly complicated with a ternary expression MOVES.include?(@@action) ? @@scene = :interact : @@scene = :backdrop. Could have done something simple like @@scene = true/false.

There are always lots of ways to do things. In this case, if there are only two values possible for @@scene, :interact or :backdrop or true/false, the two options are functionality equivalent but not semantically equivalent.

When you write software, are you programming for a computer or are you programming for people?

The best software guides the person reading it into the right understanding. This is true even if you're the only person on the project.

When I see these values of @@scene, I think:

Which is best? I don't know! But don't internalize the rule as "never ternary" or "always booleans when there are only two options". The rule to internalize is, "What best communicates my intention?"

If symbols are right, then MOVES.include?(@@action) ? @@scene = :interact : @@scene = :backdrop would more idiomatically be written:

@@scene = MOVES.include?(@@action) ? :interact : :backdrop`

And if booleans are right, it would be simply

@@scene = MOVES.include?(@@action)

Etc

If you keep going with notes and examples, I would probably try to organize your notes in chapter folders (maybe even section folders within those). The top level directory will probably get messy and hard to find things.

You're using a little bit of markdown in your notes files; if you suffix them .md rather than .txt both GitHub and your editor will know more about them.

e.g.

etc

erikamaker commented 1 year ago

It looks like I am running rbenv, but it wasn't the same version as yours. I'm going to update it. And regardless of what happens, I'll make sure I've got 3.2 running by the end of the day.

@@scene = MOVES.include?(@@action) ? :interact : :backdrop @@scene = MOVES.include?(@@action)

Thank you for showing me more idiomatic ways to write these possibilities. It feels a lot more intuitive because of this feedback. I've been combing over my engine's code for a few days between studying. I'm changing some things around currently to make it more idiomatic, and easier for a human to read. I'm surprised at how much easier it is to add new functionality to it if everything is broken down even just a little bit more. I'm also simplifying the class hierarchy where possible, untangling some christmas tree wires. Having a keener sense of what instance methods vs instance variables do is helping a lot.

If you keep going with notes and examples, I would probably try to organize your notes in chapter folders (maybe even section folders within those). The top level directory will probably get messy and hard to find things.

I updated it this morning to include folders. I tried adding it to github from my local repository with nested folders, but it kept saying an unexpected error occurred and wouldn't let me drag them in. I want to master using git on the command line. I already use the command line primarily, but I find git confusing (and kinda scary?). Do you know any good resources to practice git commands?

I am responding to your feedback a little backwards (I did chapter 2 first). Thanks so much for your feedback, and let me know if I misinterpreted anything you said. I'm starting Chapter 3 today and will let you know when I post the exercises and notes for it later this week.

Have a rad rest of your day! :D

ianterrell commented 1 year ago

I've been combing over my engine's code for a few days between studying.

🎉

I'm changing some things around currently to make it more idiomatic, and easier for a human to read. I'm surprised at how much easier it is to add new functionality to it if everything is broken down even just a little bit more.

This is such a key insight! It's sort of the insight behind all good software organization.

I expect it relates to cognitive science: we have limited short term working memory, but we can use each slot for a "chunk". It's why we organize and remember phone numbers as 3 groups of 3-3-4 numbers rather than trying to remember 10 numbers. 10 things don't fit, but 3 things do, so we have to be clever about how we organize the things.

Properly sizing and scoping methods and classes and modules, etc, builds up "appropriately sized" chunks that we can work with mentally.

Having a keener sense of what instance methods vs instance variables do is helping a lot.

🎉 that's great progress!

I want to master using git on the command line. I already use the command line primarily, but I find git confusing (and kinda scary?). Do you know any good resources to practice git commands?

I used to teach a class on git at a company I worked for, and the first slide in my presentation was Dune's litany against fear.

Unfortunately I don't know any git resources to recommend. I expect GitHub itself has tutorials on setup and usage. The general advice I'd give to start is be sure to set up git to use your editor of choice; if that's vscode google "use vscode for git" and articles will walk you through setup; that way you're not also trying to learn vim at the same time.

It should be straightforward to add, commit, and push. That will get you 80% of the way there.

After you're comfortable there, add in branching and merging, then eventually master interactive rebasing, and finally learn how to write a good commit message.

If you're ever super scared to do something, just use your file browser to copy the whole directory to a backup somewhere first.

Thanks so much for your feedback

You're most welcome!

I'll let you close out any of these issue tickets when you feel like you're done with them.

erikamaker commented 1 year ago

I expect it relates to cognitive science: we have limited short term working memory, but we can use each slot for a "chunk". It's why we organize and remember phone numbers as 3 groups of 3-3-4 numbers rather than trying to remember 10 numbers. 10 things don't fit, but 3 things do, so we have to be clever about how we organize the things.

Right, "chunking" is even the actual technical term I believe! I haven't been a psych student for almost a decade, but I still have a little of that rattling around in here. I have definitely thought about how coding feels like linking chunky puzzle pieces together, on a brainfeel level.

I used to teach a class on git at a company I worked for, and the first slide in my presentation was Dune's litany against fear.

Now that's funny. I'm going to study git a bit tonight, in addition to my flexbox exercises. But for now, I'm continuing Chapter 3. Closing this out for now.