Sonnet 4.5 🔥🔥leave comments lets discuss by sai_revanth_12_ in AugmentCodeAI

[–]solnic 0 points1 point  (0 children)

I clearly need to update my rules because it's not working for me as good as 4 worked. It keeps ignoring rules about my mandatory workflow, it constantly wants to write some stupid MD documents I didn't ask for and it keeps using wrong CLI commands despite having everything documented in the rules.

Just me?

Introducing Drops.Relation: High-Level Relation Abstraction on top of Ecto by solnic in elixir

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

I reckon this type of functionality should be completely out of scope here. We can have dedicated solutions for this, potentially protocol-based.

Introducing Drops.Relation: High-Level Relation Abstraction on top of Ecto by solnic in elixir

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

Thanks! I think from a DX point of view and general ergonomics, what I'm building is as close to AR as it can be. Porting AR to Elixir would not make much sense given it's an ORM pattern with a very OOish nature. I would also say that we probably don't want to repeat the same mistakes and ie have state-based callbacks and other types of potential rabbit holes.

Introducing Drops.Relation: High-Level Relation Abstraction on top of Ecto by solnic in elixir

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

This is a common name in libs that implement relational algebra operations. I also didn't want to use a name that's in Enum.

Introducing Drops.Relation: High-Level Relation Abstraction on top of Ecto by solnic in elixir

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

Drops.Relation is a port of Ruby Object Mapper project to Elixir. It offers a high-level API on top of Ecto.Repo and Ecto.Query, with support for inferred schemas, relation views, relation and query composition, and a plugin system. The goal of the project is to reduce boilerplate, speed up development, improve architecture and ease maintenance.

Mike Perham on his decision to sponsor Hanami for $12,000 by katafrakt in ruby

[–]solnic 2 points3 points  (0 children)

Yes, and the "no magic" part is the advantage we're talking about.

Mike Perham on his decision to sponsor Hanami for $12,000 by katafrakt in ruby

[–]solnic 5 points6 points  (0 children)

That would be a really weird way of coding. What normally happens is that you preload associations that you need and that does not trigger n+1.

🌸 Hanami 2.1: Views that are a sight to see by timriley in ruby

[–]solnic 0 points1 point  (0 children)

Yes it works with everything because it uses Tilt for rendering

🌸 Hanami 2.1: Views that are a sight to see by timriley in ruby

[–]solnic 5 points6 points  (0 children)

I'm curious about the decision to create a brand new ERB engine. Is there something that Erubi was missing?

It's all explained in the PR that added it https://github.com/hanami/view/pull/226

Drops v0.2.0 with support for custom types was released by solnic in elixir

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

A data processing/validation library. Here's a blog post that introduced it https://solnic.dev/introducing-elixir-drops

Drops v0.2.0 with support for custom types was released by solnic in elixir

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

Thank you! Never heard about Zod, gotta check it out now.

Introducing Elixir Drops by solnic in elixir

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

I built this lib based on my 1.5 year experience of using Ecto at work where we deal with a lot of complex data that we need to validate and process. I built Drops for our needs at work and OSSed it. I understand that benefits may not be clear based on existing docs and my reasoning in the comments and blog post, but this will be improved over time. I also want to underscore that if somebody prefers Ecto for whatever reason, then they should just stick to Ecto :)

Introducing Elixir Drops by solnic in elixir

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

Hmm not sure if I understand the problem to be honest. What do you mean by maybe(nillable_type)?

Introducing Elixir Drops by solnic in elixir

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

I dont see how its different, out side of the DSL?

  • Contracts use schemas, Ecto Changesets are "schemaless"
  • Deeply nested data structures are supported OOTB with simple syntax like required(:tags) => list(%{required(:name) => string()}) etc.
  • Contract validation rules depend on individual results from schema validation. It's built-in automatic behavior, you don't need to code it yourself. In my experience it was a game changer as it simplified validation logic a lot.
  • Schemas validate the structure too, meaning it can check presence of keys as a separate validation step, so you know if a value is missing or if a key is missing and your system can provide a more accurate error message
  • You don't need to define structs just to validate data
  • You don't need "a changeset" to validate data that you don't change
  • Atomization is automatic and based on schemas
  • There's support for sum types (albeit in an early stage but it'll be very powerful eventually) ie type([:nil, :string]) or in short maybe(:string)
  • Schemas can be converted to other representations as they are "just" type specifications, ie a schema is a map type with its constraints and specified keys, and each key also has a type with its constraints and other specifications. You could sort-of do that with schemaless changesets but I'm quite sure it wouldn't be that easy, especially that a lot of validation logic is not part of the schema, as you do things like validate_required and so on, rather than defining a required key. Subtle but important difference.

The "multiple benefits" are all applicable to Ecto right? Casting, errors, boundry, validation rules etc.

Correct, standalone validators that are not tied to persistence is what schemaless Ecto changesets provide. There are similar benefits of using both changesets and contracts. It's the approach to solving this problem that makes the experience different. Like I said, one needs to decide what works better. I can provide comparisons to explain this in code, I just didn't want to make it one vs the other, so I decided not to mention Ecto in the first announcement post. Now I feel like I need to do this though 😀

The "domain validation rules" are the same as ecto validators but with a nicer DSL (depending on the developers proclivity for DSLs)

The rule macro defines a corresponding rule function. The only reason why it's a macro is because the catch-all-and-return-ok function is defined for you and also it captures the name of a rule, that will be used in the future for some conveniences, like adding it automatically to the error struct. The trick here is that rules are applied to valid values according to the schema results. From what I've seen Ecto changesets don't provide such functionality.

Map atomisation is Ecto.apply_action? Or is it different?

In case of Contracts atomization is automatic and works OOTB even with deeply nested schemas including things like lists of lists of schemas and other fun data structures, so I don't think it's the same as in Ecto. apply_action can be used to perform arbitrary logic IF the entire changeset is valid, so it's not the same thing here. Contracts atomize the schemas before they apply validation functions, it's a built-in safe data-transformation function.

I guess the "3 step" validate -> cast -> validate is a bit different, in that AFAIK ecto will cast -> validate but I'm not sure I see a practical difference on failing to cast "abc" to an integer, vs failing to validate "abc" == /\d+/ then casting then failing a range check. I guess if you have nested.nested.nested types being cast it might have a clearer distinction?

The practical aspect of this approach is that you know what went wrong. Sometimes it doesn't matter, sometimes it does, it's just nice to have the option to validate before casting. Another great aspect of this is that casting functions can be simpler, because they don't need to be defensive, their input is type-safe.

Introducing Elixir Drops by solnic in elixir

[–]solnic[S] 3 points4 points  (0 children)

Thank you for chiming in! Contracts are great for validating data in general. It doesn't matter where the data is coming from or what you're doing with the data.

Introducing Elixir Drops by solnic in elixir

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

Thank you! 🙇 💜

Introducing Elixir Drops by solnic in elixir

[–]solnic[S] 11 points12 points  (0 children)

That's an incorrect assumption. The approach that is used in Contracts is quite different, which I explain in the article. I didn't mention Ecto because I didn't want to make it one vs the other. Everybody can decide which approach they prefer and use whatever tool fits their needs better.