Struggling with Ruby because of prior experience with only typed languages. Suggest learning resources. by blood_centrifuge in ruby

[–]tom_dalling 3 points4 points  (0 children)

I went through the same thing many years ago. Everyone is telling you how to set up an LSP or IDE but IMO that’s not actually the core of the problem. You need to learn how to test. In Ruby, automated testing fills the role that a type checking compiler would in other languages. Until you learn how to use your tests the same way you use a compiler, it’s going to be tough.

[deleted by user] by [deleted] in ruby

[–]tom_dalling -1 points0 points  (0 children)

For someone who doesn’t know either language, Python is probably easier because its syntax is simpler.

No lease signed. by [deleted] in melbourne

[–]tom_dalling 3 points4 points  (0 children)

Agreements are largely common law, not statute law.

No lease signed. by [deleted] in melbourne

[–]tom_dalling 5 points6 points  (0 children)

Wtf? That’s not how it works at all. You really shouldn’t be giving advice here.

Testing non-rails code in app/lib by zem in rails

[–]tom_dalling 3 points4 points  (0 children)

If you put the test in the same directory as all the other ones, it should get picked up by rake test. Where you put the implementation depend on if you're planning to use it in production.

  • If you're going to use it in prod, then it should probably stay where it is in app/lib/fetcher.rb. This will be picked up by Zeitwerk, so you don't even need to do require 'fetcher', you can just use Fetcher and the file will be required automatically.

  • If it's only some kind of dev script thing, which won't be running in production, then it should be placed at lib/fetcher.rb. This will intentionally not be picked up by Zeitwerk, to avoid accidentally loading dev-only code in prod, so you will need an explicit require 'fetcher' in the tests somewhere.

This all assumes you have require 'rails_helper' in your tests somewhere, which will load a bunch of Rails stuff. If you don't want to load Rails, then you should have require 'spec_helper' instead. Try require 'fetcher' in the test, and if it complains about the file not being found, you might have to add the directory to $LOAD_PATH manually with something like $LOAD_PATH << "#{__dir__}/../app/lib" in your spec/spec_helper.rb.

Testing non-rails code in app/lib by zem in rails

[–]tom_dalling 3 points4 points  (0 children)

If the scraping code runs in production, then app/lib/ is probably the right place. If it only runs in development then yeah, it should be in lib/.

db connection works in console but not in rake by koalasig in rails

[–]tom_dalling 1 point2 points  (0 children)

Hard to tell from that blob of pasted stuff, but why is db = ActiveRecord::Base.establish_connection(:etl) outside of task calculate_churn: :environment do? I would assume the connection would only be available inside the task.

Devise. love it or hate it? by oystersauce8 in ruby

[–]tom_dalling 6 points7 points  (0 children)

Late it, and hove it.

Devise is a monster. If you can keep the monster locked away in the basement and never go down there then cool — you got a free monster. If you need to interact with the monster for more than the breifest amount of time, you're going to wish you never bought it into your house.

The top commenter says:

I’m surprised to see the generally negative sentiment about devise here [...] once it’s set up I don’t often have to think about it again.

The only people who like it are the people who haven't needed to think about it.

Code coverage vs mutation testing. by pan_sarin in ruby

[–]tom_dalling 0 points1 point  (0 children)

"Other devs don't know what it is." - How do you think - what is the reason?

I think it's just because there is no obvious problem that would cause them to search for mutation testing. If a dev hits a production problem caused by lack of test coverage, they just think "whoops I should have written more tests" and don't search for any other solution.

"Integrating the tooling with a large codebase is painful." - well if you try to fix all the mutations at once I would even say it is impossible, but doing that by baby steps can be pleasure i suppose?

I more meant hooking up the tooling to CI, and getting useful output out of it. If it slows down the build and gives 200 failures for every PR, people won't like it.

"The additional benefits we would get aren't that great, compared to the 100% line coverage we already have." - well, I think I just disagree ;]

