-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
find
,find_by
,first
now ensures T
, call with trailing ?
for T?
#146
Conversation
@amberframework/granite-orm-contributors it seems like there are a couple different paradigms in Crystal about this. Some people want to use:
and others want:
I personally prefer the latter, but only because of my history with Ruby/Rails. I expect Do we have a paradigm for this in Amber projects? Any other preferences? |
oops. wrong button. |
@robacarp @maiha crystal follows the swift optional paradigm. Swift calls their union type a optional wrapper but the concept is the same. The variable can be either T or Nil. So if you declare something with a type In crystal, I think this request is trying to perform I am ok with this change since it goes hand in hand with the last change we made but I think this should trigger a bigger discussion with the core team if we want to try and handle this stuff or if its better suited in Crystal itself. |
Here is a good article that explains Swift's Optionals. Scroll down to the optional chaining to see how swift handles it. https://hackernoon.com/swift-optionals-explained-simply-e109a4297298 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should trigger a bigger discussion with the core team if we want to try and handle this stuff or if its better suited in Crystal itself.
@drujensen Thanks for the background and the link. I think regardless of what Crystal Lang decides to do in the near or far term, Amber needs to be consistent with this stuff in the API. We are at the stage where we will benefit from setting standards about this sort of thing. For example, does this pattern jive with what’s being written for the params refactor? I honestly haven’t looked yet. But I think the projects should be consistent in its opinions about this type of syntax.
@maiha thank you again for your submission
For the release notes, is this a breaking change? |
@robacarp no, I think the |
First, I know that this and #144 is a very big API change. But, I think that the specification where T is default is convenient from the following three points.
This is a very big change, but I believe it is also a very big improvement. |
@maiha Good points 👍 , what about using |
…`?` for `T?` (amberframework#146)" This reverts commit 719d2e5.
Please review https://github.com/amberframework/granite-orm/pull/171. This fixes the backward compatibility and changes to use the |
This PR make class query methods to ensure a value exist in default like #144.
find
,find_by
,first
returnT
if exists, otherwise raisesNotFound
find?
,find_by?
,first?
returnT?
This removes many
not_nil!
codes as in this commit.Also this prevents newbies from asking