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

Low priority proposal: Shorten 'const' to 'cn' #5215

Closed
ghost opened this issue Apr 29, 2020 · 8 comments
Closed

Low priority proposal: Shorten 'const' to 'cn' #5215

ghost opened this issue Apr 29, 2020 · 8 comments

Comments

@ghost
Copy link

ghost commented Apr 29, 2020

Related: #5076

Cons:

  • cn needs context to be associated with 'constant declaration', while 'const' is self explanatory
  • cn vs fn. not as distinguishable as const and fn
  • Syntax highlighting becomes more essential
  • No use case requires this kind of syntax change
  • "Indentation" is the same for if and cn
    • Might warrant different syntax highlighting for cn vs if/else/switch/while

Pros:

  • cn is shorter than const
  • cn is also shorter than var
  • const appears very frequently in code.
    • Making the connection between cn and 'constant declaration' will happen quickly for newcomers.
    • Makes sense to keep the most commonly used language keywords the shortest
  • Grammar change only. semantics stay the same.
    • Could allow both cn and const in a transition period, and let zig fmt convert to the new form in the meantime
    • Very easy to both implement and retract if it doesn't work out
  • Immutable slices will look nicer []cn u32 vs []const u32 in that the type will stand out more than the immutability qualifier.

An alternative to cn is df for define, but []df u8 doesn't work, whereas []cn u8 is permissible. Related: #5056

@data-man
Copy link
Contributor

cn is too long. c is better and isn't China.

@ghost
Copy link

ghost commented Apr 29, 2020

So we have v and c? Sounds good.

@ghost
Copy link

ghost commented Apr 29, 2020

Or maybe var and con?

@SuperAuguste
Copy link
Contributor

I dislike this proposal a lot as const is much more intuitive to the programmer and reader, compared to c, or con, or cn, which could be very confusing, and sometimes hard to spot.

One of Zig's Zens is "Favor reading code over writing code.", and in my opinion, this change would violate that Zen.

@SuperAuguste
Copy link
Contributor

Oh, and it might also violate:
"Communicate intent precisely.", as const is much better at communicating the creation of an constant than the shortened alternatives.
"Only one obvious way to do things." as c, con, or cn aren't very obvious, and adding a transition period would violate this Zen, and maybe even confuse newcomers.

@ghost
Copy link
Author

ghost commented Apr 29, 2020

By the (-1) reactions I suppose const is too established by now to be replaced, and it's also perfectly fine to keep it as it is. The issue can be reopened if there's any renewed interest later.

@porceCodes
Copy link

porceCodes commented Jan 6, 2025

Ergonomics view:
var 3 letters, const 5 letters.

var x: u8 = 10;
let y: u8 = 20;   // 3 letter case
const z: u8 = 30; // 5 letter case

let is from Swift

@mlugg
Copy link
Member

mlugg commented Jan 6, 2025

let has already been rejected: #181

@mlugg mlugg closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
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

4 participants