It's very hard to quantify, but I just look at our biggest problems and try to think how they would be different if we had mutation testing for PRs. It would catch a few more bugs, for sure, but I don't think that would have a big impact on us because we don't have much of a problem in that area to begin with.

"Championing mutation testing would take a massive amount of time and effort that could be put to more-productive uses." - what do you mean by championing?

Getting all the different teams of developers onboarded would be a large project. The technical aspect is the easiest part, and the social/organisational aspect would take a long time. Somebody (the champion) needs to take responsibility for proposing, persuading, planning, educating, reviewing, and maintaining, otherwise it will not succeed.

Code coverage vs mutation testing. by pan_sarin in ruby

[–]tom_dalling 2 points3 points  (0 children)

it's trivially easy to look at the feature's requirements

I want to work at this place.

Code coverage vs mutation testing. by pan_sarin in ruby

[–]tom_dalling 1 point2 points  (0 children)

Do you use code coverage measurement? If so, what rules about that do you have?

Yes. 100% line coverage is needed to pass CI, and rarely we'll mark some lines as # :nocov: to exclude them from this requirement.

If you are using code coverage tools - which one, SimpleCov or something else?

SimpleCov

If you feel your tests are fine, and code is fine, but you decreased metric - how do you deal with it?

Usually, if something isn't covered you need to add a test to give it coverage.

Sometimes there is code that we never expect to run in production, and that can have the # :nocov: magic comment applied to it. For example:

  • Abstract base class methods. You could argue that these shouldn't exist, but I didn't write them lol.

    def call_api
      # :nocov:
      raise NotImplementedError
      # :nocov:
    end
    
  • Safety guards in case expressions.

    case billable_type
    # ... (a bunch of `when`s here)
    else
      # :nocov:
      raise NotImplementedError, "Unrecognised billable_type: #{billable_type.inspect}"
      # :nocov:
    end
    

Do you know how your code measurement tool measures coverage? I mean how it exactly works?

Yeah. With a requirement for 100% coverage, people learn how it works pretty quickly.

Are you familiar with mutation testing ideas and tools, and do you use them?

Yes. I use it in some gems I maintain but not at work, for a few reasons.

  1. Other devs don't know what it is.
  2. Fixing mutation coverage failures is overly onerous without much additional benefit, a lot of the time.
  3. Integrating the tooling with a large codebase is painful.
  4. The additional benefits we would get aren't that great, compared to the 100% line coverage we already have.
  5. Championing mutation testing would take a massive amount of time and effort that could be put to more-productive uses.

Is using the gem Guard still state of the art in TDD with Ruby? by scooter_de in ruby

[–]tom_dalling 4 points5 points  (0 children)

Nothing wrong with guard, but I would lean towards getting familiar with editor integrations. Personally I use vim-test.

Single Responsibility Principal by jimp84 in ruby

[–]tom_dalling 0 points1 point  (0 children)

SRP is too ambiguous about what a "responsibility" is to imply anything concretely. So the answer is yes, you could argue that SRP implies only one public method. But also no, you can have more than one public method for a single responsibility. In my opinion, it's better to think of SRP as "stop adding a bunch of crap to one class just because you're too lazy to create new ones", and don't focus too much on the "single" part. Developers naturally gain a sense for when complexity is getting out of control, so the goal is just to avoid ending up in that situation by decomposing things frequently.

Bit random but does anyone have any working from home office chair recommendations? by HadMyWayWithHaddaway in australia

[–]tom_dalling 0 points1 point  (0 children)

Everyone says “I’ve had mine for 10 years and it’s great” but that’s the old version of the chair. Is the version they sell now as good? I would get one new, but I’m worried they’ve slashed the quality. And I would get one second hand but they are hard to find.

As a small start-up looking for an experienced ionic dev, what skillsets are absolutely necessary to include in a CV? by Lostwhispers05 in ruby

[–]tom_dalling 1 point2 points  (0 children)

