Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJason Anders
Treehouse Moderator 145,860 PointsSpace after comma? ... or not?
I'm about half way through the "Build a Basic PHP website," and I've notice that Alena Holligan doesn't use spaces after the commas.
Eg.
echo get_item_html($id,$item);
As opposed to
echo get_item_html($id, $item);
As an editor by trade, I'm finding this a very difficult habit to acquire. My question is... Does it matter? Is this just a personal convention? Or, is this something that needs / should be done in PHP? I've noticed both work when compiled, and I've seen both used in code.
Just wondering, because this will be a very hard convention for me to adopt.
Thanks guys!
2 Answers
Seth Kroger
56,413 PointsNo it doesn't matter. Languages with C-ish syntax are pretty ambivalent about whitespace. Unless it's required to separate names/keywords it doesn't need to be there. But whitespace does help us to read and understand the code. All the whitespace rules are are conventions of varying degree of adherence to make code more legible. And as conventions, there will always be a bit of personal variation.
I'd say that if you're more comfortable with spaces after commas, stick with it. You'll be in good company.
Jason Anders
Treehouse Moderator 145,860 PointsThanks Seth.
Alena Holligan
Treehouse TeacherI'm just lazy ;) and PHP doesn't care about white space
Jason Anders
Treehouse Moderator 145,860 PointsHaha... Thanks. :)
Farouk Charkas
1,957 PointsFarouk Charkas
1,957 PointsI am not sure, test both lines and see if they create any trouble :-)