You are not logged in.

Important Note: This forum is being archived and will be completely locked down on the 7th of February. The new forum can be found at http://laravel.io.

Announcement

    Laravel 4 Advanced Architecture: Book Now On Sale

#1 2012-10-09 22:36:47

Xxp
Artisan
Registered: 2012-10-09
Posts: 55

L4 camelCase http://www.phptherightway.com/

According to phptherightway website - PSR-0, PSR-1 and PSR-2 all state:

Methods
Method names MUST be declared in camelCase().

My question is, will Laravel 4 follow these coding standards and therefore things like a RESTful Controller use getActionName as opposed to get_action_name, or actionSomeName as opposed to action_some_name for non-RESTful controllers?

Everyone has their opinions on this but phptherightway is trying to enforce some sort of coding standards which wouldn't hurt Laravel to become more opinionated on coding style, much like Zend does. It means future bundles / packages would all adhere to one single coding standard.

Offline

#2 2012-10-09 22:41:04

JonoB
Artisan
Registered: 2011-11-09
Posts: 284

Re: L4 camelCase http://www.phptherightway.com/

Offline

#3 2012-10-09 22:50:05

Xxp
Artisan
Registered: 2012-10-09
Posts: 55

Re: L4 camelCase http://www.phptherightway.com/

Ok so L4 is using Composer, I would assume camelCase() is going to be used for actions then cheers! smile

Offline

#4 2012-10-09 22:55:12

Xxp
Artisan
Registered: 2012-10-09
Posts: 55

Re: L4 camelCase http://www.phptherightway.com/

Had a quick look through Illuminate... Wow!! Just.. Wow! You guys are amazing, I can't wait to learn it and start contributing! Keep going strong big_smile!

Offline

#5 2012-10-18 18:59:16

benjaminkohl
Artisan
From: Grand Rapids, MI
Registered: 2012-09-07
Posts: 17

Re: L4 camelCase http://www.phptherightway.com/

I can't stand the PSR standards because camelCase is ugly and I really don't care to adhere to strict standards on how I format my conditionals (I always make my opening and closing brackets lineup the same way vertically). I won't go so far to say that this is a big mistake because maybe most developers love those code style standards, but I KNOW I am not the only person that strongly prefers snake_case over camelCase.

Offline

#6 2012-10-18 22:22:56

Franz
Administrator
Registered: 2011-11-13
Posts: 758

Re: L4 camelCase http://www.phptherightway.com/

I think the benefits (code interoperability and common standards) by far outweigh the disadvantages, because, really, they're just a matter of taste. And there's definitely no right or wrong answers to such questions. wink


FluxBB Core Developer - trying my best to break this forum everyday :)

Offline

#7 2012-10-18 22:53:30

Xxp
Artisan
Registered: 2012-10-09
Posts: 55

Re: L4 camelCase http://www.phptherightway.com/

benjaminkohl wrote:

I can't stand the PSR standards because camelCase is ugly and I really don't care to adhere to strict standards on how I format my conditionals (I always make my opening and closing brackets lineup the same way vertically). I won't go so far to say that this is a big mistake because maybe most developers love those code style standards, but I KNOW I am not the only person that strongly prefers snake_case over camelCase.

Whether you find it ugly or not camelCase is generally a strong standard amongst most development languages. Google's standards for C++ / Javascript are very similar to PSR too. Coming from a Zend Framework background the biggest thing I liked about it was that they were very opinionated on Coding Standards and what every developer should adhere too when using their Framework. Their documents stated the standards to be used and when I used someone else's code, it looked like mine. When I contributed to someone else's code, again it looked the same.

I know people always have different opinions on this but sometimes you just have to grin and bare it. Many developers that move into large corporations generally are told to use x, y and z coding standard within the company so that other developers don't need to understand their syntax.

Btw, L4 isn't adhering to PSR anyways by the looks which is kind of frustrating.

if ()
{
}
class Name {
}