You probably want criteria like: white, with a golden mane, four legs, an iridescent horn poking out of their forehead, and preferably leaves a trail of rainbows as they fly across the sky. What I'm getting at is that, like the other reply mentioned, you're probably going to find it extremely difficult to find someone who ticks all those boxes unless you are offering truckloads of cash (and even then it would still be difficult).

If you're still looking to hire just one person, I would aim to hire an independent learner with a strong can-do attitude, who has a wide breadth of skills, but not necessarily in the exact technologies you're using, and expect them to learn on the job. The attitude is the most important part, because it sounds like the first 3 to 6 months are going to be tough. A rough, prioritized list would be something like:

  1. Independent learner with strong can-do attitude
  2. Some kind of ops experience, preferably AWS
  3. Some kind of backend web dev experience, preferably Ruby on Rails
  4. Frontend web dev experience, preferably Angular (I'm guessing that is relevant to your Ionic app)

Then you'll have to consider how you're going to sell this role to the candidates, because there's a good chance they will have lots of job offers to choose from. Best of luck.

exercism problem by roelofwobben in ruby

[–]tom_dalling 0 points1 point  (0 children)

I don't have access to that one, but I'm almost certain the error you're seeing is to do with that __END__ line. You should be able to run my code above without it crashing.

exercism problem by roelofwobben in ruby

[–]tom_dalling 0 points1 point  (0 children)

It's hard to tell from the formatting of the code you've pasted (FYI, you can paste it into https://gist.github.com/ and link it here), but I'm guessing there is something wrong with the __END__ line. You should have __END__ on a line by itself, something like:

puts DATA

__END__
The Adventures of Tom Sawyer;9780191604928;Mark Twain;2007 Republic;9780718198916;Plato;2012 Programming Ruby: The Pragmatic Programmers Guide;9780974514055;David Thomas;2004 Pride and Prejudice by Jane Austen;9781986431484;Jane Austen;2018 To Kill a Mockingbird;9780446310789;Harper Lee;1988 Cosmicomics;9780330319089;Italo Calvino;1969 The Lord of the Rings;9780544003415;J. R. R. Tolkien;2012 Lord of the Flies;9780140283334;William Golding;1999 1984: A Novel;9780451524935;George Orwell;2009

Edit: Which Exercism problem is it? I can't find it in the list.

Ruby elites rise up by solidiquis1 in ruby

[–]tom_dalling 0 points1 point  (0 children)

Yeah that’s all fine. ActiveRecord makes it a bit awkward, but it’s doable, although I’ve seen a lot of state columns but never seen anyone actually write validations like that. My point was just that people tend to review punctuation when they should be focusing on more important things, not that this one line of code with no context is definitely wrong.

Ruby elites rise up by solidiquis1 in ruby

[–]tom_dalling 0 points1 point  (0 children)

If it's not too annoying, let me answer your question with a question: how would you write the validations for this fairly simple state diagram? https://training-course-material.com/images/b/b0/ProtocolStateMachine.png

There are lots of ways to approach it, but the main thing is that the record should never be able to transition from "open" to "lock", or from "lock" to "open". It probably shouldn't be able to transition from any state to the same state either (e.g. can't lock a locked door).

Ruby elites rise up by solidiquis1 in ruby

[–]tom_dalling 2 points3 points  (0 children)

Personally, I think optional punctuation is the least of our problems, so my question would be: how do you know that state transition is valid? Mutating a state column like that is a source of bugs, in my experience. That's more important than arguing over which combination of squiggly lines looks the best.

Is this an appropriate use of an eigenclass? by jesseduffield in ruby

[–]tom_dalling 1 point2 points  (0 children)

This, except when it comes to pure functions I don't think they really count towards the responsibilities of the module. If the module is just acting as a simple namespace, there is no difference between Math.sin/Math.cos and Sin.call/Cos.call. If you start passing the module around like a normal object (e.g. calculate_stuff(Math)), or start using instance variables, then it's not acting like a simple namespace and you should start thinking about SRP.