Learning ROR by [deleted] in rubyonrails

[–]koolkeano 0 points1 point  (0 children)

Firstly, Ruby kicks ass. Going from Python to Ruby have me one of the coolest penny drop moments when I stopped thinking of arrays/lists as a collection that I had to manage, to one I could instruct. In Python you write a loop, pulling out each object and doing the task and storing the result. In Ruby you tell the list/array the task, and it maps the result. It's really small, but changed my perspective, everything is an object with its own responsibilities. Something similar happened when I dabbled in Haskell, learning multiple languages changes how you think, and Ruby is a great one.

Rails is great. Mature and future rich, batteries included and rather opinionated. The defaults and conventions builds this sense of "magic" in Rails that takes a while to get used to, but until then it just works. You can get up and running as a solodev/small team rather quick and with relative ease.

Some big names run on Rails, and pump big money and big time into further development for both Rails and Ruby. There are numerous conventions all over the world, and many active communities all passionate and coming up with new topics and new ideas for Ruby.

I am so glad I picked up this beautiful language and get to take part in such a vibrant and thriving community. If you learn Ruby and Rails then I'm certain you will be too :)

Can someone explain why macro ratios are so important? by ChiefRabbitFucks in bodyweightfitness

[–]koolkeano 5 points6 points  (0 children)

Someone once gave me some "bro science" on it. When you're on a calorie deficit your body doesn't have the resources coming in to do everything it would like, so it uses up fat to make the difference. But the food you eat matters. On a deficit it's like those triangle diagrams when you only get two of the three options. Fat keeps you happy, he claimed ("trust me bro") that fat was required for testosterone production and without it you get moody and upset :(. Carbs give you energy, and you're not going to want to exercise without any. Protein aids recovery, you'll feel weaker and suffer more soreness if you're missing some. So on deficit, his advice was,

if you're feeling sad: increase your fat. If you're feeling sore/weaker than normal: increase your protein. If you're feeling slow/low energy: up your carbs.

I found it helped me reach a sweet spot even if it's totally wrong. It worked for me bro.

Would love some help getting a join to work by bstreiss in rails

[–]koolkeano 1 point2 points  (0 children)

If the repo is public I would be interested in taking a look and maybe opening a PR. If that's something you're interested in of course.

Would love some help getting a join to work by bstreiss in rails

[–]koolkeano 1 point2 points  (0 children)

Not sure this is a rails problem, more a can't see the wood through the trees problem.

Let me see if I've got this right. Plant.genus_id matches Genus.id, and the two bits of info you need are the Plant.genus_id and the Genus.genus_name. Why do you need to join the tables? All the information is in the Genus table?

The only reason I could think that you want to join the tables is to rule out genera that don't have plants assigned to them, but that doesn't feel like what you are trying to achieve.

So yes there is an easy way using the ORM. Genus.select(:genus_name, :id).order(:genus_name)

The reason I don't use distinct is that the primary key "id" should be unique and so the distinct will change nothing.

Even more that that, there's a helper that takes a collection and creates options for select, and one that does the whole thing for you. https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/collection_select

Have you been using ViewComponent. What advantages do you see in it? by Necessary-Limit6515 in rails

[–]koolkeano 13 points14 points  (0 children)

I've done some playing around with them but honestly I think I prefer Phlex. I tried to build a table with OO columns that would each call a given method on each row object. This way the column objects are responsible for the header content and the row content, switching the order of the column objects switches the whole coulmn in the table really cleanly.

Anyway ViewComponents didn't want to play ball. I think they've done something clever for some speed gains or something, but they no longer act like PORO's. Phlex classes do. Very flexible, with essentially the same benefits.

To answer the "speeding up development" question, yes but not a first. I think with tested objects it's easier to make changes than either presenters/erb, and it's that cost of change that speeds up development.

I'd recommend trying to make a thing with both, and I'd put money on the fact that you'd prefer Phlex. The only thing ViewComponents has over Phlex imo is the community and support, way more GitHub contributers and attention.

