Skip to content
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

NF: rename model to note type #17598

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Arthur-Milchior
Copy link
Member

As David mentioned recently, Anki don't use "model" anymore, it should not be in the codebase.

There are two places where model should not be replaced. When the variable refers to a model that is not a note type (e.g. a viewModel, the Card Browser's model..). And when the word "model" appears in the API. Indeed we should not break the existing code using the API.

While it may be considered to extend our API, duplicating the Model commands to introduce a NoteType command with the same meaning. And, maybe one day, deprecate the previous API. But I don't think there is even a need to deprecate the API, it does not really lead to confusion.

On top of replacing "model", "models", "Model", "Models", "MODEL", "MODELS", we also rename the variables "m", "m2" and "mm" as those variable where abbreviations for "Model". I renamed some layout, menu,

In one case, the documentation was wrong. It mentioned "model" instead of "template". I thus replaced "model" by "template" in order to correct the documentation.

Note that all the changes were done manually. I used Android-Studio to rename function, variables, values and constant. But I generally avoided the "search and replace" feature which may have led to erroneous update. (Example of exception: m and mm in modelTest

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge change, could it be broken down to PRs in the ~300LOC level, so it's reasonable to review in a sitting?

  • This contains breaking changes to our API
    • Note: Renaming parameters in Kotlin is a breaking change
  • Renaming an activity is a breaking change to our public API
  • addNoteUsingBasicModel might as well be addBasicNote
  • NoteTypeType is not a good name

@@ -199,7 +199,7 @@ class ModelFieldEditor :
}
}
c.setConfirm(confirm)
this@ModelFieldEditor.showDialogFragment(c)
this@NoteTypeFieldEditor.showDialogFragment(c)
Copy link
Member

@david-allison david-allison Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the @ shouldn't be necessary at all

@Suppress("SameParameterValue") front: String,
@Suppress("SameParameterValue") back: String,
): Note = addNoteUsingModelName("Basic (type in the answer)", front, back)
): Note = addNoteUsingNoteTypeName("Basic (type in the answer)", front, back)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addNoteOfType would seem sensible

@lukstbit lukstbit added the Needs Author Reply Waiting for a reply from the original author label Dec 14, 2024
Copy link
Contributor

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Dec 28, 2024
@Arthur-Milchior
Copy link
Member Author

This is a huge change, could it be broken down to PRs in the ~300LOC level, so it's reasonable to review in a sitting?

Not very easily. git reset HEAD^ followed by interactively adding some small part of the code one by one would not work. Any function that is renamed may impact many files. Even changing a variable from m to noteType couldn't easily be added with git add -i, because the lines are changed from val m = getModel() to val noteType = getNoteType().

  • This contains breaking changes to our API

    • Note: Renaming parameters in Kotlin is a breaking change

I first thought that you were referring to ContentProvider. But there I only changed parameters of private function, so I don't except this is breaking anything, given that all calls to those methods are changed simultaneously.
I also changed private constants and local varibles.

Is there any other library we export to other code not contained in the ankidroid repo?

  • Renaming an activity is a breaking change to our public API

I assume you are speaking of ModelFieldFieldEditor. Or are you referring to any other activity I'm missing?
I would not have thought that we were offering this activity to other app. I guess they technically may open it. I can't imagine why an external app would directly offer to open our activity to edit the list of fields of a note type.

  • addNoteUsingBasicModel might as well be addBasicNote

Right. I also did the same change to other functions nearby

  • NoteTypeType is not a good name

The name out of context is certainly bad. TypeOfNoteType would avoid the immediate repetition, but not be consistent with the name of other enums. And the note type contains a field named type, so this is really the name that makes sense.

@github-actions github-actions bot removed the Stale label Dec 29, 2024
Arthur-Milchior added a commit to Arthur-Milchior/Anki-Android that referenced this pull request Dec 29, 2024
And `mm` to noteTypes.

As first part of ankidroid#17598 as David requested the PR to be split.
mikehardy pushed a commit to Arthur-Milchior/Anki-Android that referenced this pull request Dec 30, 2024
And `mm` to noteTypes.

As first part of ankidroid#17598 as David requested the PR to be split.
github-merge-queue bot pushed a commit that referenced this pull request Dec 30, 2024
And `mm` to noteTypes.

As first part of #17598 as David requested the PR to be split.
As David mentioned recently, Anki don't use "model" anymore, it should
not be in the codebase.

There are two places where `model` should not be replaced. When the
variable refers to a model that is not a note type (e.g. a viewModel,
the Card Browser's model..). And when the word "model" appears in the
API. Indeed we should not break the existing code using the API.

While it may be considered to extend our API, duplicating the Model
commands to introduce a NoteType command with the same meaning. And,
maybe one day, deprecate the previous API. But I don't think there is
even a need to deprecate the API, it does not really lead to
confusion.

On top of replacing "model", "models", "Model", "Models", "MODEL",
"MODELS", we also rename the variables "m", "m2" and "mm" as those
variable where abbreviations for "Model". I renamed some layout, menu,

In one case, the documentation was wrong. It mentioned "model" instead
of "template". I thus replaced "model" by "template" in order to
correct the documentation.

Note that all the changes were done manually. I used Android-Studio to
rename function, variables, values and constant. But I generally
avoided the "search and replace" feature which may have led to
erroneous update. (Example of exception: `m` and `mm` in `modelTest`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Has Conflicts Needs Author Reply Waiting for a reply from the original author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants