Coding standards... and me.

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

AKA Panama Jack wrote:This is by far the BEST way to enter functions because it is much easier to visually match beginning and ending brackets.
I didn't even notice that this is what they were referring to. I always match brackets, and I even put brackets on statements that only execute one line of code. It may take more space, but it's more organized, IMO.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

astions wrote:Tabs are the work of the Devil. If I was god I would abolish them into the depths of nothingness. They are useless placeholders destined to be replaced with spaces.
astions wrote:But the files are different. They should show as different.
The files are different when you compare the whitespace. But because (besides Python) most languages are whitespace independent it does not matter to PHP.

If anything, I would think the infinitesimal time it takes to parse over all those extra space characters rather than the far fewer tabs would make a man of your passionate opinions pro-tab!
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I became annoyed with tabs when my code would get misaligned from one editor to another. That never happens with spaces, so my code is still pretty :wink:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

AKA Panama Jack wrote:

Code: Select all

function bar($more)
{
    //do that
}
This is by far the BEST way to enter functions because it is much easier to visually match beginning and ending brackets.
The counter argument I have heard to this is that because modern editors will show bracket errors that never using one true brace is more consistent shows more program lines per page -- which is an essential goal of that style.

FYI - that opening brace style was because in C you declared parameters between the function declaration line and the code block, so the opening code brace lined up with those declarations. Languages like PHP put the parameter declaration in the function declaration line so the one true brace is no longer needed.
(#10850)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

astions wrote:I became annoyed with tabs when my code would get misaligned from one editor to another. That never happens with spaces, so my code is still pretty :wink:
Yup, that's the reason to use spaces. It is often a good practice on teams that use different editors, as well as large public projects. However if the team can configure their editors to translate, or have the CVS to it for them, then it can become a non-issue. I have worked on teams where each programmer checked out code with their own preference. Releases were pretty-printed to some agreed upon target.
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

arborint wrote:I have worked on teams where each programmer checked out code with their own preference. Releases were pretty-printed to some agreed upon target.
That sounds like a pretty cool way to do it. I find myself going through others code and indenting it properly. I don't know if it makes the other guys mad or not but they never say anything about it lol.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

astions wrote:That sounds like a pretty cool way to do it. I find myself going through others code and indenting it properly. I don't know if it makes the other guys mad or not but they never say anything about it lol.
I should have to clean up all my code. What I do is probably anathema to you -- I don't care much if the indenting is a little off so I just leave it however it is ...
(#10850)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

superdezign wrote:
AKA Panama Jack wrote:This is by far the BEST way to enter functions because it is much easier to visually match beginning and ending brackets.
I didn't even notice that this is what they were referring to. I always match brackets, and I even put brackets on statements that only execute one line of code. It may take more space, but it's more organized, IMO.
That would be the Zend standard way. Always brackets. Always. =] I like it that way. I like the function brackets.. but not so much the if ()'s.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

astions wrote:I became annoyed with tabs when my code would get misaligned from one editor to another. That never happens with spaces, so my code is still pretty :wink:
That is an editor problem and not a coding problem. I have tried many different editors before sticking with UEStudio and every one of them would cut and paste tabs perfectly if you disabled the "TABS as SPACES" feature if the editor has it.

Personally, I found far more problems with misaligned cut and paste code when programmers used SPACES instead of TABS because it seems like every programmer has a different definition of how many spaces it takes to make a tab. If you use TABS then they will ALWAYS be the right distance when you cut and paste between applications.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

arborint wrote:
AKA Panama Jack wrote:

Code: Select all

function bar($more)
{
    //do that
}
This is by far the BEST way to enter functions because it is much easier to visually match beginning and ending brackets.
The counter argument I have heard to this is that because modern editors will show bracket errors that never using one true brace is more consistent shows more program lines per page -- which is an essential goal of that style.
I have heard that too and find it an annoying argument. ;)

Most modern editors will do automatic bracket matching. I use UEStudio and it does that as well but I like being able to LOOK at program code and tell at a glance where bracketed code blocks are instead of moving the cursor to each bracket to see the corresponding bracket highlighted. The latter is time consuming and less efficient.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

@arborint: The main reason why I go through and indent the code is because I can process the code and know where I am in the flow without having to actually read the code. This makes it much faster and easier for me to zero in on the part I want to modify. When it's not indented I have to read the code instead of just the if/while/foreach statements. Also, it's amazing how many undiscovered bugs I have found by doing this.

@aka: Are you a windows fan? I would venture to guess that most Linux guys probably prefer spaces, while most windows guys prefer tabs.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

I prefer Linux for servers as it is better suited for that task.

I don't care for Windows but I use it because I have to use it if I want to use certain applications and games. Yes, games also play as bit a part as applications. Linux is getting there but way too slowly for my tastes. Until entertainment companies start including Linux versions by default in all of their releases I doubt that I will be switching anytime soon.
User avatar
The Phoenix
Forum Contributor
Posts: 294
Joined: Fri Oct 06, 2006 8:12 pm

Post by The Phoenix »

arborint wrote:The counter argument I have heard to this is that because modern editors will show bracket errors that never using one true brace is more consistent shows more program lines per page -- which is an essential goal of that style.
To which I say, welcome to the world of 20"+ monitors, dual monitors, zooming text, and IDE's that do code folding. I'm not a fan of modern IDE's, but the whole "I can see more on one page" line seems more and more laughable as monitors get larger than windshields..
AKA Panama Jack wrote: Any Diff programm worth it's salt will basically ignore leading spaces and tabs that are outside quotes when comparing file code. If it doesn't then that DIFF program has a really bad problem. I have one called Free Diff that only compares actual code differences which is what a Diff program should do.
A rephrase could be that there are some diff programs that offer the ability to ignore whitespace differences. But by default almost every one of the unix standard diff (for the last twenty YEARS mind you) has indeed seen tabs as different than spaces.

Because they are.

But yes, you can get an editor that converts tabs to spaces. And yes, you can get a diff program that ignores tabs v. spaces, and you can also even use a program to prettify the formatting before committing. But in the end, all of those give you workarounds to the main problem - inconsistencies between programmers.
AKA Panama Jack wrote:it seems like every programmer has a different definition of how many spaces it takes to make a tab
Which is why we have coding standards. :) By saying "no tabs at all", that issue is entirely eliminated.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

The Phoenix wrote:
AKA Panama Jack wrote:it seems like every programmer has a different definition of how many spaces it takes to make a tab
Which is why we have coding standards. :) By saying "no tabs at all", that issue is entirely eliminated.
Couldn't be more wrong on that because you will find different people claiming coding standards that use spaces instead of tabs have different idea as to what is the proper number of spaces to use in place of tabs.

You see tabs were created for a REASON way back in the old typewriter days and refined with computers. Tabs have a built in STANDARD for width so if you use a tab in one editor it will show properly in another program unlike spaces. Just about every major or decent editor that offers the ability to use tabs instead of spaces allows the number of spaces per tab to be set by the user. And you will find that not all editors have the same default number of spaces to represent a tab.

If any programmer wants to have display consistency they would never use spaces but stick with tabs as tabs because the display will always be the same no matter what editor they use. Even Linux editors support tabs as tabs. You would probably have to really dig to find a modern editor, even on Linux, that doesn't display tabs properly as tabs.
Last edited by AKA Panama Jack on Sat Aug 11, 2007 1:05 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

@aka, I think your totally right about how tabs have a set width. But isn't that related to document formating? As in for print? I think code is a bit different.
Post Reply