-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
crazy idea: change the type
keyword
#19157
Comments
Making the word |
I do like |
If this is done, it should be done ASAP so that it can be included in |
If this is going to happen, than use what everybody recognizes before thinking: |
I also think |
I thought +1 for |
Thus struct is related to both. I think |
Any variable is mutable. Assigning that label to a universally recognized name (a |
For someone coming from Fortran the keyword So maybe we should leave it as is. |
or
if a more descriptive form is desired. |
If we use I suspect Fortran programmers are familiar with the term "struct". |
+1 for |
I think |
I should clarify that I think |
Having to add the |
Otoh, I believe Fortran has a |
@KristofferC above has it right: I also find myself saying "struct" when explaining what this is. Even in internal discussions |
If these names are really on the table ( Just as a thought, another possible term for mutable might also be |
Another possible name would be |
👍 to noun(s) |
I always liked
Imagine introducing a newcomer to
Probably worth noting that Latin-language-family adjectives like "mutable" are grammatically also allowed to be nouns in there own language. That's why when we ask "what is the noun form of mutable" we shrug our shoulders. But we always say "a variable" and in Julia-speak I would say "let's introduce an immutable for this". Unfortunately it feels awkward at first because of the Germanic roots of English grammar - but this happens really often in English (because we are also based on French and Latin) but you get used to it with time. Finally, since the topic is "crazy idea", these keywords more-or-less construct a new # Similar-ish to current
MyType = DataType(
a::Int,
b::Float64
)
# A DataFrame-like constructor
MyType = DataType(a = Int, b = Float64) I guess these would have to be specially (statically) parsed like |
Right... I think I was thinking of Swift, where:
which sounds like |
I agree the adjectives can in practice serve as nouns. One can say e.g. "this is an immutable". I just think they are insufficiently descriptive. Rather than telling you what the thing is, it just tells you that whatever it is, you can/can't mutate it. |
I like Edit: maybe |
Or a version that involves having fewer keywords would be |
That's a good point - but I would consider the referencing behaviour vs "value" behaviour much more important and interesting to describe than "is it a struct or a bitstype?" (mostly because To completely obviate the need for immutable 32 Int32 <: Integer or you could have un-adorned fields as number of bits immutable Int32 <: Integer
32
end which (in general when mixed with named fields) could also be useful for inserting padding when necessary. Then it's just a choice between a value type (what is currently immutable) vs a reference type (what is currently mutable - but potentially with |
It's true that We originally picked |
No renaming of this keyword would do that. Those issues have to do with static checking and casts, which aren't involved here at all.
I don't fully understand this. If an object is immutable there's no way to tell whether it's passed by value or reference, so how can the value/reference distinction be fundamental?
|
@JeffBezanson, with C-like const-ness I meant the possibly implied expectation of the Julia type to have same behaviour as in C/C++: immutable only after construction, modifiable anyway through casting, sometimes being without effect at all for function arguments or return types. Thus, when choosing keywords probably not refering to C/C++ is a good choice, hence please not Regarding 'value vs. reference': It took me quite a while to understand why an immutable type embeds the members directly and produces nice and compact fast assembler code, but 'type' didn't and still contains all the calls to objects. Or in other words, why I would typically want to use an NTuple when aiming for speed. Thus, when reading 'immutable' and 'mutable' I'd have expected the meaning as a 'parameter' in Fortran, but not also the change in the layout or kind of implementation of the actual datatype. However, that was my experience when learning the Julia low-level machinery to obtain fast assembler code, but I don't know how to better reflect that in naming keywords and how to combine or express that just with mutability. |
I get where you're coming from @m-j-w, I've been there, but I think you're better off unlearning everything you know about C/C++. Here, it is the But, really, I would prefer large immutables were passed by reference (perhaps by stack pointers, where that makes sense, but it is probably best to heap allocate an I think what I'm saying is that the keywords need to reflect semantics which will stay constant for a decade or two, not implementation details that will change in a couple of years (i.e. efficient small mutables and efficient large immutables).
This might be a good enough reason in itself to consider
I'm pretty sure this is absolutely fine where it makes sense, but it won't allow more complex modifications of the type, e.g. |
@andyferris, I already 'unlearned', but for other new users it may be easier to get over the 'why is Julia so slow despite compilation' phase. Picking keywords that support a fast development of a mental model of those details can be a huge selling point to new users not having too much of a computer science background. Not to forget 'simple' keywords to avoid other spoken language barriers either. |
@m-j-w Great, and I do agree with all of that. :) |
Tell you what, let's try the closest thing we can to a poll using the very best GitHub functionality: reaction emojis. Here I've tabulated, in no particular order, the suggestions that appear to have the most support. React using the specified emoji to cast your vote for that suggestion. I believe this requires accessing GitHub through a desktop browser; AFAIK reaction emojis haven't been implemented in the mobile interface. Click the face in the upper right corner of this post to access the menu of emojis.
Failure to vote corresponds to an implicit vote for |
I have to say, I'm not a huge fan of doing contentious decisions like this "democratically". If discussion has played out with no consensus, I would just defer to the decision of the BDFLs. |
Fair point, @TotalVerb. As I said before, I'd be totally fine having the powers that be just give us whatever they think is best. It seems to me like the thread is meandering a bit and @juliohm's point about voting seems reasonable, so I figured I'd give this a go and see what happens. I see it as a way to more clearly show what the consensus is, but I definitely think the final decision should be left to our overlords, regardless of what the community consensus actually is. |
Personally, I don't think I like having two words aesthetically (
So |
I suspect there are no keywords that are concise, convey the intended semantics, and are unlikely to be desirable as variable names. The terminology I feel comes closest to these goals is |
I wish in addition to immutable T
a::Int
b::Float64
...
end
t = Vector{T}(10)
t[2].a = 5 # error here
# instead
c = t[2]
t[2] = T(5, c.b, ...) # works The code creates a neat array of value types |
I think this is an impossible-to-achieve goal since allowing changes is precisely what gives something object identity. Perhaps you would like this approach instead: #11902 |
except for separating mutables and immutables, it should be better if we split values and references. abstract Node{T}
immutable Link{T} <: Node{T}
value :: T
next :: ref{Link{T}} # next :: Link{T} will be an error: Recursive type
end |
There is no need to overcomplicate the language with an artificial distinction between values and references. Mutable and immutable types are semantically much simpler; the fact that a type is a value type is merely an optimization. |
@Keno makes a good point
As I mentioned earlier, I think the "correct" semantics is given by type Complex{T}
const re::T
const im::T
end
z = Complex(1,2) Here As @JeffBezanson states, this isn't really convenient for large numbers of fields, and isn't compatible with the current implementation of types. Partially mutable, partially constant structs may or may not be implemented in the future. However, there is a syntax which makes sense both currently and into the future: @const type Complex{T}
re::T
im::T
end The current way this is implemented, a macro can change the from
|
@be5invis yes, this is a usual way in many languages, e.g. in C# there is
So basically I would love to see the introduction of a type with just property 2. This won't disrupt the existing codebase ( @johnmyleswhite thank you for #11902, still believe that it should not be that ugly |
@wgreenr As mentioned earlier, and has been discussed many times, that is not possible. It is also not really related to the discussion in this issue. |
Anything's possible but introducing mutable value types would be wildly disruptive and a very bad idea. I can understand why it's an apparently simple and appealing idea, but adding a new, entirely different kind of object semantics and bifurcating the type graph into reference and value semantics is not going to make the language better. What it would accomplish is making it impossible to write generic code safely since the same code would do very different things depending on unknown semantics. There's an extensive discussion with examples here. The point of #11902 is to recover benefits of mutable value types without wrecking things. |
I'm not sure if this is even worth mentioning; but in C/C++ 'struct' also implies something about the layout of the data. On the other hand, it is frequently worthwhile to re-arrange struct members to get better memory layout. If you're considering a breaking change to the syntax, might it be worthwhile to have a mechanism to somehow differentiate between 'structs' (ordered -> C interop) and 'immutable's (could potentially be ordered in any way). I'm fairly new to Julia, so I'm sorry if I missed something obvious. I personally have no real preference wrt names; however, I'm surprised that nobody seemed to have suggested "concrete", given that there already exists "abstract". |
To add yet another suggestion, the following seems best to me:
Some justification and thoughts:
UPDATE: I used to have |
Is it likely something will happen in this space before v0.6 feature freeze? |
Probably not, given that no decision has been made (at least publicly) and we're just ~10 days away from the freeze. |
I haven't followed this carefully, but one comment is that if/when this does change, I'd like to request that we first have really good reporting of the offending file/line number in place. Or at least the module; in 0.5 it's still sometimes difficult even to figure out which package has a |
xref #20418 (comment) |
Over time, this keyword has increasingly bothered me. There are several problems:
type
is a very generic word and I'd just as soon leave it available for variable names (and keyword arguments!)type
to refer only to concrete, mutable, struct-like types.type
is the most obvious type-defining keyword, but usuallyimmutable
is preferable and recommended.Here are some alternate keyword suggestions:
mutable
-- opposite ofimmutable
!struct
-- at least says something about what sort of type it isreftype
-- for "reference type", which also conveys some of its key propertiesThe text was updated successfully, but these errors were encountered: