Variable declaration versus assignment syntax

Posted by rwallace on Programmers See other posts from Programmers or by rwallace
Published on 2013-10-27T19:12:42Z Indexed on 2013/10/27 22:00 UTC
Read the original article Hit count: 303

Working on a statically typed language with type inference and streamlined syntax, and need to make final decision about syntax for variable declaration versus assignment. Specifically I'm trying to choose between:

// Option 1. Create new local variable with :=, assign with =
foo := 1
foo = 2

// Option 2. Create new local variable with =, assign with :=
foo = 1
foo := 2

Creating functions will use = regardless:

// Indentation delimits blocks
square x =
    x * x

And assignment to compound objects will do likewise:

sky.color = blue
a[i] = 0

Which of options 1 or 2 would people find most convenient/least surprising/otherwise best?

© Programmers or respective owner

Related posts about language-design

Related posts about syntax