Jyte is now owned by AboutUs. Read all about it here.

There should be no space between a function name and the paren that starts the argument list.

By 8 Rorek on February 07, 2008

i.e foo(bar, bam, baz) not foo (bar, bam, baz)

A space after the open paren is acceptable.

Embed Claim Make a related claim

Discussion (16)

http://fixedd.com/

4 fiXedd who agreed, says

but how do you feel about curley brackets (braces) after the function list? same line or not?

eg.

foo(bar, bam, baz) {

or

foo(bar, bam, baz)
{

Make a related claim over 2 years ago (link)
http://rorek.org/

8 Rorek who agreed, says

I'm agnostic in that regard, as long as it's consistent. I feel it's clear either way.

Make a related claim over 2 years ago (link)
http://rorek.org/

8 Rorek who agreed, says

However I do feel strongly that the closing brace should be on it's own line.

Make a related claim over 2 years ago (link)
http://fixedd.com/

4 fiXedd who agreed, says

agreed.

Make a related claim over 2 years ago (link)
http://armormatic.com/

1 armormatic.com who agreed, says

foo( bar, blee, baz ) {
...do stuff...
}

I do like spaces between the opening paren and first element of the list as well as between the last element and paren, though.

Objections?

Make a related claim over 2 years ago (link)
http://darch.myopenid.com/

6 D'Archangel who agreed, says

Parens should tightly surround their contents. Spaces immediately inside parens creep me out; to my eye, they serve no purpose of distinction and actually make code harder to read while I try to figure out why there is a space there.

I also distinguish between function calls and special forms; if "foo" were a keyword, I would want a space between it and the list.

My reasoning in both of these cases is grounded in how I chunk code. Arguments are a list; the parens define the list and are therefore part of it and should be physically close. A function call without parens is not a function call but merely a bare identifier; the parens are part of make it what it is, and should be close to it. The condition of an if statement is not part of the if statement in the same way, and if you leave it too close to the keyword it might look like a function call. So let's make it visually distinct by putting a space there.

That run-on paragraph is in that form because it's a sort of recounting of my stream of consciousness on the subject.

D'A

Make a related claim over 2 years ago (link)
http://rorek.org/

8 Rorek who agreed, says

D'A: I sometimes put a space to separate a nested function call to make it easier to count parens on the right, and then I put a space on the left for symmetry.
e.g. foo( bar, bam(baz, bif, biz) )

Make a related claim over 2 years ago (link)
http://rodney.id.au/

No_score rodney.id.au who disagreed, says

Just go with the flow, dude.

Make a related claim over 2 years ago (link)
http://rorek.org/

8 Rorek who agreed, says

Rodney: I agree that it's best to follow coding conventions with whatever project one is working on. This claim is about which convention is better.

Make a related claim over 2 years ago (link)
https://me.yahoo.com/a/eJvM_d520fcYasqbSWFQVLMeqZKX4q2phIRH55WSZnM-

No_score Bruno De Barros who agreed, says

Well on PHP I can use function(args, or I can use function (args... PHP doesn't really care about that. I agree though, I don't like spaces -.-

Make a related claim over 2 years ago (link)
http://rorek.org/

8 Rorek who agreed, says

Idon'tlikespaceseither.Theyareevil.

Make a related claim over 2 years ago (link)
http://bcat.name/

9 Jonathan Rascher who agreed, says

I like to put a space before the opening paren in a function's definition. Otherwise, I think the definition ends up looking too much like a function call.

Make a related claim over 2 years ago (link)
http://rorek.org/

8 Rorek who agreed, says

JR: I find there are enough other cues that there's never that confusion.

Make a related claim over 2 years ago (link)
http://bcat.name/

9 Jonathan Rascher who agreed, says

OK, I've finally given up on this.

Make a related claim about 2 years ago (link)
http://encryptio.com/

1 Chris Kastorff who hasn't voted, says

Depends on the language - in C-like languages sure, but others not so much. Lisp, Factor, and Haskell come to mind.

Make a related claim about 2 years ago (link)
http://darch.myopenid.com/

6 D'Archangel who agreed, says

In Lisp:

(+ 1 2 3)

No space.

I won't speak to the other languages you've mentioned, but I'm guessing you're as reliable there as wrt Lisp.

D'A

Make a related claim about 2 years ago (link)
Sign in in to leave a comment.