-
-
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
Simplify Keywords and Syntax where possible #1718
Comments
To be honest I would even prefer generic functions for in-/output where you just need to specify the interface (terminal, file, sockets, etc.) instead of having several functions with different function names :) |
They are distinct types ATM. I filed an issue here about true aliases, which Go supports. rune should still be a distinct type, see that issue.
The |
const is a compile time constant, like an enum but without being part of a sequence or namespace. An immutable variable can be initialised by runtime data, so the compiler doesn't know its value. |
I'm totally new to v but a professional programmer since more than a decade and this is something I absolutely second.
V should drop aliases entirely. It would make the language far more consistent to read. I'd like to insist that it would make the language and the compiler even more complicated when you can define your own types not only for rebadging existing ones. |
I don't think they do any harm at all when implemented the right way. See the following example which should work: module main
fn main() {
x := int(5)
y := i32(6)
print(x == y)
} ...but instead gives you: So in summary it seems like the compiler threats them as different types... An alias shall be just another name to the same type - or even arbitrary name (function, variable, ...) what do you think? |
+1. This is very useful for generic programming. |
@ALL Please don't feel offended by my strong opinion. Discussions like this help to understand each other.
In the current state of the compiler/language the above mentioned example error is wrong compared to what the documentation says. An alias is just another name for the same thing. So I'd expect too that it should compile. But there is absolutely no need to do this (to alias your basic data type) in a completely new language. @ntrel See also the FAQ on vlang.io about macros: No, sorry. Macros can be really useful, but they complicate the code significantly. Every company, team, developer can extend the language, and it's no longer possible to jump into a new codebase and immediately understand what's going on. V will have sophisticated code generation." And when 'int' is always 'i32', why is it there in the first place (three alphanumeric characters but one is way more specific [i32])? Recall that v is f#*@ing fast at compiling and I do hope that will stay that quick. If you put aliases in that quotation it'll become as slow as Rust. IMHO: Generic programming is something where the compiler has to analyze the code more to insert/generate one-the-fly and use the appropriate code when compiling your source. This seems to match the following quote (shamelessly stolen from Wikipedia and checked in PDF): |
I don't like having i32 + int and i8 + byte I'd like to have i32 and i8 removed, because I prefer Aliases can be a useful and powerful tool. For example, Go's |
By the way we shouldn't be calling |
It proposes only better reading or did I get something wrong? Good work anyway! |
It's more readable and safe than using |
So to sum it up I agree that aliasing is bad, and existing aliases Subtyping is different and should stay. |
Then it is not aliasing anymore. It's inheritance/subtyping. Damn you're fast! |
Possibly the types could made a bit more verbose so there is no need for aliases, like: Of course we do not need "byte", "short", "long", "double" etc. as it is expressed by the numeric width. |
i(8|1632|64|128) |
As clarified by @medvednikov this is something I did get wrong in the first place. Thus I agree with you @medvednikov and @avitkauskas that subtyping is something v should support, but not doing this with the aforementioned basic data types when there's no need. I can not repeat it enough: Keep up the good work! I consider to donate on a monthly basis beginning with this years december. |
This is #983. |
Aliases are useful when aliasing a long expression. They are also useful in a compile-time if block to alias to different symbols depending on a compile-time test: $if windows
{
alias myfoo = win32_foo;
}
else $if linux
{
alias myfoo = linux_foo;
}
Actually they are useful for aliasing template instantiations: alias IntTree = btree.BalancedTree<int> Aliases can even have template parameters themselves: alias Foo<T> = SomeTemplate<T, T.sizeof> |
See this comment about why Go has it: |
Absolutely agree, that the Go's notation is not well chosen, would it be possible to have a really clear aliasing using something like this (or similar definition):
and you would be able to inspect its type e.g. by: |
And of course you'll have to dig deep for every project you're involved in what aliases are set in order to understand the code/library/you name it. One can alias in every single source code holding file to a different name as it is possible to do so. And it will happen that way. So no, to alias is a bad habit. I have currently a project where they "live" that habit for over two decades (luckily only variable names as OpenEdge ABL doesn't support alias of data types) and it is tremendously hard to get through. Think a little longer when naming something. We have 2019(!) and almost any editor or IDE has some sort of autocompletion. Subtyping is something I understand that it is useful because you can add additional methods to the new type as mentioned by @medvednikov , but aliasing is simply renaming an existing thing and one use case of yours shows me that code which uses this will be very hard to understand because you are able to change the syntax. This is a possible source of fault. Gradually changing a code base could be done with different methods. in the time where both aliases are allowed you will find in the wild projects that become a mess because they'll use both types even in one source code file. I have seen this. IMHO. |
It doesn't change syntax, it simply wraps a template instantiation.
How so? |
That's why compilers have a command-line option to make deprecated symbols cause an error. You are also ignoring the case where the original symbol is private and only the alias name is public. It's an encapsulation tool. |
Used the wrong word (syntactically) for that - it has a broader meaning in german. What I meant was the following: |
This is exactly what I don't want in this language. Keep it simple stupid. It just adds complexity where no complexity is necessary.
Well, actually it then was private for a reason. Now you 'opened the gate'. Encapsulation with aliases? Seriously? It's more an 'override-the-developer-intention-because-i-want-to-do-so' tool. If one want to encapsulate something one make it private for a reason. Mainly because one don't want other objects/developers to use it in 'the wrong way' or urge them to use it via an API. |
Of course aliases are just another names for the same types, so they would have the same access modifiers as their original types - everything else would add complexity and endanger safty |
Primitive aliases were removed from the language. |
I suggest to not pick up lagacy too much and not to use rundandant keywords/aliases.
Examples:
Example 1:
So, how such an compiler error msg is even possible:
field value #1 'val' has type 'i32', got 'int'
when they are just aliases?Instead predefining aliases to primitive types (just because you know them from c), allow creating aliases to types in general
Example 2:
strictly speaking predefined functions like
println('')
are redundant (in this case toprint('')
. as "new line" is just another character), it shall be easy to define ownprintcrlf('')
or whatever when neededExample 3:
could be defined and clear anough as:
Example 4:
for i := 0; i < 10; i++ {}
loops seems also redundant and limiting (e.g. in case you need more than one "running" variable or multiple iterating statements or is it possible to use something like:for i := 0, j:=10, k:='a'; i < 10 && j > 5 || k != 'a'; i++, j-- {}
Example 5: possible inconsistency: why
const ()
is a function and not an access modifierconst:
? please also explain in more detail the difference between const und immutable in the tutorialExample 6: inconsistent boolean values
actual output is ==>
1
If I get more familiar with the V syntax I might propose more of those. It is worth to check out the https://www.ponylang.io/discover/#The-Pony-Philosophy as an good example
The text was updated successfully, but these errors were encountered: