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

add ctor specialization #23

Merged
merged 9 commits into from
Jan 17, 2023
Merged

Conversation

advasileva
Copy link
Contributor

@advasileva advasileva commented Jan 14, 2023

Implementation of #22

Test case

Now the following test passes:

[] > first
  [] > boom
    QQ
    .io
    .stdout > @
      "First!\n"

[] > second
  [] > boom
    QQ
    .io
    .stdout > @
      "Second!\n"

[x] > foo
  x
  .boom > @

[] > app
  seq > @
    foo
      first
    foo
      second

transforms to

[] > first
  [] > boom
    QQ
    .io
    .stdout > @
      "First!\n"

[] > second
  [] > boom
    QQ
    .io
    .stdout > @
      "Second!\n"

[x] > foo
  x
  .boom > @

[] > app
  seq > @
    foo_spec_x_first
      first
    foo_spec_x_second
      second

[x] > foo_spec_x_first
  x
  .boom > @

[x] > foo_spec_x_second
  x
  .boom > @

and outputs

First!
Second!

Limitation: works correctly only for objects with one free attribute.

Dev solutions

  • xcop action was deleted because it docker build fails in the workflow and xcop are already runs in the maven build.
  • eoc old version 0.10.0 is used because the latest release 0.10.1 fails on windows (I can add an issue, but there are already failed GHA there).
  • Tests are restructured: divided by cases and added parameterization of tests.

@advasileva advasileva marked this pull request as ready for review January 15, 2023 15:39
@advasileva
Copy link
Contributor Author

@yegor256 PR is ready for review

@yegor256
Copy link
Member

@volodya-lombrozo please, help me review this

@yegor256
Copy link
Member

@advasileva eoc 0.11.1 should work just fine

@advasileva
Copy link
Contributor Author

@yegor256 updated eoc to the latest version, it works, thanks)

Copy link
Member

@volodya-lombrozo volodya-lombrozo left a comment

Choose a reason for hiding this comment

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

@advasileva Several suggestions:

  1. Try to inline variables as much as possible. Article
  2. The PR is quite large. I believe It would be great to send that changes at least in 2 separate PRs: (1) for 2-1-to-objects and (2) 2-2-calls-replacement.
  3. You test both transformations at once in a single test, It would be great to have separate unit tests for each transformation. Unit tests actually help to understand the code behaviour in different cases and improve overall architecture.

Makefile Outdated
mvn clean install -Dmaven.test.skip -Pqulice
cp target/speco-1.0-SNAPSHOT-jar-with-dependencies.jar speco.jar

lint: ##@Dev Rebuild app without linting and tests
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@volodya-lombrozo In this case, it is a "copy-paste" error

@ParameterizedTest
@ValueSource(strings = {"simple"})
public void convertsFromXmir(final String name, @TempDir final Path temp) throws IOException {
final Path output = this.runSpeco(this.xmirs.resolve(name), temp, false);
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva You can inline that variable

for (final Path path : Files.newDirectoryStream(output)) {
@ParameterizedTest
@ValueSource(strings = {"booms", "pets"})
public void convertsFromEo(final String name, @TempDir final Path temp) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva Probably you can inline output and produced variables.
Please read this article: https://www.yegor256.com/2015/09/01/redundant-variables-are-evil.html

* @param second Directory
* @throws IOException Iff IO error
*/
private void compare(final Path first, final Path second) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva You can inline variables here too

} else {
base = this.xmirs;
}
private Path runSpeco(final Path base, final Path temp, final boolean iseo) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva The method could be static.
Probably we can also inline some variables here.

* @param second Directory
* @throws IOException Iff IO error
*/
private void compare(final Path first, final Path second) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva The method could be static

}

/**
* Compares two directpries.
Copy link
Member

Choose a reason for hiding this comment

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

*
* @param first Directory
* @param second Directory
* @throws IOException Iff IO error
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva Did you mean "If"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@volodya-lombrozo no, this is an abbreviation of "if and only if"

* @param second Directory
* @throws IOException Iff IO error
*/
private void compare(final Path first, final Path second) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva Please, give more meaningful names for that variables. It's hard to understand their purpose. You can also add some information to JavaDoc

