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

Version 0.9.0 #177

Merged
merged 103 commits into from
Mar 26, 2014
Merged

Version 0.9.0 #177

merged 103 commits into from
Mar 26, 2014

Conversation

Progi1984
Copy link
Member

No description provided.

Progi1984 and others added 30 commits March 15, 2014 10:00
Fancy web interface for samples
@Progi1984 Progi1984 added this to the 0.9.0 milestone Mar 26, 2014
@Progi1984 Progi1984 self-assigned this Mar 26, 2014
@Progi1984 Progi1984 added the Pull label Mar 26, 2014
Progi1984 added a commit that referenced this pull request Mar 26, 2014
@Progi1984 Progi1984 merged commit ac6f5a3 into master Mar 26, 2014
@ghost
Copy link

ghost commented Mar 31, 2014

This just explains in details what I just said. It is a lot cleaner to not use leading backslashes everywhere, that would just drives us all crazy.

@gabrielbull, I wouldn't agree with you. :) My opinion is based on the followed research results.

Regarding constants.

  • As danbettles mentioned, the language allows to define a constant in a certain namespace. That means, if you see an unqualified constant name in your source code, you have no idea whether it's a local or global constant until you look into the code carefully. You have to look through the code to make sure that it's global/local constant in your case. Using leading backslash before global constant calls increases code readability, saves readers time, and makes the code clearer. It works in the way it works with classes: if you see backslash before unqualified name, you may be sure that the constant is from global namespace. In current situation you have to spend some time to reveal that.
  • As manolachref mentioned, the language allows us to redefine existing global constants and even NULL value. I checked that on PHP 5.4, and the described behaviour is still actual. That means, if you see usage of constant which name looks like global constant, you may be wrong, because somebody could redefine it's value in local namespace. In this case you can't be sure that you use value from global constant (INI_ALL, for example) even it's name looks so. You will have to spend some extra time to find out which namespace this constant belongs to. Leading backslash saves readers time in this situation too.

Regarding functions.

I found this page: https://php.net/manual/en/language.namespaces.fallback.php

That's the right link. It means the same as with constants. If you look at some unqualified function name, you have no idea whether it's a local or global function. Even its name looks like global (strlen, for example), you may be wrong, because the function could be redefined in a local namespace. In this case you have to spend some extra time to find out the truth. That's not good. Fallback is a good thing when you develop small project and develop by yourself only. If you're a member of a team and codebase is large enough, using fallback decreases code readability and requires extra time to understand the code.

And finally, classes have no fallback to global namespace, but functions and constants have. It's a waste of brain power and of your memory resources if you prefer keeping this in your mind permanently. We're all human beings, and we make mistakes. Somebody can easily use local function/constant instead of global one. Moreover, you will always have to make sure that you deal with global/local constant or function. Using the leading backslash everywhere (classes, constants, functions) gives us the same logic for all global calls and thus saves a lot of time, attention and decreases bug appearance probability.

Here is what really drives me crazy (not leading backslahes):

  • wasting my time to check whether I look at global constant/function or at local one instead of resolving this task by leading backslash presence;
  • permanently keeping in my memory the rule, that classes have no fallback to global namespace, but functions/constants have, instead of using the same approach with all of them;
  • possible mistakes, because of overriden global constants/functions.

If you ask me what I vote for, I vote for increasing code readibility, time and attention savings, and minimum of bugs.

@gabrielbull
Copy link
Member

Well, if we're to take a vote, I vote we don't ever use backslashes for PHP functions and we use backslashes or the use keywords for classnames. I'm sorry if this isn't what you wanted, but you'll never convince me otherwise. There is simply no way I'm going to code in a language that requires backslashes before functions. As for the time being spent looking if the function is global, you should consider PHPStorm, it will save you that time and much more. I'm sure we're entitled to a free license for this project.

@ghost
Copy link

ghost commented Apr 1, 2014

@Progi1984, @ivanlanin, what do you think? Another bad idea?

@gabrielbull
Copy link
Member

Why you say another, nobody said the PSR-4 thing was a bad idea. It was a good idea, we're just not yet ready ;-).

@ivanlanin
Copy link
Contributor

Coding standards are always become source of debate. I like it that we don't use our own standard and use existing PSR standard instead. Still, we have to face this issue :)

IMHO, this is just a matter of preference. Yes, there are some valid technical issues that were mentioned, but I think we can use either with or without leading backslashes. My personal preference is always to write my codes in the shortest way as possible/allowed, i.e. I prefer without leading backslashes. I've joined teams with different coding styles and I'm fine with any decision made by the PHPWord team :)

@ghost
Copy link

ghost commented Apr 6, 2014

OK, let it be so. I will remove the backslahes when @ivanlanin is done with refactoring.

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

Successfully merging this pull request may close these issues.

3 participants