aren't PSR-2 hmm However if there is ever an Official Laravel Coding Standard released and it stated that is how I should do conditionals regardless of PSR, then I would do that... Just so my syntax is the same as every other Laravel developer and the Laravel source.

I'm not looking to get into debates on opinions, all I was trying to do was say that like many other languages it would be nice to have some sort of official coding guideline for Laravel 4+ so that when I use someone else's code via Composer the syntax is the same.
http://www.phptherightway.com/ is trying to introduce this with PSR even to the point of 4spaces = 1tab etc.

If you don't believe in standards then you must have a hell of a job working with others on a single project.

class Chicken
{
	/**
	 * Return class entities
	 *
	 * @return array
	 */
	public function getAllEntities()
	{
		// Logic.

		return $data;
	}

  //Get entity by id {another dev's code}
  public function get_entity_by_id() {
    //Logic.
    return $entity;
  }
}

^ Ouch

Offline

#8 2012-10-18 22:55:10

swt83
Artisan
From: Washington, DC
Registered: 2012-03-08
Posts: 74

Re: L4 camelCase http://www.phptherightway.com/

I agree that camelCase is horrible. 

I think we got caught by a political situation where Taylor was part of the standards group and got out voted, and now he has to play nice with the decision.  We need to work toward keeping him lonely and isolated from these peer groups in the future.

Offline

#9 2012-10-18 22:58:37

TaylorOtwell
The Creator
From: Arkansas, USA
Registered: 2011-06-06
Posts: 1,198

Re: L4 camelCase http://www.phptherightway.com/

I chose camelCase partly because of PSR-1, but mainly because of PHP itself.

All of PHP's object oriented libraries are in camel case (PDO, SPL, etc.)... basically I believe you should follow the standard of your environment. In PHP global functions are snake_case and libraires are camelCase, so that's the standard I followed.

That being said Laravel 4 follows PSR-0 and PSR-1, not PSR-2.

Offline

#10 2012-10-18 23:17:00

Xxp
Artisan
Registered: 2012-10-09
Posts: 55

Re: L4 camelCase http://www.phptherightway.com/

TaylorOtwell wrote:

I chose camelCase partly because of PSR-1, but mainly because of PHP itself.

All of PHP's object oriented libraries are in camel case (PDO, SPL, etc.)... basically I believe you should follow the standard of your environment. In PHP global functions are snake_case and libraires are camelCase, so that's the standard I followed.

That being said Laravel 4 follows PSR-0 and PSR-1, not PSR-2.

Hey Taylor, do you think at some point we could get an official Laravel 4+ Coding Standard documentation please? Even if it were a copy / paste of an aggregated PSR-0 / PSR-1.

Offline

#11 2012-10-22 16:12:34

gkunno
Artisan
Registered: 2012-07-10
Posts: 57

Re: L4 camelCase http://www.phptherightway.com/

Well this sure is quite unfortunate, I understand and support the unified coding standards. However I cant get my head around people who actually prefer the camelCase, it makes reading code much more difficult and irritating.


if ( thisLooksAppealing )
{
    youLikeCamelCase = true;
    votePoll( camelCaseFormatting );
}
else if ( this_looks_appealing )
{
    you_like_underscores = true;
    vote_poll( underscore_formatting );
}

Whats easier to read?

Offline

#12 2012-10-22 16:45:54

TLGreg
Artisan
From: Hungary
Registered: 2011-09-03
Posts: 739

Re: L4 camelCase http://www.phptherightway.com/

Actually only method names has to be camelCase according to PSR-1 and classes StudlyCase, class constants UPPERCASE_AND_UNDERSCORED. Other than that, like for example for properties, functions or variables the only thing it says is to be consistent and that remains even in PSR-2.

