-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Thoughts on lowercase const names? #1382
Comments
If V is serious about immutable by default and consts are the only globals, then these should be the easiest to write and read. The best option is lower case. |
Also in order to distinguish consts from local variables, full path can be required: |
I think |
Personally I like Pascal case. But if you don't like that then either all caps or maybe all lowercase but must maybe start with, or start and end with an underscore (
|
BTW |
The default is immutable; if there's special syntax for exceptional values it should be for mutable values, not const values. Functions are immutable: all lower case. Consts are immutable: all lower case. Variables are by default immutable: all lower case, unless made mutable. Etc. |
@ntrel in V that's exactly what
The definition of consts is different in V. They do not need to be known at runtime, they are basically immutable global variables with a defined value. They could be differentiated, but that would complicate the language, and I don't really see the benefits. |
That gives a misleading impression, they should be called
V could read compile-time constants with Go allows fixed-size arrays to be declared with a compile-time constant: |
@ntrel I've just implemented that. |
Ok, great. But there is a difference between compile time constants and immutable globals: const (arr = [1, 2])
a := [arr.len]int
|
This may sound like a minor issue, but it's actually a pretty important one.
There will be lots of consts in V code since there are no globals, and consts are a lot more powerful than in other languages.
There are 3 options:
ALL_CAPS
This is great in languages like C, where you can only use it for primitive values.
But in V half the code base would now be SHOUTING_AT_YOU. And
os.ARGS[1]
orMY_CONST_ARRAY.do_something()
just look ugly.PascalCase
This is the one currently used. It's also used in Go.
I don't like it because, again, it forces to use a different naming style for a huge part of identifiers, and consts can now be confused with types.
Current
os.args
would have to be renamed toos.Args
, and this doesn't feel right to me.lower_case
The only problem with this is consts are now indistinguishable from variables. But that's already the case with mutable vs immutable variables, and consts are basically just module level immutable variables.
ALL_CAPS for primitives (ints mostly), lower_case for everything else
What do you think?
The text was updated successfully, but these errors were encountered: