-
-
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
Syntax for access modifiers #64
Comments
Perhaps formatting should be different:
|
most readable for me
|
Yes, perhaps. Functions:
|
same with functions |
I agree with @whoizit suggestion. |
Good point, let's do it this way. |
why not using keywords? |
I like the approach of Go and Oberon to achieve this without keywords. Adding more keywords increases complexity of the language, and the definitions would look a lot more verbose:
|
oh, that makes sense |
It would be also handy to allow minus as word separator in names. It is more readable than underscore.
|
Yes, that would be nice, and I had precisely the same idea. Unfortunately it's not possible. I don't want to make a whitespace sensitive language, and I want it to be similar to C/C++ and Go. This would be too big of a change for all these developers. |
All these languages suffer of Words separated by dash are bit more readable than with underscore. (I noticed this in Lisp code.) Traditional typography employs en dash ( If arithmetic operators always require spaces around, then it won't be confusing for the reader. There's low chance of accidentally joining two words and making valid symbol, which then even compiles. |
I assumed that, but I would like V to allow overloading only on number of arguments. This is a lot simpler than C++ overloading, no complications about
If we're using symbols for this, I think the same syntax for public and private should apply to functions and types. The default could be public, which for fields means read-only [outside the struct module] (to follow your design). Then fn public_func(){}
fn -private_func(){}
struct -private_type{}
struct public_type {
read_only_public_field T
-private_field T
+read_write_public_field T
} |
Immutable struct fields by default got a lot of support:
|
Yes, where I wrote |
Good point, this is the 5th option, and it's not handled. So perhaps Oberon's readonly
This is getting a bit complicated...
The default is private in all major languages, it's not going to change. The default must always be private. |
There will never be function overloading: |
It is straying off topic, but: There are valid reasons why function overloading got a really bad name:
If these mistakes are avoided, function overloading wouldn't be seen as a monster. There are natural uses of overloading - math functions like sin/cos/etc. Even C realized it and attempted to add it into the language with C11. Unfortunately, they had chosen Function name overloading has one not so obvious advantage - it reduces the pressure to use unreadable One also could take inspiration in Smalltalk, and use function parameter names as part of name resolution.
|
OK.
Read-only field syntax without mutable data should be an error, it's correct if But should functions and type names be public or private by default? If private then |
The plus and minus look like operators. I find this extremely confusing and noisy - the meaning of plus and minus aren't naturally understood as anything other than operators, so this is a bit too creative for my taste. Fewer characters do not necessarily make something easier to parse for a person. We're used to words like "public", "private", "internal" etc. from english language - and if not from there, then from other programming languages. It seems like you're struggling to make everything as few characters as possible? I think that's misguided. In my opinion, readability of code is much more important than how many characters you have to type - simply having having characters does not automatically make a syntax more readable. Think regular expressions. Most people needs weeks to months to learn the basics. Whereas most people learn to read languages like Java (while it does tend to be overly verbose) almost immediately - even if they don't learn the meaning of the keywords, anyone can immediately identify the keywords, which gives them at least a way to automatically associate terminology with keywords, so they can ask questions, do a search or talk to more senior coworkers about them. Compounding everything down to symbols (worse, ambiguous symbols) increases the density of the code, which isn't automatically a good thing. Keywords aren't just noise - when used properly, they reduce the density and add to the semantics of the language. Be careful not to compress the syntax to the point of obfuscating. |
I think the concerns of @mindplay-dk are valid and need to be considered. Though I personally actually prefer a symbol based system as it reduces the verbosity by a quite large amount compared to "private, internal, public" keywords. I also think it's important to remember that whereas fewer numbers of character doesn't, on its own, make for more readable syntax the opposite is also true. Otherwise we'd all be coding in COBOL-like languages. I suspect that it's quite hard to know for sure which syntax would be more intuitive. While I get the idea of the regex comparison I don't think it's a very good comparison in this case. I'd personally like to argue that if you're a beginner it's not very clear what you can do to a "protected internal" property in C#. You need to know more than the dictionary definition of the actual words. And therefore I'm really not convinced that it's much harder to instead learn the contextual meaning of two or three different symbols. But that's just my personal thoughts, not backed by any reliable sources at all. |
I agree, it does reduce verbosity. But it does so at the expense of readability due to increased visual ambiguity - words are unambiguously recognized by the majority of the population, possibly with the exception of dyslexics; most of whom do learn to read today, and/or can memorize the spelling of a few keywords. Even non-english speakers who know the latin alphabet learn to read and write keywords. Learning the meaning of arbitrary symbols is harder - especially when those symbols are ambiguous. Being able to visually scan and read code is extremely important. While verbosity is of course also a concern, you shouldn't barrel down on that problem, or any single problem, at the expense of everything else. Good language design is about balancing trade-offs. Are you sure that's what you're doing here? It seems to me like you're asking a lot of new users - be careful not to compress and obfuscate the syntax to the point that too many will just look at this and dismiss it outright. Most newcomers will already know another language, and will recognize common keywords with a common meaning from most other mainstream languages. I'm all for trying new things, but in my opinion you're trying to innovate something that doesn't really need innovation, and making some detrimental trade-offs in the process. |
sorry, are you seriously!!? what the 'hell' syntax?
Agree with this, but i'm not the big fan of keywords too, cause it's more verbosity. I wonder why nobody to recommend the design of Golang, capitalize the first letter or not. |
I agree about the problematic ambiguity that comes with using the proposed + and -. I also think that the proposed meaning of the minus sign is far from obvious. But I think it'll probably be hard to come up with other symbol based modifiers that will be better and more intuitive. Though I still think that using "public" and "private" keywords does not feel like a good fit with the general syntax of V. Then I agree with @han2015 that it's worth considering Go's naming convention, considering that V is already sharing many similarities with Go. |
In generic code it's very helpful to have type names Capitalized and variables starting lowercase. Otherwise it takes longer to work out what's going on in the code. For this reason I don't want to see Capitalized function names. If we want to change the symbol identifier itself to signify access, I'd prefer I don't think traditional attributes are necessarily verbose: e.g.
I missed this comment before, so with this syntax functions are private by default. With |
If the concern is sheer verbosity, a few languages opt for sectioning instead of annotations - for example:
This is visually unambiguous, and non-repetitive when you have to list 10-20 public or private fields. |
Yes, this is an option. If we use C++ syntax and skip
Everything is going to be private by default. It's simpler, and that's how it works in all other languages. |
@medvednikov that looks really nice and functional 👍 |
Yes, I like it too, and I even prefer the full names |
Most variables shouldn't be mutable anyway. |
Mutable version being more verbose might encourage people to make their variables immutable where possible. |
Idk, but i didn't like this approach. too much things to typing with keyboard XD |
@arhen this version is not going to be a lot more verbose when you have many fields:
|
Just my 2 cents, how about using
|
The sectioning example with private by default is by far my favourite this far, feels more clean and convenient than most other alternatives. |
if we reduce function to fn, then we should reduce and public to pub and mutable to mut. But then it will be Rust) |
Yeah, I agree with this in the end.
|
This makes everything public by default, which is undesirable. Also the majority of the module's code now has method calls starting with |
I like it. |
@medvednikov why did you go back on this in your last examples? Please use proper words. |
@mindplay-dk if it is a |
@mindplay-dk I decided not to change anything for now. I realized I was spending too much time on this. I need to finish lots of projects before the end of April. It will be trivial to change the syntax in the future with the help of |
I have a small suggestion, if you should choose to go the symbol route. I know that there was some discussion about using '!' with generic types, but what about prefixing ann identifier with an exclamation for external visibility (exported)?
But I rather prefer:
This idea is derived from Dylan, where it is convention to end a binding identifier with '!' if it destructively modifies its arguments. |
The syntax has been decided. Thanks for your input. |
Here's what I currently have in mind:
What do you think?
edit
Slight improvement:
edit 2
Immutable struct fields by default got a lot of support:
The text was updated successfully, but these errors were encountered: