-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for automatic type inference (enabled by default). #3
base: main
Are you sure you want to change the base?
Conversation
i think this is too much DWIM-ness that easily leads to confusion. just because i initialize a slot to some value, it doesn't mean that i want to restrict the type of all future values to that of the initform. |
Sure, but then you can always specify |
Would you be OK with merging this if we disable type inference by default? |
@attila-lendvai Friendly ping! :) |
your effort is appreciated, but i don't think this feature belongs into a general-use library. my reasoning:
is this convincing enough? |
Well, allow me to counter-argue! :)
- it badly hurts code readability for not much in return.
True, the code could be better separated into smaller functions.
This is also true to the original code, so we could improve this in all
cases! :)
some lisps ignore the slot's :type declarations while others are
rather strict about it. developing on one lisp may completely hide
errors/warning that only show up as errors when tested on another
lisp.
What I'm proposing is an opt-in feature: if you don't enable it, nothing
changes.
If you enable it, you get stricter typing. If a compiler reports an
error, it's a feature: the type is wrong and should be fixed.
In that sense, the slot `:type` option has the same impact as the other typing
capabilities of the language (e.g. `(declaim (ftype ...))`).
- it also increases code complexity
Isn't this point the same as your first one? If we separate this
function into smaller functions, the code would be much clearer.
and i suspect most people will not use this feature,
or straight out
don't even know that it exists if it's not on by default.
Well, we have a documentation! :)
complexity has a cost that is most often ignored.
- whoever decides to specify the slot's type is better off doing it explicitly
They still can with my proposed change.
To sum up, what this does in practice is _slot type inference_, which
some programmers find useful: it adds some type checking for free
(i.e. without additional code to write).
|
47611d1
to
a101d79
Compare
I've updated the patch to disable type inference by default (it's now an opt-in feature). |
@Ambrevar, don't forget to propagate atlas-engineer/nyxt@c3778a2 to type inference here, as @attila-lendvai, I'd consider one year in an OO-heavy project a good test period for a feature that's otherwise addressing your concerns (given that type inference is off by default now, there's nothing else to worry about)! |
I think it's a very useful default. But could it break existing libraries using compilers that do slot type checking?
(CCL is one of the few that does.)