Skip to content

Improve parameter names in ext/xmlwriter #6202

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

Closed
wants to merge 1 commit into from

Conversation

dtakken
Copy link

@dtakken dtakken commented Sep 24, 2020


function xmlwriter_start_dtd_element(XMLWriter $xmlwriter, string $qualifiedName): bool {}
function xmlwriter_start_dtd_element(XMLWriter $writer, string $qualified_name): bool {}
Copy link
Member

Choose a reason for hiding this comment

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

As these are aliased with XmlWriter::startDtdElement() etc and have common documentation (https://www.php.net/manual/en/function.xmlwriter-start-dtd-element.php), I believe we need the parameter names to match as well. Is that correct @cmb69?

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I was the one who told Dik that it's possible to use different names for the procedural and the OO API (since it has no technical limitation). Unfortunately, I didn't think about the documentation :/

Copy link
Member

Choose a reason for hiding this comment

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

As it is now, the procedural and OOP API have individual <methodsynopsis> elements, so this is not an issue for the documentation. I am generally not sure that having different parameter names for dual APIs is a good idea, though, since that may make transitioning from procedural to OOP slightly harder (the other way round is equally harder, but likely not a relevant issue).

Copy link
Member

Choose a reason for hiding this comment

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

@cmb69 The issue I had in mind here is that parameter names are also referenced in the body of the documentation, not just the method synopsis. There wouldn't be a unique parameter name to use in that case (though I guess using either one wouldn't be terrible either).

Copy link
Member

Choose a reason for hiding this comment

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

Oh, indeed, that wouldn't be nice.

Copy link
Author

Choose a reason for hiding this comment

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

I think it is worth considering to simply always use $snake_case style parameter names inside php-src.

Does this not go against the general direction to make internals and userland more alike, blend more naturally? At some point, internal APIs may even be written in PHP. In that scenario, having internal APIs look less alien from a userland perspective seems relevant...

(Of course, always using $camelCase in php-src is also an option, I just suggested snake_case as it seems to be currently predominant.)

I prefer that proposal. I agree that the procedural APIs are of lesser importance. Making the OO APIs come out right is the main thing. If the procedural versions also come out right, that is a nice to have.

Copy link
Author

Choose a reason for hiding this comment

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

(Of course, always using $camelCase in php-src is also an option, I just suggested snake_case as it seems to be currently predominant.)

Just to make sure I understand your proposal correctly:

  • Pure OO APIs: camelCase
  • Dual APIs: camelCase
  • Pure procedural APIs: snake_case

Copy link
Member

Choose a reason for hiding this comment

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

Yes, either that, or pick one of camelCase/snake_case for everything.

Copy link
Author

Choose a reason for hiding this comment

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

I think keeping the snake_case for pure procedural is nice. It makes the parameter naming style match the existing snake_case function names. Also, most APIs are in that style already.

Using camelCase for everything else nicely matches the style of most userland code.

Copy link
Author

Choose a reason for hiding this comment

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

Just pushed an update to apply Nikita's proposal.

@dtakken dtakken force-pushed the parameter_names_xmlwriter branch from 83afd1d to 456f5df Compare September 30, 2020 10:19
@dtakken
Copy link
Author

dtakken commented Sep 30, 2020

I just pushed an update that includes review feedback from @nikic.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

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

Looks ok. @kocsismate?

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

That's all I found :)


function xmlwriter_write_element(XMLWriter $xmlwriter, string $name, ?string $content = null): bool {}
function xmlwriter_write_element(XMLWriter $writer, string $name, ?string $content = null): bool {}
Copy link
Member

@kocsismate kocsismate Sep 30, 2020

Choose a reason for hiding this comment

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

Aha! I see why content was used for attributes! While it is's a good term for describing what an element contains, it's not the best in case of attributes.

Copy link
Author

Choose a reason for hiding this comment

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

I understand your preference for $value for attributes. I would be OK with using $value for attributes while keeping $content elsewhere. Are you OK with that as well @nikic?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm okay with making that distinction.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I just pushed these last few changes.

@dtakken dtakken force-pushed the parameter_names_xmlwriter branch from 456f5df to 803deee Compare October 1, 2020 11:24
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.

4 participants