Laravel core coding style differs from PSR-2 at for example class brackets, in Laravel they are in the same line not on their own, control structures' and closures' brackets are in their own line not in the same, indentation is by a tab and not four spaces. PSR-2 also doesn't allow ternaries or other inline control structures, but Laravel uses them at many places.
What did I miss? smile

Last edited by TLGreg (2012-10-22 16:47:48)


Sorry if my English is bad. ^_^

Offline

#13 2012-10-22 21:45:42

JonoB
Artisan
Registered: 2011-11-09
Posts: 284

Re: L4 camelCase http://www.phptherightway.com/

TLGreg wrote:

PSR-2 also doesn't allow ternaries

I haven't seen or heard of this one before.

Offline

#14 2012-10-22 22:36:13

TLGreg
Artisan
From: Hungary
Registered: 2011-09-03
Posts: 739

Re: L4 camelCase http://www.phptherightway.com/

I should have added that "at the moment".
They are actually didn't mentioned explicitly, but they are control statements, which has the "closing braces MUST go on the next line after the body". Thus they are expected at block statements and validators also detects inline control statements as PSR-2 violations.
Hope they will be clarified soon.


Sorry if my English is bad. ^_^

Offline

#15 2012-10-22 22:39:32

ShawnMcCool
Quality Team
From: Utrecht, Netherlands
Registered: 2011-10-05
Posts: 535
Website

Re: L4 camelCase http://www.phptherightway.com/

camelCase in PHP is ugly because PHP is ugly. I've been bitching about it for a long time. But, it's not like we don't have viable options. I guess now it's either jump ship or just deal with it. I'm too interested in what Taylor is doing with Illuminate and the possibilities of Composer to stop now.


Note: I tend to speak in hyperbole.

About Shawn McCool | About Big Name | BigTo.Do - FreshBooks time tracking for to-dos | Laravel IO - The Official Laravel Community Portal

Offline

#16 2012-10-23 17:29:10

benjaminkohl
Artisan
From: Grand Rapids, MI
Registered: 2012-09-07
Posts: 17

Re: L4 camelCase http://www.phptherightway.com/

gkunno wrote:

Well this sure is quite unfortunate, I understand and support the unified coding standards. However I cant get my head around people who actually prefer the camelCase, it makes reading code much more difficult and irritating.


if ( thisLooksAppealing )
{
    youLikeCamelCase = true;
    votePoll( camelCaseFormatting );
}
else if ( this_looks_appealing )
{
    you_like_underscores = true;
    vote_poll( underscore_formatting );
}

Whats easier to read?

I absolutely agree. I love snake_casing my methods and using Allman-style indentation. I'm all for coding standards (to an extent) and I fully understand the reasoning behind Studly caps for class names. I've had to work with a lot of code written by other people and it never disturbed me that they had a slightly different style. I think people should just deal with the fact that some coding style preferences vary by developer rather than enforcing their opinions on others and branding it as "the right way". I hate that damn website. Of course, I am sure I'll just give in and change my tabs back to spaces and start placing my brackets inconsistently so we can all be consistently inconsistent.

I have really enjoyed Laravel 3 and the whole concept of bundles and how it was executed. I also think the bundles section of the site looks and behaves far better than Composer's Packagist website. That site is just plain UGLY and the package browsing/search sucks. How can THAT be the future of PHP? It just seems to me that Laravel will be sacrificing a lot of what made it unique and pleasant to work with for the sake of being consistent with other frameworks. That is disappointing to me because there is a reason I chose Laravel over other frameworks.

I do love this framework and I know I will continue to use it. I just figured I should voice my opinion about where PHP seems to be heading because I know there are a lot of people that don't like this new direction but not many people speak up about it because it makes us appear to be "anti-standards", which is an unfair assumption. Do I have an alternative idea in my head? No. But I will gladly discuss the formation a competing standard that isn't so pretentious like "PHP The Right Way". You can achieve interoperability without forcing people to abandon style.

Offline

#17 2012-10-23 17:36:02

