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
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Coding standards... and me.

Post by s.dot »

I forget which topic it was in where someone told me that adapting to standards is a sign of a mature programmer. So, I'm trying with the zend coding standards. I got the spacing down. And the parenthesis. Which I don't like, but I can deal with it.

Code: Select all

if (foo) {
    //do this
}

function bar($more)
{
    //do that
}
I can even deal with the variable naming (which I also don't like).

Code: Select all

$thisNameGoesHere = foobar();
All of the rest I pretty much did already, making it easy to comply. :)

However, the one I refuse to change (maybe it's my immaturity) is using 4 spaces instead of tabs. I don't think I will ever change that. Tab is just way easier, in my opinion. And I've been used to it since back when I started writing HTML.

Is that that much of a big deal? I mean most editors come with a function that converts tabs to spaces and vice versa.

I don't want to start the tabs vs spaces debate though.

My point of this topic is do you conform to coding standards? If so, which? Was it hard to get into practice of using the standards? Are there any (like me) that you just refuse to use?
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
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

It seams that everyone has their own standards which are so simmilar but so different too. The ones I go with are:

Code: Select all

if (foo)
{
    //do this
}

function foo()
{
    //do that
}

$this_name_goes_here = foobar();
And yes, I use a tab instead of spaces. I used to be the other way around and would fight to the death about it but I dunno, it just seams easier to use tabs now. You can view my tabs in as many spaces as you want so no problems.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

The same as @shiznatix.


About the variable naming - I feel pretty comfortable with both of suggested.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

In my opinion, $variable_name_here is so much "prettier", easy to read, and less prone to case errors.
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
The Phoenix
Forum Contributor
Posts: 294
Joined: Fri Oct 06, 2006 8:12 pm

Re: Coding standards... and me.

Post by The Phoenix »

scottayy wrote: However, the one I refuse to change (maybe it's my immaturity) is using 4 spaces instead of tabs. I don't think I will ever change that. Tab is just way easier, in my opinion. And I've been used to it since back when I started writing HTML.

Is that that much of a big deal? I mean most editors come with a function that converts tabs to spaces and vice versa.

I don't want to start the tabs vs spaces debate though.

My point of this topic is do you conform to coding standards? If so, which? Was it hard to get into practice of using the standards? Are there any (like me) that you just refuse to use?
Definitely not starting the debate, or continuing it, but just wanted to point out the logic that led me to a different conclusion.

The tools in use: Putty on Windows, Firefox viewing the websvn on sourceforge, and nano on linux as the text editor.

Copy and paste from firefox, into nano via putty. Tabs are pasted as spaces. Now do a svn diff. Guess what? They are different than the code you are viewing - resulting in an incorrect diff.

It makes it impossible to use that set of tools. Further, nano doesn't offer a way to view tabs as spaces as far as I know.

Tabs have plenty going for them, but cut-n-paste across multiple platforms isn't one of them. Tabs is good for compatibility between different coding styles, spaces is good when you need the code to be consistent no matter what.

So, I went with spaces. There is almost never a time when a piece of software cannot consistently display four spaces. :)
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

The thing I like about Editplus is that I can set it so that whenever I tab, it uses 4 spaces instead of a tab, thus constraining to a standard, but keeping the ease of use of a single keystroke versus 4 keystrokes.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Just about any editor wort its salt nowadays can spacify tabs (and vice versa). I am a tab man myself, except in one editor, which I use to write code for the forums (posting in the forums) because tabs in the Syntax Highlighter are way bigger than four spaces would be.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Everah wrote:Just about any editor wort its salt nowadays can spacify tabs (and vice versa). I am a tab man myself, except in one editor, which I use to write code for the forums (posting in the forums) because tabs in the Syntax Highlighter are way bigger than four spaces would be.
I counted them once. ;) Tabs are 8 spaces on here (or the geshi mod... whatever you guys are using).
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
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
if ($spaces) {
    echo 'These are spaces.';
} elseif ($tabs) {
	echo 'These are tabs.';
}
?>
User avatar
The Phoenix
Forum Contributor
Posts: 294
Joined: Fri Oct 06, 2006 8:12 pm

Post by The Phoenix »

Everah wrote:Just about any editor wort its salt nowadays can spacify tabs (and vice versa).
Turns out I was wrong - nano does support tabs->spaces. Nevertheless, the end result that gets committed (ie, the coding standard) for me has to remain spaces so I don't cause different diffs based on a tab v. a space.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I like tabs, but the editor I use (PHP Designer 2007) makes it so that I can treat spaces like tabs when traversing the document, so whether it's spaces or tabs, I don't notice the different unless I use the mouse.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

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.

Also, using tabs is also better than using spaces.

Why?

Because every file I have seen with tabs the person using them uses something different and they tend to mess things up. You have a programmer use 2 spaces for tabs and other uses 4 spaces for tabs. Yet another uses 3 spaces. And these same people who use tabs tend to screw up on the tabbing while editing their code. The person using 4 spaces sometimes inserts code at a 3 space point making everything unaligned. :P

I end up having to use search and replace to convert 2/3/4 space tabs to single tabs. That's easy but then I have to go back and remove all of their errors where they use extra spaces and BROKE their tab sequence. :P Sloppy programming.

Yes, I know I am anal about formatting but it makes things so much easier to read if you get it right the first time.
Last edited by AKA Panama Jack on Fri Aug 10, 2007 2:16 pm, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

AKA Panama Jack wrote:Also, using tabs is also better than using spaces.
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.
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:
Everah wrote:Just about any editor wort its salt nowadays can spacify tabs (and vice versa).
Turns out I was wrong - nano does support tabs->spaces. Nevertheless, the end result that gets committed (ie, the coding standard) for me has to remain spaces so I don't cause different diffs based on a tab v. a space.
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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

But the files are different. They should show as different.
Post Reply