@advasileva
Copy link
Contributor Author

@volodya-lombrozo I didn't catch point 2, is it better for me now to create two (or three with a separate PR for tests) branches, transfer changes there, and then make edits? Or first make edits to this PR, and then create new PRs?

@volodya-lombrozo
Copy link
Member

@volodya-lombrozo I didn't catch point 2, is it better for me now to create two (or three with a separate PR for tests) branches, transfer changes there, and then make edits? Or first make edits to this PR, and then create new PRs?

@advasileva You can leave as is - it's for the future. As for tests - too, you can just create "@todo Write separate unit test".

@advasileva
Copy link
Contributor Author

@volodya-lombrozo okay, a good opportunity to try pdd)

At first I thought of splitting it into several parts when I was writing #22, but I didn't do that so that no one would have to review and edit a lot of intermediate code.

Copy link
Member

@volodya-lombrozo volodya-lombrozo left a comment

Choose a reason for hiding this comment

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

@advasileva Good. Few small comments

final StringWriter writer = new StringWriter();
IOUtils.copy(process.getInputStream(), writer);
final String[] output = writer.toString().split("\\r?\\n");
final String[] result = Arrays.copyOfRange(output, 11, output.length - 1);
return Arrays.asList(result);
return Arrays.asList(Arrays.copyOfRange(output, 11, output.length - 1));
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva Why exactly 11?

Copy link
Member

Choose a reason for hiding this comment

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

@advasileva (Optional) If you want, you can use cactoos classes instead - they are more convenient, as to me:

new Split(new TextOf(process.getInputStream(), "\\r?\\n");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@volodya-lombrozo 11 is a magic number that I counted myself. That's how many lines the eoc output takes up until the program output itself. As far as I know, this is the output only for eoc link and I can read the program output only for eoc --alone dataize app.

Copy link
Member

Choose a reason for hiding this comment

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

@advasileva It's better to add such description of magic numbers into JavaDoc.

@@ -90,8 +90,7 @@ public void exec() throws IOException {
source = this.input;
}
for (final Path path : Files.newDirectoryStream(source)) {
final XML before;
before = Speco.getParsedXml(new XMLDocument(Files.readString(path)));
final XML before = Speco.getParsedXml(new XMLDocument(Files.readString(path)));
final String after;
if (this.eolang) {
after = new XMIR(
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva You have code duplication here Speco.applyTrain(before).toString(), apparently you can move that upper

@@ -1,15 +0,0 @@
---
name: xcop
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva We fixed problem with xcop. g4s8/xcop-action#4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@volodya-lombrozo It's still redundant (because it is checked in the maven build), but let it be


/**
* Test to test the operation of the command line tool.
*
* @since 0.0.1
* @todo #22:90min add separate unit-test for each transformation,
* which would run step by step and check the intermediate results,
Copy link
Member

Choose a reason for hiding this comment

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

@advasileva Can we add single indent for @todo description?

* @todo #22:90min add separate unit-test for each transformation,
*  which would run step by step and check the intermediate results,
*  for example, use yml packs as in dejump.

this helps to highlight the text of the task

Copy link
Member

@volodya-lombrozo volodya-lombrozo left a comment

Choose a reason for hiding this comment

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

@advasileva Looks good to me

@advasileva
Copy link
Contributor Author

@yegor256 can we try to merge it?

@yegor256
Copy link
Member

@rultor merge

@rultor
Copy link
Contributor

rultor commented Jan 17, 2023

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 6d26670 into objectionary:master Jan 17, 2023
@rultor
Copy link
Contributor

rultor commented Jan 17, 2023

@rultor merge

@yegor256 Done! FYI, the full log is here (took me 5min)

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

Successfully merging this pull request may close these issues.

4 participants