tags:

views:

76

answers:

8

I started with CSS so I always used brackets this way:

#content {
    selector: value;
}

While using CodeIgniter I noticed that each file have the brackets like this:

function something here() 
{
    $this->$item('item');
    $data['rows'] = $this->data_model->getAll();

    $this->load->view('home', $data);
}

Is the second example better for readability or copying or pasting?

+2  A: 

No difference at all, you can use this style just if it's more understandable for you.

Centurion
There is a **big** difference in readability and LOC.
Alix Axel
@Alix Axel, As you can see i mentioned readability, LOC maybe, but it wouldn't affect performance in way that you would feel it somehow
Centurion
The OP asked which one was more readable or easier to copy + paste, your reply stated that there was no difference at all. I didn't read performance anywhere - and more (or less) LOC won't affect performance, once could argue that comments could, if they were big enough to increase the byte count, but not LOC.
Alix Axel
A: 

I would have said your way is more readable.

It's a personal preference / team standards thing at the end of the day though.

Most people tend to go for your method or the following:

function something()
{
   //more code
}
Rob Stevenson-Leggett
A: 

there is no matter where you put the brackets ...... you put them where for you will be more easy to read the code

Gatman
+1  A: 

The Zend Framework manual has a good chapter on their coding style, which might help you with the basics such as class naming etc.

Update: Looks like the original question has been changed to include CodeIgnitor. It is best you adhere to the style in the framework or the surrounding code if you are taking over someone elses project.

Treffynnon
+1 Quite a lot of companies adhere to the ZF coding guidelines too, so it might be useful to apply these.
wimvds
+1  A: 

You can use both styles in PHP (and in CSS) and that will not affect the way your code executes.

Choosing one style over the other is a matter of personal preference. If you are using CodeIgniter, though, I'd recommend that you stick to it's coding style and be consistent.

Emanuil
+4  A: 

That actually looks a bit wrong for CodeIgniter; according to the Style Guide, they use Allman style. See this article on Wikipedia for some background on indentation styles. [NB: indentation now fixed in question].

Really, though, it's just a matter of religion (note that Wikipedia's Indent Style article is currently linked to from its Wars of Religion article!)

The best thing to do is to be consistent.

So, for your own project, use whatever you feel is the most readable/usable. But if you wanted to contribute code to CodeIgniter, you'd use the Allman style, and if you're writing a project that just uses CodeIgniter, it might be easier to follow their style simply to stop your brain from having to swap between two styles while you're simultaneously digging through their code and writing yours.

Matt Gibson
"The best thing to do is to be consistent." I think this is the thing I was looking for. I better be consistent with CodeIgniter.
janoChen
A: 

It's doesn't matter, as long as it's interpreted correctly.

However, if you work in a multi-developer environment, it may be worth agreeing upon a coding style standard across your work flow.

Martin Bean
A: 

No, it isn't simply a matter of preference. The style used by CodeIgniter simply is wrong in my eyes (yeah, give me many downvotes pls). There simply is one coding style that many projects use, the Zend Coding Standards Coding Style. In my opinion this is the only valid coding style, simply because most projects use it and you therefore don't need rethinking when you start contributing to them.

Actually, this is one of the reasons, why I do not use CoedIgniter. Another reason is, that they provided the introduction videos only in QuickTime. I don't expect they provide me a webm video, but at least Flash would really be nice.

PS: Please don't think I say this only because these are the Coding Standards I use. No, this isn't the case. I do not strictly adhere to these standards. But I think I should and I will try to. Simply because they are the standard.

nikic