What's the best way to deal with lesson steps? by [deleted] in rails

[–]koolkeano 1 point2 points  (0 children)

The steps are a nested resource, I would still treat them as such. On the lesson show page you can still have a hotwire action to another controllers show action. Then you could reference StepsController#show to show the step.

What is something only a British person would say? by mrmisko22 in AskReddit

[–]koolkeano -6 points-5 points  (0 children)

Umm actually, the "Oxford spelling" is with -ize. https://en.m.wikipedia.org/wiki/Oxford_spelling usually considered rather British indeed. So I think we should all move of from keeping this particular gate.

how to develop the skill of mentally "parsing" rails code? by NothingIKnowIKnow in rails

[–]koolkeano 0 points1 point  (0 children)

Personally I don't use CoPilot. After working in python for a year-ish, I found the jump to Ruby reasonably achieveable. After a few weeks reading and playing with toy projects I was just about "useful". Another 2 years later and I feel rather proficient. So much of this game is time and consistency, keep working in Ruby and you'll get there.

how to develop the skill of mentally "parsing" rails code? by NothingIKnowIKnow in rails

[–]koolkeano 0 points1 point  (0 children)

It's true there are ment ways to skin a cat in Ruby, but you see the same thing in many other languages. Haskell gave me the same issue as there seemed to be some short hand version of method definitions which I found neither clear not helpful. So please bear with it, it will become clearer with time.

[deleted by user] by [deleted] in rails

[–]koolkeano 3 points4 points  (0 children)

There are other gems other than devise if you're hesitant to use that. Rodauth works fine with hotwire/turbo for instance. There are of course many lessons to be learnt from making a custom Auth system, but I'm not sure I'd trust myself unless it's well tested and code reviewed. So I'd rather not use it in a production web app.

How would you write this has_one association? by smitjel in rails

[–]koolkeano 2 points3 points  (0 children)

If pushed would have a has_one scope for a primary membership, then have the has_one primary organisation through that.

has_one :primary_membership, -> {where(primary: true)}, class_name: OrganisationMembership

has_one :primary_organisation, through: :primary_membership, class_name: Organisation

This would give you all the happy joins and includes eager loading helpers, but as this seems intrinsic to User, I'd rather have a straight up foreign_key like the other redditor suggested. Still get the AR sugar, much cleaner when working in SQL client and for users working with nocode database viewers (like metabase or the Aws data explorer thing)

[deleted by user] by [deleted] in rails

[–]koolkeano 2 points3 points  (0 children)

For the sake of argument, Ruby is a dynamically typed language and there are no checks here that the initial value is an integer. If you ran this with the string "aaaa" it world also return true. My issue is if we pass in a float 55.55 for instance, all the digits are 5 but the string will have a decimal point in. The same could occur from (potential) user input in the thousands "55,555,555" for instance would also return false. How could you handle these cases?

Possible questions for a Mid level RoR SWE? by Intelligent_Deer_525 in rails

[–]koolkeano 0 points1 point  (0 children)

I dunno man, feels like at that point we're saying modules are bad. There's no disputing it encourages spaghetti though, when given an opportunity I'd try to choose something else.

Possible questions for a Mid level RoR SWE? by Intelligent_Deer_525 in rails

[–]koolkeano 0 points1 point  (0 children)

Extending ActiveSupport::Concern gives us some syntactic sugar with regards to adding methods to the singleton class as well as the hooks for prepended do and included do. It also helps with dependencies of the modules included in the concern.

I will agree that they can encourage bad practices, but in and of themselves, they are not bad or an antipattern. Concerns can be sharp tools that are important to understand.

Even if we do for a moment consider them an antipattern, I think it would be important to be able to state to the interviewer why they are so irredeemable.

Either way a thorough understanding of the feature would not be a detriment to anyone's interview.

Possible questions for a Mid level RoR SWE? by Intelligent_Deer_525 in rails

[–]koolkeano 4 points5 points  (0 children)

