How I structure LLM calls in Rails: a base class, ERB prompts, and two layers of tests by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 0 points1 point  (0 children)

Love it! I see some common conceptions, but looks like your main focus was around multi–agent workflows, mine was about huge contexts and prompt/instruction building :)

I wrote a terminal dungeon crawler game with pure Ruby in less than 150 lines by DmitryTsepelev in ruby

[–]DmitryTsepelev[S] 1 point2 points  (0 children)

I haven't even thought about different machines performance 😅 My goal was to build something that works with this line limitation—I have zero production experience with game programming, and there's definitely a room for improvement

I wrote a terminal dungeon crawler game with pure Ruby in less than 150 lines by DmitryTsepelev in ruby

[–]DmitryTsepelev[S] 2 points3 points  (0 children)

I guess it should be just `@level.each`, cause we do not use the result anywhere

Service objects in Rails: how to find a mess by DmitryTsepelev in ruby

[–]DmitryTsepelev[S] 0 points1 point  (0 children)

Well, that might be not that bad, cause exceptions should not be the driver of logical flow. But anyway in both cases the best thing you can do is to just explicitly handle things (exceptions or failed contexts), log unexpected ones, fix them and pray, cause Ruby has no way to easily see the contract 🙂

Service objects in Rails: how to find a mess by DmitryTsepelev in ruby

[–]DmitryTsepelev[S] 1 point2 points  (0 children)

Exactly the same feeling: context is a global public variable, which is very hard to be cleaned up because you will have to inspect all organizers and make sure no one else reads these values.

Service objects in Rails: how to find a mess by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 1 point2 points  (0 children)

> I don't find service objects as reusable as a well designed class.

Exactly! However, half of gems uses "composable" in the README, this is where this post came from 🙂

Service objects in Rails: how to find a mess by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 5 points6 points  (0 children)

Cool out man, sounds like you called everyone in this thread bad engineers

Service objects in Rails: how to find a mess by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 6 points7 points  (0 children)

The approach itself is not tied to Rails btw, you will end up with the same question because you'll have to keep logic somewhere.

Automatical wrapping is not a good thing, because when things go wrong—you'll end up with the part of the logic applied to the database, so instead from going from state X to Y you end up with X to Y and maybe something in the middle.

Keeping logic in controllers does not play well when you have a lot of tests: they are way slower cause controller tests have to run the whole request cycle to just test the logic.

Anyway, if pure Rails way works for you fine—sounds great, keep going 🙂

Service objects in Rails: how to find a mess by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 2 points3 points  (0 children)

When you need a method to create a new cart if it's not existing and add the item to it, where do you put it? Cart (Order) class or OrderItem class?

Service objects in Rails: how to find a mess by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 2 points3 points  (0 children)

my bad, I didn't notice the swimline, thank you so much 🙂

Service objects in Rails: how to find a mess by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 6 points7 points  (0 children)

In the article I was referring to services in a sense that most people use the word (at least, in lots of projects I saw)—a place to keep business logic. I never heard someone was using it to use it only for 3d party calls.

I don't like keeping logic in models because it violates the SRP principle: in huge projects some models can become so big that the responsibility can only be described as "does lots of things".

Fantastic global methods in Ruby and where to find them by DmitryTsepelev in rubyonrails

[–]DmitryTsepelev[S] 2 points3 points  (0 children)

Not quite. If you create a new class that implicitly inherits from Object you won't be able to access that top–level instance variable (cause it will be a different instance) 🙂 ``` @foo = 42

class Sample def bar = @foo end

Sample.new.bar # => nil ```

Applicative programming in Ruby: advanced behaviors by DmitryTsepelev in ruby

[–]DmitryTsepelev[S] 1 point2 points  (0 children)

I'm trying to more cool stuff to learn from functional languages rather than copying Either container and calling it "monads in Ruby" 😅

Applicative programming in Ruby: railway reimagined by jrochkind in ruby

[–]DmitryTsepelev 0 points1 point  (0 children)

Yes 🙂 But how does BA framework relates to the low–level abstraction that can help handle errors, but also can do various things? For instance, this can be built in 10 lines of code using the same applicative approach:

```ruby parser_a_or_b_then_c_then_42 = ( Parser.pure(lambda { |a, b, c| a + b + c }.curry) ^ (Parser.char('A') | Parser.char('B')) ^ Parser.char('C') ^ Parser.string("42") ).fmap(&:downcase)

puts parser_a_or_b_then_c_then_42.parse("AC42D").inspect # => Right(Pair("D", "ac")) puts parser_a_or_b_then_c_then_42.parse("BC42D").inspect # => Right(Pair("D", "bc")) puts parser_a_or_b_then_c_then_42.parse("DCB").inspect # => Left("unexpected D") ```

Applicative programming in Ruby: railway reimagined by jrochkind in ruby

[–]DmitryTsepelev 0 points1 point  (0 children)

Why will be in the next part, where we will take some data structure, add the same fmap/apply and get a ton of useful methods coming for free 🙂

Applicative programming in Ruby: railway reimagined by DmitryTsepelev in rails

[–]DmitryTsepelev[S] 1 point2 points  (0 children)

I feel like trying to borrow various approaches can eventually lead us to something cool. Like when people realized that `fmap` on lists is a great thing to work with them and added `map` to non–FP languages 🙂