ShawnMcCool
Quality Team
From: Utrecht, Netherlands
Registered: 2011-10-05
Posts: 535
Website

Re: L4 camelCase http://www.phptherightway.com/

Composer is the shit, and not because of any website. Its value will become more clear as everyone sees how Illuminate works.

And as a side note, I'm ALL FOR Allman-style and snake_case in situations where variable prefixes are involved ($, @, etc). Currently my code looks like:

    public function post_signup()
    {
        // validate form
        if( !SignupForm::is_valid() )
        {
            Alert::add( 'error', __( 'alert.form_validation' ));

            return Redirect::back()->with_input()->with_errors( SignupForm::$validation );
        }

        // validate user
        $user = new User( Input::get() );

        $user->type   = User::TYPE_STANDARD;
        $user->status = User::STATUS_ACTIVE;

        if( !$user->is_valid() )
        {
            Alert::add( 'error', __( 'alert.form_validation' ));

            return Redirect::back()->with_input()->with_errors( $user->validation );
        }

        $user->save();

        // send new user mail and login
        Mailer::send_new_user_email( $user );

        Auth::login( $user->id );

        Alert::add( 'success', __( 'alert.new_account_created', array( 'display_name' => $user->display_name )));

        return Redirect::to_action( 'dashboard@index' );
    }

Super non-standard and everyone but me probably hates it. But, that's where I've landed for now.

But, as far as PHP The Right Way. I think that it's just a reaction to the fact that PHP developers tend to muck everything up. I'm not saying that's you or me. I'm just saying, you ever inherited PHP code from a random contractor? Don't you wish they did things the "PHP The Right Way" way? As long as you understand WHY PHP The Right Way comes to their conclusions then you can you know... take some liberties I think. But, I don't think that site was targeted at people like you.


Note: I tend to speak in hyperbole.

About Shawn McCool | About Big Name | BigTo.Do - FreshBooks time tracking for to-dos | Laravel IO - The Official Laravel Community Portal

Offline

#18 2012-10-23 17:58:58

benjaminkohl
Artisan
From: Grand Rapids, MI
Registered: 2012-09-07
Posts: 17

Re: L4 camelCase http://www.phptherightway.com/

Shawn, I think your code style looks just like my style. I even place spaces between function parameters (or control structure conditions) and the parentheses like that (most of the time). That should be the standard! Just kidding. I think Composer itself is a good tool and the JSON that defines each package is great. I just think the Packagist website needs to be redesigned so that searching for packages or just browsing them is a more pleasant experience. It isn't an issue if I know exactly what I need to use, but sometimes I might think "I wonder if there is a package that does X". It should be more like the Laravel bundles site, basically. Also, Laravel's site is aesthetically pleasing to the eye. That helps. I'm a terrible designer but I can recognize and appreciate a good design.

Last edited by benjaminkohl (2012-10-23 18:00:01)

Offline

#19 2012-10-23 22:28:59

Xxp
Artisan
Registered: 2012-10-09
Posts: 55

Re: L4 camelCase http://www.phptherightway.com/

To sum it up, it would be nice to have a standard to how we as the Laravel Community format and write out code "The Laravel Way" just like Zend Framework has "The Zend Framework Way". It makes for overall cohesion between Framework developers and I'll gladly change my PHP coding style to fit with the framework coding standards. I did it with Zend Framework 1 and will do it with Laravel if there is a official documentation written by someone smile Ideally for Laravel 4+ since some standards have already been applied to the source.

I would love it if my code and any other Laravel 4+ code I looked at had the same syntax to that Laravel 4+ source code itself.

Then I could see a Sublime Text 2 plugin for Laravel 4+ Code Formatting in the works tongue

Offline

#20 2012-11-16 19:25:01

GaryJ
Apprentice
From: Basingstoke, UK
Registered: 2012-11-16
Posts: 2

Re: L4 camelCase http://www.phptherightway.com/

TaylorOtwell wrote:

