Skip to content

[Yaml] Add flag to dump NULL as ~ #32669

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

Merged
merged 1 commit into from
Aug 4, 2019
Merged

[Yaml] Add flag to dump NULL as ~ #32669

merged 1 commit into from
Aug 4, 2019

Conversation

OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Jul 23, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#12071

This PR adds the ability to dump null as ~ by a new Flag Yaml::DUMP_NULL_AS_TILDE:

- foo: null
+ foo: ~

Todos:

  • Fix/add tests

@fancyweb
Copy link
Contributor

👍 but it has been refused by @fabpot in the past (#26717)

@OskarStark
Copy link
Contributor Author

OskarStark commented Jul 23, 2019

👍 but it has been refused by @fabpot in the past (#26717)

Oh I didn't know that, I talked to @xabbuh before starting to work on it...

To me there is technical reason (regarding the comment in the other PR). I am reading Yaml files, adding some content and dumping it again to the filesystem. Now, depending on the source, wether its using null or ~ the diff get s quite big and a diff/commit is a technical thing to me.

Let me be more clear with an example.

Adding content too this file:

foo: bar
baz: ~

would result in:

foo: bar
- baz: ~
+ baz: null
+ lol: null

which is very verbose. The following would be less verbose:

foo: bar
baz: ~
+ lol: ~

Btw. I created nearly the exact same PR like you @fancyweb without knowing it 😄

@fabpot
Copy link
Member

fabpot commented Jul 23, 2019

Let me explain a bit more why I think that this is not something I want: adding more options is adding more complexity (and complexity grows exponentially with more added options). Having only. One way to do something makes our code simpler, easier to understand, easier to document, and easier to use. Less decisions.

@OskarStark
Copy link
Contributor Author

I agree with you Fabien 👍. Another option would be to rework the YAML component and create an extension point for projects.

I hope you read my argument, because I was updated my post.

I am not the one who decides to get this merged, but as the tilde is a common used thing in YAML, I talked to @xabbuh and he asked me to create a PR, @fancyweb created the same PR... so it looks to me that for this small option the community (at least some of them 😄 ) have a need.

Another point is, that YAML is best to be human readable, but a diff changes every line including a ~ isn't readable anymore.

@fabpot
Copy link
Member

fabpot commented Jul 23, 2019

We moved away from generating ~ in favor of null a few years ago as people didn't understand the meaning of ~ (we probably did that with @javiereguiluz back then).

I know that this is opinionated, but if you have a look at the flow of PRs, we have a regular stream of PRs adding options. I'm the one trying to challenge them to be sure that we really need those new options.

@OskarStark
Copy link
Contributor Author

I'm the one trying to challenge them to be sure that we really need those new options.

And as I said its ok for me to challenge and not merge it. I gave all my arguments 😄 and I really like that you sometimes decide to not merge something 👍

@linaori
Copy link
Contributor

linaori commented Jul 23, 2019

The reason Fabien gives here:

as people didn't understand the meaning of ~

This is one of the few things I didn't know until recently. I think an explicit NULL is far better than having a tilde. However, I also do agree with Oskar on the following:

Another option would be to rework the YAML component and create an extension point for projects.

I think it's pretty great to have a sub-set of YAML functionality provided by Symfony, to which you can create a more complete implementations via 3rd party tools. Not sure how this would be done internally though, as it sounds very complex.

@OskarStark
Copy link
Contributor Author

OskarStark commented Jul 23, 2019

I think an explicit NULL is far better than having a tilde.

Thanks for your feedback @linaori, but I don't want to change the default value (so this is not an argument IMHO) and only want to have the option for people who know the ~ but currently I have really big git diffs after read/modify/dump 😢

@linaori
Copy link
Contributor

linaori commented Jul 23, 2019

If complexity is an issue, should the related code be rewritten to reduce this complexity? Even if it costs a bit of performance (you don't call this run-time, hopefully). The current flag system is also limiting at some point.

@OskarStark
Copy link
Contributor Author

No I am using it async to handle my YAML files.

The proposed option is quite small and I think to rewrite it to fulfill my use-case is too much overhead, the flags are sufficient here.

@derrabus
Copy link
Member

I smell a small inconsistency here. Using the tilde seems to be a Symfony best practise, yet the YAML dumper uses the literal null instead. In other words: If would parse and dump a YAML file from the recipes, all ~ would be changed to null and there's nothing I could do about it, correct? 😕

@OskarStark
Copy link
Contributor Author

If would parse and dump a YAML file from the recipes, all ~ would be changed to null and there's nothing I could do about it, correct

exactly thats my point!

@nicolas-grekas nicolas-grekas added this to the next milestone Jul 25, 2019
@mvhirsch
Copy link
Contributor

I think this should be added, because Symfony interprets ~ as null already. Why not allow dumping it as ~ again, too? 👍

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I'm personally OK to add this one.

@nicolas-grekas
Copy link
Member

But CI needs to be green!

@OskarStark
Copy link
Contributor Author

Sure thing Nicolas, will have a look soon 👀

@xabbuh
Copy link
Member

xabbuh commented Jul 31, 2019

I asked Oskar to open this PR as I agree with the reasoning for the changes. Dumping null by default is good, but being able to get ~ instead allows to keep files more similar to what we use in the documentation. While I generally agree with not adding more options than necessary the impact here is rather limited and doesn't add much complexity. So 👍 from me.

@OskarStark
Copy link
Contributor Author

@fabpot
Copy link
Member

fabpot commented Aug 1, 2019

What about changing ~ to null in the recipes? As I mentioned before, we had a few complaints about the meaning of ~ and decided to move to use null everywhere. Apparently, we forgot about this in the recipes, but that can be easily fixed (see symfony/recipes#635 and symfony/recipes-contrib#720).

@OskarStark
Copy link
Contributor Author

What about changing ~ to null in the recipes?

That makes definitely sense, but the intent of my PR is to handle files, delivered from customers (in my project) which are using ~ instead of null. So this is not only Symfony related.

@fabpot
Copy link
Member

fabpot commented Aug 1, 2019

@OskarStark Of course. I just wanted to follow up and finish the discussion on the Symfony part, where we can definitely standardize on using null instead of ~. I've also added a validation rule so that if one uses ~ in a recipe, we will have a validation error.

For this PR, I'm +0.

@OskarStark
Copy link
Contributor Author

I've also added a validation rule so that if one uses ~ in a recipe, we will have a validation error.

This is a nice addition. I would gladly help to fix those recipes, shall we run a sed command across the whole contrib repo?

For this PR, I'm +0.

I know ;-)

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

with one minor comment

@OskarStark
Copy link
Contributor Author

Travis failure is unrelated

@fabpot
Copy link
Member

fabpot commented Aug 4, 2019

Thank you @OskarStark.

@fabpot fabpot merged commit 749c11d into symfony:4.4 Aug 4, 2019
fabpot added a commit that referenced this pull request Aug 4, 2019
This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] Add flag to dump NULL as ~

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#12071

This PR adds the ability to dump `null` as `~` by a new Flag `Yaml::DUMP_NULL_AS_TILDE`:
```diff
- foo: null
+ foo: ~
```

Todos:
- [x] Fix/add tests

Commits
-------

749c11d [Yaml] Add flag to dump NULL as ~
@OskarStark OskarStark deleted the dump-null-as-tilde branch August 4, 2019 05:33
xabbuh added a commit that referenced this pull request Aug 5, 2019
This PR was squashed before being merged into the 4.4 branch (closes #32944).

Discussion
----------

[Yaml] Removed unused $nullAsTilde property

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

#32669 added a new private property `$nullAsTilde`, but that property was never used, so this PR removes the unused property

Commits
-------

fbef854 [Yaml] Removed unused $nullAsTilde property
OskarStark added a commit to symfony/symfony-docs that referenced this pull request Aug 5, 2019
This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] Dump null as tilde

Docs for symfony/symfony#32669

Commits
-------

68cf0cf [Yaml] Dump null as tilde
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants