-
Notifications
You must be signed in to change notification settings - Fork 76
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
[RFC] On being a poet (or about writing stanzas) #101
Comments
I like it a lot. Makes code much more readable (and less error prone - the whole point of testing, right?). Is there no way to introduce some sort of clever caching? |
I also like your idea @erszcz. I'd like to add one bit from me to the performance issue. We're also using escalus for load tests with amoc. And here we probably would like to better performance also and that's why I'm not sure weather we should switch to the more user-friendly format or not. On the other hand, how difficult would it be to have a parse transform changing the XML at compile time to the record representation? Would it make sense at all? |
For |
I agree, runtime caching sounds easier and for me personally it's the missing puzzle before switching to your approach. |
Most, if not all, of stanzas in
escalus_stanza
and custom stanzas in tests use the following style of building up the Erlang representation - that is, records are composed directly:While this approach is easily understandable for Erlang developers, it requires extra effort to get the XML as it really looks in text format, e.g. in cases where we want to provide snippets for tutorials or communication with client app devs.
However, for some time there's also some support for using Mustache for generating stanzas, which makes the constructors look like this:
This approach is also composable, because of the following form:
escalus_stanza:from_xml/1
andescalus_stanza:from_template/2
differ in the fact that the former doesn't take any parameters to substitute - effectively it's the same asexml:parse/1
. Both return an Erlang/exml
representation of XML. Triple braces{{{some_element}}}
mean that the element passed will be treated as anexml
style XML element to ensure composability.The main benefit is regular represenation of XML in documentation, XEPs, test code and in communication with front-end / client developers. In this case it's pretty easy to just copy and paste the template and turn it into an example for non-Erlangers.
The main disadvantage of this solution is heavily decreased performance due to the templates being parsed first by
mustache
and then byexml
, especially if we use rendered templates to parameterize subsequent templates. Therefore, this method probably should not be used in MongooseIM itself, only in the test code.I wanted to ask about your opinion:
I'm asking these questions now, because I'm going to write support for a new extension and would like to avoid using code that will be frowned upon in the longer run.
The text was updated successfully, but these errors were encountered: