re: Write a simple but impactful script VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi, Victor! 😊 I'm super ambivalent about this, lol! On one hand, I think the right solution for the problem is the procedural one-liner File.write...
 

Hi Josh!
I have to say, I was really impressed about the time you took to get all those comments together.
It really helps me, it really helps the community reading this comments.

In most sense, I completely agree with almost all your comments

  1. it writes to the wrong filename. That's quite not 100% accurate, as the original excersice (without the bonus) tells: "Then put them into a random order and save the output into a text file." .. as you can see, no file specified.

  2. Agree

  3. Agree! (and consider it a mental note tattooed to my forehead!)

  4. Agree as well, I guess I had the intention to move those two methods down the private section, but never did. Clumsy Victor!

  5. attr_reader vs attr_accessor.. I have always liked the idea to have inmutable objects rather than allowing a change outside of the Object itself. It doesn't feel right. So, unless there's an explicit need to change the object and do recalculation, I'd stick with attr_reader

  6. do_generage "There are only two hard things in Computer Science: cache invalidation and naming things". -- Phil Karlton

  7. Agree

  8. Agree

  9. Agree
    ...

Overall, I really liked your approach.
One thing I could eventually do better, is follow Ruby style guide github.com/bbatsov/ruby-style-guide like single line method definitions, or somethimes using parenthesis and some other times not.

On any case, Thank you Josh! Thank you for your time and for your refactor.

it writes to the wrong filename. That's quite not 100% accurate, as the original excersice (without the bonus) tells: "Then put them into a random order and save the output into a text file." .. as you can see, no file specified.

Ahh, yes, this is fair. The filename was part of the "bonus challenge", which hopefully no one actually did :P

attr_reader vs attr_accessor.. I have always liked the idea to have inmutable objects rather than allowing a change outside of the Object itself. It doesn't feel right. So, unless there's an explicit need to change the object and do recalculation, I'd stick with attr_reader

Yeah, I'm wary of mutability, too (hence moving the arg from process to initialize). The purpose for the accessor here is so that when we initialize it, we can do self.var = ... rather than @var = ..., which I prefer because if the names become misaligned, then it will error where we try to set it, rather than where we do something after accessing it (or worse, if it doesn't error at that point, b/c nil is a valid value, and instead it blows up elsewhere in the program, or we just get really unexpected results). If we were calling the setter more than once, I'd advocate using a local var instead of an instance var. I guess I'm thinking of it as a "one-time-use" setter.

You know, the more I write Ruby, the more I contemplate making my own attr_* methods :P In this case, the way I use it, a better definition would be something like this.

One thing I could eventually do better, is follow Ruby style guide github.com/bbatsov/ruby-style-guide like single line method definitions, or somethimes using parenthesis and some other times not.

I had no issue with any of your syntactic choices (other than the -1 having mismatched whitespace). Looking at mine, there were a few weird ones, I think that's b/c I was inlining things so that my code samples in the comments would be inline, because the markdown processor doesn't seem to nest code blocks inside of lists. But, I initially wrote all my methods as multiline, and it was really just an error from trying to juggle the formatting requirements of the different places the data existed (my editor, the gist, within the comments).

code of conduct - report abuse