That being said Laravel 4 follows PSR-0 and PSR-1, not PSR-2.

To make life a little easier for those who do want / need to write their L4 projects in PSR-2, would you consider having the app, public, artisan controller generator and other non-vendor directory code as PSR-2?


New to Laravel, v4 only.

Offline

#21 2012-11-17 00:12:15

Nacht
Artisan
Registered: 2012-07-09
Posts: 266

Re: L4 camelCase http://www.phptherightway.com/

gkunno wrote:

Well this sure is quite unfortunate, I understand and support the unified coding standards. However I cant get my head around people who actually prefer the camelCase, it makes reading code much more difficult and irritating.


if ( thisLooksAppealing )
{
    youLikeCamelCase = true;
    votePoll( camelCaseFormatting );
}
else if ( this_looks_appealing )
{
    you_like_underscores = true;
    vote_poll( underscore_formatting );
}

Whats easier to read?

The camelCase, because Java is the main language of my choice and I learned it that way wink

Offline

#22 2012-11-17 01:39:39

Night
Artisan
From: Uruguay
Registered: 2012-06-28
Posts: 34

Re: L4 camelCase http://www.phptherightway.com/

PHP is lowerCamelCase, Java is too and both are ugly. Just saying

Last edited by Night (2012-11-17 01:46:10)

Offline

#23 2012-11-17 17:31:24

TommyC81
Artisan
Registered: 2012-05-27
Posts: 41

Re: L4 camelCase http://www.phptherightway.com/

Just stick to a standard, whatever it might be. Preferably PSR-2 as it is in fact coming along as an overall standard for coding. Maybe it's not the way I do things right now, but give me a week and I've changed my ways and adapted. Will make life so much easier in the long run.

Offline

#24 2012-11-17 20:00:01

Anahkiasen
Artisan
From: France
Registered: 2012-07-07
Posts: 241
Website

Re: L4 camelCase http://www.phptherightway.com/

I prefer camelCase and I've never made any Java before or anything. You guys need to stop thinking just because you think one is easier to read, that everyone thinks so.
PSR standards weren't just brought out arbitrarely — it was a democratic votes between ~25 of the most influent PHP developpers. People behind PEAR, Symfony, CakePHP, Zend, Drupal, Joomla etc. If camelCase won in the end it means of all those developpers a majority of them thought it was easier to read.

And I agree that if there is a standard in place, whatever the language, stick to it. Don't think about yourself, think about other people trying to read or alter your code. The more uniform everyone's code is, the easier it will be to find your way in a random person's code.

Last edited by Anahkiasen (2012-11-17 20:01:50)

Offline

#25 2012-11-17 21:21:43

Night
Artisan
From: Uruguay
Registered: 2012-06-28
Posts: 34

Re: L4 camelCase http://www.phptherightway.com/

Anahkiasen wrote:

I prefer camelCase and I've never made any Java before or anything. You guys need to stop thinking just because you think one is easier to read, that everyone thinks so.
PSR standards weren't just brought out arbitrarely — it was a democratic votes between ~25 of the most influent PHP developpers. People behind PEAR, Symfony, CakePHP, Zend, Drupal, Joomla etc. If camelCase won in the end it means of all those developpers a majority of them thought it was easier to read.

And I agree that if there is a standard in place, whatever the language, stick to it. Don't think about yourself, think about other people trying to read or alter your code. The more uniform everyone's code is, the easier it will be to find your way in a random person's code.

If I have to work in group I'll use the style that majority uses, or those who're recommended to. But doesn't means that coding style is better.

For example, I'm a big fan of Fabien (Sf), he has done really good work but it's (for me) hard to read his code because of his coding style. That's not a problem when I read the Laravel's code.

The only think I like for the PSR are the namespacing style. If Laravel becomes camelCase I'll HATE IT, just kidding, I'll keep writing Laravel in camelCase smile

Offline

Board footer

Powered by FluxBB

');