odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.55k stars 570 forks source link

Reduce number of range and slice operators #239

Closed gingerBill closed 6 years ago

gingerBill commented 6 years ago

Current:

x[a..b] // half-closed
x[a...b-1] // open
for i in 0..N {} // half-closed
for i in 0...N-1 {} // open
switch x {
case a..b: // half-closed
case x...y: // open
}

Proposed:

x[a:b] // half-closed
for i in 0..N-1{} // open
switch x {
case x..y: // open
}

Rationale: removes confusion between .. and ... and adds familiarity for slicing from languages such as Python and Go.

Tetralux commented 6 years ago

This strikes me as a good idea, despite having two very different operators for similar things.

The familiarity from slicing languages is a decent idea; the difference will be easier to remember and work with because of the Python/Go reference

If you're a C-only programmer, then it won't be so obvious, but still. In my experience, the open range is normally what you want, and is clearer because of the explicit N-1, so I'd personally prefer that to be ...

With this change, both operators are short to type... Three dots always felt a bit much to me.

On Wed, 1 Aug 2018, 15:07 gingerBill, notifications@github.com wrote:

Current:

x[a..b] // half-closed x[a...b-1] // open for i in 0..N {} // half-closed for i in 0...N-1 {} // open switch x { case a..b: // half-closed case x...y: // open }

Proposed:

x[a:b] // half-closed for i in 0..N-1{} // open switch x { case x..y: // open }

Rationale: removes confusion between .. and ... and adds familiarity for slicing from languages such as Python and Go.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/odin-lang/Odin/issues/239, or mute the thread https://github.com/notifications/unsubscribe-auth/ABST0Fe2fhKv7BhmhZXxKECa24oqxTk6ks5uMbY7gaJpZM4VqkZY .