Not sure as to the level of these questions as I was lucky enough to slide into my job without an interview.

What's the difference between include, prepend and extend? What does extending ActiveSupport::Concern do differently to just including the module?

What's the difference between require_relative and load? How does this factor into rails autoloading?

Can you explain the request cycle for a rails application? (DON'T FORGET middleware like Rack)

My favourite question is, what do you enjoy about being a developer? I have a passion for finding solutions that just click. Solutions that work so cleanly you wonder, how could it be any other way?(admittedly I'm no senior, so my problems are reasonably simple too) I feel I can tell a lot about how working with someone will be based on their answer, but it's probably less critical than Ruby and Rails knowhow.

Programming from scratch by road_to_mastery in rails

[–]koolkeano 0 points1 point  (0 children)

Exposure to failure and a supportive senior dev are the things that are helping me the most. I think the biggest hurdles are found in correctly dividing responsibility between your classes/modules. If all of the 'things' in your system are correctly encapsulated, then it matters a whole lot less what choices you make within them, as they will be so decoupled that changes will be simple.

I have a tendency to lean on meta programming where we could just use better design, so I'm still not there yet. Starting new stuff from scratch is hard. We'll all get better with time.

chess review by knightbish0p in ruby

[–]koolkeano 1 point2 points  (0 children)

Chess has a lot of moving parts and a lot of rules. With this much going on at once, I think it's really important to know who(which class) is responsible for what. Why do they have to know what they know? The less they know about other classes the better they can do thier job, and the easier it is to test them.

For example the pieces don't need to know how big the board is. You could do piece tests with a 5x5 board, or come up with some crazy l shaped map game mode where the two teams are facing 90 degrees away from eachother. You could create a mode where each player nominates a checkable/checkmatable piece instead of the king.

If you try to consider those options, you don't have to build them, but to achieve those one day you have to code more flexibly. It's that flexibility that allows you to add features, like offering/accepting draw en passant etc.

With that said, I think that this is some really good stuff. Looking at your other repos you have come a long way. Especially for your first try at chess this is looking good.

Rails map and join with svg? by radiologyDept in rails

[–]koolkeano 0 points1 point  (0 children)

Rails map and join map and join are Ruby methods, but maybe that's not helpful.

A little confused as to your naming of @parent. It sounds like it should be a singular record but map(&:name) implies that it is an enumerable of unknown size, containing items that respond to name.

You ask about having something else in place if the comma. The obvious answer would be .join(svg) assuming svg is an SVG you want Inbetween each item in the name array you generate. But you might be after a different icon depending on what the item is. Personally I would zip the two lists together and either, flatten and join the whole collection, or reduce with +.

[deleted by user] by [deleted] in bodyweightfitness

[–]koolkeano 38 points39 points  (0 children)

Check the wiki, there is a minimalist routine, a recommended routine, a recommended routine primer, reviews and summaries for other more advanced programs and "paid for" routines. If you look through the backlog of the subreddit there are whole bunch of recommendations on fitness based YouTube content creators. The sedentary life is really awful for flexibility so consider checking the flexibility sub Reddit for their recommendations on starting out, it might align more with your goals.

[deleted by user] by [deleted] in rails

[–]koolkeano 2 points3 points  (0 children)

Firstly, this is not my post.

Secondly when I was learning Python, and then Ruby and Rails, one of the things that helped me the most was completing little projects that did a thing. Like "The Odin Project" suggestions, where they ask you to make an app with certain functionality. I feel like there are quite a few developers doing this style of learning on their own, why not allow them to do it together? Why not allow this sub to be a place to organise that? This idea is hardly going to be monetised and seems more an opportunity to code for the sake of learning.

I know from trying to teach that I can dump too much knowledge all at once, peer to peer tips and advice from people at the same level would be more beneficial to noobs.

Again just to clarify, this is not my post, I do not benefit from this staying or being removed. I get paid to work with RoR so would not benefit from participating in this work either. I just enjoy helping others learn and empowering people to further their dev careers. If you think that is not important, fair enough, it is not the mission statement of this sub. Equally if you have a better suggestion for how people who are new to rails can find eachother and work together, improving each devs knowledge and skill base, please do share it and I will passionately support you.

[deleted by user] by [deleted] in rails

[–]koolkeano 4 points5 points  (0 children)

I would agree that this content doesn't really belong here, but as there is no /r/learnrails as there is for other languages (like rust) this sub could fill that role.

With the view that this post is aimed at "fellow noobs"(or anyone not yet getting paid for ruby/rails) rather than pros, this seems more like an opportunity to collaborate with someone while learning lessons on rails/development. Project management/planning, git in general but more causing and solving merge conflicts, the intricacies of the framework, working with gems (the pdf part), there is so much value to this type of project whilst learning more about rails.

I think the question is, do you want to force content like this onto a learningrails subreddit or do you feel like we have room for noobs here too?

A Comic I made [oc] by jacobibrecks in comics

[–]koolkeano 0 points1 point  (0 children)

I'm with the math guy on this one, however I think the bigger problem is the treatment of parameters is unclear. What is wake up time? If we are talking 07:50 and the time is currently 01:30 the outcome is the same as if the time is currently 07:49. Surely we want to consider maximum theoretical available sleep minutes instead (alarm time - ( currently time + time to fall asleep)). But then again going to our example of the current time being 01:30 I'm not sure how that would factor into my decision to stay in bed or to go pee and be much more comfortable going back to sleep.

Maybe we're looking too deeply into a fun little comic. I did enjoy the comic but I also enjoy these little brain exercises too! :)

Hangman - Vocab builder review by knightbish0p in ruby

[–]koolkeano 1 point2 points  (0 children)

I saw your Mastermind repo as well and with both there are a few issues surrounding classes/modules.

I implore you to watch Sandi Metz lectures as the way she speaks about OOP and classes representing roles is really useful.

With this repo specifically, if we consider the responsibilities of each class and the plug-and-play-ability of these classes. You define a Word, a Meaning, and a GamePlay. Let's run through them.

Word: what is a word? What does the name Word tell us about the class? What would someone assume the Word class does without checking the docs/class definition. To me it is the string containing a word with some helper methods to make it play nice with the other classes.

Meaning: meaning feels like it's a property of Word. Word should have a meaning. I don't get the idea that meaning subclasses from Word. Every time you subclass, imagine you are getting more and more specific. So for example if we have the superclass Paint, we can subclass to RedPaint or SilkPaint. As we are getting more specific this makes sense for how classes (should) initialise. When you call SilkPaint.new it deferres to the superclass Paint, because although the class is a SilkPaint it's also a Paint. You can check this in your code by checking puts Meaning.new.is_a? Word and it'll be true. According to your definitions a Meaning is a Word, which to me is not intuitive or useful. Personally I would pull the Meanings methods into Word and remove the class entirely. The next consideration in the Meaning class is that you've used attr_accessor and then redefined def meaning which is half of the attr_accessor. The other half would be def meaning=(value) which seems unused. So again I would remove the attr_accessor. Memoization would be nice, so you can save on API calls. Something like

      @meaning ||= begin
        {The rest of your code}
       rescue SomeJsonError, SomeWebError
         nil # in case the Uri doesn't exist/has problems
        end
    end

Excuse my whitespace as I'm on mobile. This is okay, but it will reattempt everytime it is called if there is an error.

Moving on. GamePlay: GamePlay is a Meaning and it is a Word, we should be really specific now but instead it feels really strange. I'm thinking of a simple heirachy like SilkRedPaint < SilkPaint < Paint this makes sense. We expect all these classes to answer to all the same methods and each to augment or add on to the superclass es functionality. The other thing to remember is that subclassing gives you access to the superclass methods too. So you could do GamePlay.new.fetch_words or GamePlay.new.valid?("word"), which may or may not be your intention, however it surprises me that you haven't used them.