0

Is it poor practice to not use spaces between parameters in a scripting language (or any for that matter)?

With spaces:

def does_a_thing(x, y):
    ...

does_a_thing(5, 9)

Without spaces:

def does_b_thing(x,y):
    ...

does_b_thing(1,2)

I have seen it done both ways and personally prefer using spaces as it shows more readable.

Are there situations where either style should be preferred?

5
  • Readability is always preferred. the compiler or interpreter couldn't care less. Commented Nov 11, 2016 at 23:18
  • I like lots of white space as it improves readability for me. Of course, I compress script for distribution, e.g. use Google's closure compiler. Commented Nov 11, 2016 at 23:26
  • 1
    I didn't know we have a tag for whitespace! Commented Nov 11, 2016 at 23:27
  • I prefer as much whitespace as possible. I normally measure whitespace in gigabytes. Commented Nov 12, 2016 at 3:45
  • How do you use whitespace in plain written text? You, use, whitespace, after, comas, and, after, a, fullstop. Do that in your code. Commented Nov 13, 2016 at 6:47

2 Answers 2

3

Are there situations where either style should be preferred?

Yes. If the rest of the code base uses spaces then use spaces. If the rest of the code base doesn't use spaces then don't use spaces. It's called consistency.

Trivial things like this matter. Not because one is so much better than the other. But because watching style change from one to the other is distracting and I have better things to be thinking about than this.

0
1

Easy:

  1. What is used by your team? Keep your style consistent with your colleagues.

  2. If there is no team (for instance the project haven't started yet), then use the style commonly used in your company.

  3. If there is no previous usage (for instance your company never used a specific programming language), then use the official style for a giving language. Languages such as C# or Python do have an official style.

  4. If there are no official style, as it is a case in JavaScript, use either a convention published by a well-known company, or a style which appears to be popular when looking at open source projects.

In all cases:

  • Don't reinvent the wheel: don't invent your own style, because (1) it requires an excellent knowledge of the language, (2) is difficult to do well, (3) won't be known by other developers and (4) is subject to criticism from your peers.

  • Enforce the style automatically. The best choice is to make your IDE behave in a way that developers would not have to think about style in the first place. When impossible, at least check the style automatically through the pre-commit hook.

  • Remember that the existence of style rules matter much more than which rules are used. In other words, what is important is consistency, not that you put braces on a new line or the same line or that you use tabs or spaces.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.