Jump to content

Programmer Style Guide...?


Alex

Recommended Posts

Strings consisting of more than one character should be surrounded with double-quotes ("). Strings consisting of only a single character may be surrounded with single-quotes (').

Source: http://docs.blesta.com/display/dev/Programming+Style+Guide

 

Why in the world..? That's slower and more confusing; exact opposite of my normal style guide. Sure in Java or C++ -- but why would you do this in PHP?

Link to comment
Share on other sites

Slower to type? Because it certainly isn't slower to execute.

 

Why have we made double quotes required for string literals? Because:

  1. Double quoted strings are more powerful.
  2. It improves readability, allowing quick identification of array indexes vs string literals.
  3. All of the Blesta devs come from a C/Java background so it's only natural from our perspective.
  4. Because of #3, if we didn't define how string literals should be handled we'd potentially have a mess of code with mixed quoting which negatively affects readability.
Link to comment
Share on other sites

 Slower to type? Because it certainly isn't slower to execute.

 

Why have we made double quotes required for string literals? Because:

  • Double quoted strings are more powerful.
  • It improves readability, allowing quick identification of array indexes vs string literals.
  • All of the Blesta devs come from a C/Java background so it's only natural from our perspective.
  • Because of #3, if we didn't define how string literals should be handled we'd potentially have a mess of code with mixed quoting which negatively affects readability.

 

Well, no, it's slower to execute... If anything, it is probably faster to type your way. Extra run-time parsing is done with double quotes, causing inherently slower execution. This has been debated from both sides and I don't have any benchmarks for you, but I think that it just makes sense looking at it from a high level. PHP isn't compiled, so all of these seemingly marginal considerations add up to a much larger impact than they do with C/Java, even if it is still marginal.

 

#1 - Power should be used with discretion, since it is usually harder to debug and slower. What power does it give you really? Variables inside strings and escape sequences other than \'? Whoopdie freaking doo!

#2 - I've never had an issue with the readability of either.

#3 - I figured this right off, but I know lots of other programmers with the same background who would agree with me in the case of PHP.

#4 - See below:

• Always use single quotes

• Concatenate with commas when using echo

echo 'I ',$loveORhate,' ice cream.';

I've written code bases with xx,xxx lines using this method and developers have picked up on it in hours not days, with no documentation, so the issue of readability is a really hard sell for me. It seems to me like your method was a decision based on familiarity and preference, not principle.

 

It's not a big deal, conformity is most important, but the reasoning is clearly the Java/C background and not that it's ideal in PHP. I will simply write Blesta extensions using this method since it's probably too late for you guys to make a change like this now.

Link to comment
Share on other sites

 

Well, no, it's slower to execute... If anything, it is probably faster to type your way. Extra run-time parsing is done with double quotes, causing inherently slower execution. This has been debated from both sides and I don't have any benchmarks for you, but I think that it just makes sense looking at it from a high level. PHP isn't compiled, so all of these seemingly marginal considerations add up to a much larger impact than they do with C/Java, even if it is still marginal.

 

There is essentially no performance difference (http://www.phpbench.com/). But I have neither the time nor patience to get into a protracted argument of the pros and cons of performance vs readability which are, on occasion, diametrically opposed.

 

#1 - Power should be used with discretion, since it is usually harder to debug and slower. What power does it give you really? Variables inside strings and escape sequences other than \'? Whoopdie freaking doo!

 

I couldn't possibly disagree more.

 

#2 - I've never had an issue with the readability of either.

 

Readability, while somewhat objective as you've come to find, is not about one man's issues.

 

#3 - I figured this right off, but I know lots of other programmers with the same background who would agree with me in the case of PHP.

 

That's nice, but they're not constrained by this style guide so their opinion is moot. Maybe they prefer spaces over tabs, I don't care.

 

#4 - See below:

I've written code bases with xx,xxx lines using this method and developers have picked up on it in hours not days, with no documentation, so the issue of readability is a really hard sell for me. It seems to me like your method was a decision based on familiarity and preference, not principle.

 

It's not a big deal, conformity is most important, but the reasoning is clearly the Java/C background and not that it's ideal in PHP. I will simply write Blesta extensions using this method since it's probably too late for you guys to make a change like this now.

 

A style guide is created and enforced by those that have their heads in the code each and every day. There are as many style guides as there are development teams. If PSR existed when we started Blesta, maybe we would have conformed to that standard instead (unlikely because tabs are better than spaces), but I digress.

Link to comment
Share on other sites

There is essentially no performance difference (http://www.phpbench.com/). But I have neither the time nor patience to get into a protracted argument of the pros and cons of performance vs readability which are, on occasion, diametrically opposed.

 

 

I couldn't possibly disagree more.

 

 

Readability, while somewhat objective as you've come to find, is not about one man's issues.

 

 

That's nice, but they're not constrained by this style guide so their opinion is moot. Maybe they prefer spaces over tabs, I don't care.

 

 

A style guide is created and enforced by those that have their heads in the code each and every day. There are as many style guides as there are development teams. If PSR existed when we started Blesta, maybe we would have conformed to that standard instead (unlikely because tabs are better than spaces), but I digress.

 

What I got here is that the bottom line is you guys chose this style because it is more native and comfortable to you, and you have to work with it every day. That's fair reasoning, and so as I said, I will adhere to the guidelines as I work with Blesta in an effort to maintain the most important feature of all here: conformity.

 

I am curious though, what power do these double quotes behold that I am overlooking?

 

In my wee bit of a brain the syntactical similarity between array indexes and single quoted strings is non-existent, due to the wrapping square brackets around one. That's probably because I started with PHP and learned (what little I know of) Java/C later, so I can understand where you're coming from on that, so long as I look at it from an objective point of view.

 

Thanks for taking the time to answer this thread. I don't want this to become a tit for tat intellectual stage, nor do I have the time or patience for that, I was just curious. I perceive a bit of hostility or at least frustration in your reply, and so I should tell you that it didn't actually strike me that his would have come from a C/Java background until after I posted (you can check the edits of my OP to see that), so please don't be offended. (I do admit I wrote that I saw this "right off" in my second post, but that was poorly worded, as what I meant to say was "right after I posted" -- Paul can confirm this per our conversations happening in parallel)

Link to comment
Share on other sites

I just want to throw out there I agree with Alex.

With that said, its not my product so my opinion doesn't matter.

I've been developing web applications over 15 years. Initially with Perl, then shortly thereafter with PHP.

I've always found single quotes easier to read whenever you need to plug a variable in. I always use concatenation.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...