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

[Code] Placement of parsing and writing logic #888

Closed
tobiasdiez opened this issue Feb 28, 2016 · 2 comments · Fixed by #1453
Closed

[Code] Placement of parsing and writing logic #888

tobiasdiez opened this issue Feb 28, 2016 · 2 comments · Fixed by #1453

Comments

@tobiasdiez
Copy link
Member

Right now parsing and serialization is not handled in a uniform way. (see e.g #875)

Possible designs which come to my mind:

  • The BibParser and BibWriter contain all the logic as private methods.
    • e.g.: BibParser.parseMetaData(String stringyMetadata) and BibWriter.writeMetaData(Metadata)
    • pro: encapsulation of responsibilities
    • contra: rather big classes BibParser and BibWriter, hard to test
  • There are transformer classes which just convert the string to the object and vice-versa.
    • e.g.: MetadataTransformer with static parse(String stringyMetadata) and static write(Metadata) [suggestions for a better name then transformer? ReadWriter?]
    • pro: encapsulation of responsibilities (but weaker as 1), can be reused somewhere else, better testability
    • contra: exposes writing and parsing to the outside world, many new classes
  • The corresponding objects have methods which allow parsing and converting to string.
    • e.g.: Metadata has static parse(String stringyMetadata) [or constructor?] and serialize()
    • pro: encapsulation of responsibilities (but weaker as 1 and 2), can be reused somewhere else, better testability as 1
    • contra: exposes writing and parsing to the outside world, scatters parsing and writing logic

I have no strong opinion about which option we should use (slightly preferring 2), but we should decide for one to handle parsing and writing uniformly.

@simonharrer
Copy link
Contributor

My 2 cents: For the file field, we provided a class that can convert from String to List and back.

To me, the BibWriter and BibParser know how to write bibentries using key/value pairs of strings, and metadata in its general format.

All other information should be part of such converter classes.

But I am not sure, whether this approach is currently feasible for the metadata as its serialization and parsing is highly customized and does not follow a general scheme as the bibtex structure does.

@lenhard
Copy link
Member

lenhard commented Mar 4, 2016

I have been dealing with the serialization of MetaData a lot lately. I can say that it is feasible to extract this logic. Currently, it is quite localized in private methods in the parser and writer and we should be able to move it without too much effort. The difficult part about serializing MetaData is that every tag has very specific serialization conventions which requires a lot of if/elseif structuring. Moreover, I don't think this will require a lot of new classes. After all, for what kind of data do we need such transformers? MetaData, CustomEntryType, what else?

The parser and writer would benefit from a simplifaction, so I am for moving this logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants