You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the discussion of #588, the idea of a compiler warning on indexing operations was briefly floated. (Because they could potentially throw exceptions and are thus unsafe). Don Syme mentioned performance issues on indexing operations, which suggests another possible compiler warning. If an indexing operation on a given data structure is "slow" (precisely what "slow" means might vary from context to context), maybe the designers of the data structure could tag that operation with an attribute that would generate a compiler warning, text definable by the user. For example, if the index operator on Lists was tagged with that attribute, the text might look like: "This operation is included for API compatibility with Array. But while indexing into an array is O(1), indexing into a list is O(N). Unless you know that N will be small, it is recommended that you avoid index operations on a list."
The name of this attribute could be InefficientOperationWarningAttribute, or just InefficientOperationAttribute since gluing together more than two or three CamelCase words can become unreadable very fast.
The ObsoleteAttribute is similar in how it generates a compiler warning with user-definable text, but its semantics are not what I'm suggesting here. ObsoleteAttribute suggests that the function might be removed from future iterations of the API, whereas I'm suggesting an attribute that would communicate the warning, "This function is in the API to stay, but should be avoided unless you know what you're doing. There are other functions that will do this operation more efficiently."
Pros and Cons
The advantages of making this adjustment to F# are that we can warn people away from operations that they may not know are inefficient (.[n] on a list or seq, Seq.last...).
The disadvantages of making this adjustment to F# are yet another attribute, slower compilation, and larger code size (unless there's a way to make the attribute available at compile-time only, but not bloat the runtime code with it — and I don't know of any way to do that).
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M (maybe even S?)
This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
This is not a breaking change to the F# language design
I or my company would be willing to help implement and/or test this
The text was updated successfully, but these errors were encountered:
I agree with this, it fits with various other suggestions by @charlesroddie for more opt-in warnings. Marking as approved-in-principle. Please consider submitting an RFC and PR for this.
In the discussion of #588, the idea of a compiler warning on indexing operations was briefly floated. (Because they could potentially throw exceptions and are thus unsafe). Don Syme mentioned performance issues on indexing operations, which suggests another possible compiler warning. If an indexing operation on a given data structure is "slow" (precisely what "slow" means might vary from context to context), maybe the designers of the data structure could tag that operation with an attribute that would generate a compiler warning, text definable by the user. For example, if the index operator on Lists was tagged with that attribute, the text might look like: "This operation is included for API compatibility with Array. But while indexing into an array is O(1), indexing into a list is O(N). Unless you know that N will be small, it is recommended that you avoid index operations on a list."
The name of this attribute could be
InefficientOperationWarningAttribute
, or justInefficientOperationAttribute
since gluing together more than two or three CamelCase words can become unreadable very fast.The
ObsoleteAttribute
is similar in how it generates a compiler warning with user-definable text, but its semantics are not what I'm suggesting here.ObsoleteAttribute
suggests that the function might be removed from future iterations of the API, whereas I'm suggesting an attribute that would communicate the warning, "This function is in the API to stay, but should be avoided unless you know what you're doing. There are other functions that will do this operation more efficiently."Pros and Cons
The advantages of making this adjustment to F# are that we can warn people away from operations that they may not know are inefficient (
.[n]
on a list or seq,Seq.last
...).The disadvantages of making this adjustment to F# are yet another attribute, slower compilation, and larger code size (unless there's a way to make the attribute available at compile-time only, but not bloat the runtime code with it — and I don't know of any way to do that).
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M (maybe even S?)
Related suggestions:
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: