Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer nil for empty lists over () or '() #50

Open
Fuco1 opened this issue Aug 28, 2018 · 2 comments
Open

Prefer nil for empty lists over () or '() #50

Fuco1 opened this issue Aug 28, 2018 · 2 comments

Comments

@Fuco1
Copy link
Collaborator

Fuco1 commented Aug 28, 2018

There are essentially 5 ways to "initialize" a list

(let (results)
  (--each ... (push x results)))

(let ((results))
  (--each ... (push x results)))

(let ((results nil))
  (--each ... (push x results)))

(let ((results ()))
  (--each ... (push x results)))

(let ((results '()))
  (--each ... (push x results)))

Personally I use 2 and 3 and prefer 2 if there are multiple bindings at the same time

(let ((x 1)
      (y 2)
      (results)
      (z 3))
  (--each ... (push x results)))

Having it wrapped in the parens sort of signifies to me it's a list. A nil there wouldn't hurt though, I'm just lazy.

I was hoping there would be some way to distinguish () and nil for example for the purpose of analysis but they both appear as nil to the reader, so meh.

@bbatsov
Copy link
Owner

bbatsov commented Aug 28, 2018

I generally go with option 2, as then it's easy to add more non-empty elements to the bindings, but I agree that 3 & 4 definitely read better. I'm fine with suggesting the use of nil, although I don't think we should discourage ().

@mngb
Copy link

mngb commented Oct 13, 2024

I think the 4th one is better. The 2th in this case: results's initial value will not been care about. The 3th in this case: results is a variable, a object, a interger etc. But not a list, despite nil == (). The 4th one in such case: results is a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants