-
-
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
API consistency review #20402
Comments
Apologies if this isn't the appropriate place to mention this, but it would be nice to be more consistent with underscores in function names going forward. |
No, this is a good place for that. And yes, we should strive to eliminate all names where underscores are necessary :) |
|
There was also a recent Julep regarding the API for |
Should we deprecate I am suspicious of Edit: It would even make sense to reuse |
+1 for replacing |
I'll add renaming |
Double-check that specializations are consistent with the more generic functions, i.e. not something like #20233. |
Review all exported functions to check if any can be eliminated by replacing them with multiple dispatch, e.g. print_with_color |
The typical pairing is |
If we're not going to use the typical name pairing for this kind of data structure because we're worried that the operation entails communication overhead that isn't adequately conveyed by those names, then I don't think |
Maybe double-check that there is general consistency between whether functions take a tuple as the last argument or a vararg. |
Perhaps too big for this issue, but it would be good to have consistent rules on when functions should throw errors, and when they should return |
No issue too big, @simonbyrne – this is the laundry list. |
Btw: this isn't really for specific changes (e.g. renaming specific functions) – it's more about kinds of things we can review. For specific proposed changes, just open an issue proposing that change. |
Not sure if this is what you're talking about, but see CreateMacrosFrom.jl |
|
|
if this is part of this, then maybe also: remember to label your tests with the issue/pr number. It makes it a lot easier to understand why that test is there. I know how git blame works, but when adding testsets (just to give an example) it's sometimes a bit of a mystery what is being tested, and it would be great if the issue/pr number was always there. |
@dpsanders: and exported macros! e.g. |
This is very minor, but the |
@amellnik The difference is that |
No, they are different functions and shouldn't be merged julia> String(UInt8[])
""
julia> string(UInt8[])
"UInt8[]" |
This looks like a situation where |
That sounds ok although calling |
Yes, but that's where the disconnect between |
Please take a look! I haven't gotten a chance to go through these issues systematically. |
BTW, I've noted an inconsistency in the naming of traits: we have |
Those should definitely be made consistent. Do you want to make a PR? |
This is mostly done or can be done in 1.x releases. I can update the checkboxes, but we just went through them on the triage call and everything but #25395 and the underscore audit are done. |
Underscore auditThe following is an analysis of all symbols exported from Base which contain underscores, are not deprecated, and are not string macros. The main thing to note here is that these are exported names only; this does not include unexported names that we tell people to call qualified. I've separated things out by category. Hopefully that's more useful than it is annoying. ReflectionWe have the following macros with corresponding functions:
Whatever change is applied to the macros, if any, should be similarly applied to the functions.
Aliases for C interopThe type aliases containing underscores are
Bit counting
For a discussion of renaming these, see #23531. I very much favor removing the underscores for these, as well as some of proposed replacements in that PR. I think it should be reconsidered. Unsafe operations
It's probably okay to keep these as-is; the ugliness of the underscore further underscores their unsafety. Indexing
Apparently Interestingly, the single index version of Traces
Presumably these are the Tasks, processes, and signals
Streams
It would be nice to have a more general Promotion
See #23999 for a relevant discussion regarding Printing
Code loading
Things I didn't bother categorizing
|
+1 for |
How do we feel about de-underscoring |
The other C names are types, while |
How so? |
Constants are often all caps with underscores – |
I mistakenly thought https://github.com/JuliaLang/julia/blob/master/doc/src/manual/variables.md#stylistic-conventions referenced constants but it doesn't. It probably should. |
I suggest a consistent, mathematically sound, interface for general Hilbert spaces in which vectors are not Julia Arrays. Function names like |
As I've said a few times, this is not a catchall issue for things one wants to change. |
I'd like to do something with |
Something which should probably review is how numbers are treated in the context of collection operations like |
I'm starting this as a place to leave notes about things to make sure to consider when checking for API consistency in Julia 1.0.
Convention prioritization. Listing and prioritizing our what-comes-first conventions in terms of function arguments for do-blocks, IO arguments for functions that print, outputs for in-place functions, etc (official conventional argument precedence #19150).
Positional vs keyword arguments. Long ago we didn't have keyword arguments. They're still sometimes avoided for performance considerations. We should make this choice based on what makes the best API, not on that kind of historical baggage (keyword performance issues should also be addressed so that this is no longer a consideration).
Metaprogramming tools. We have a lot of tools like
@code_xxx
that are paired with underlying functions likecode_xxx
. These should behave consistently: similar signatures, if there are functions with similar signatures, make sure they have similar macro versions. Ideally, they should all return values, rather than some returning values and others printing results, although that might be hard for things like LLVM code and assembly code.IO <=> file name equivalence. We generally allow file names as strings to be passed in place of IO objects and the standard behavior is to open the file in the appropriate mode, pass the resulting IO object to the same function with the same arguments, and then ensure that the IO object is closed afterwards. Verify that all appropriate IO-accepting functions follow this pattern.
Reducers APIs. Make sure reducers have consistent behaviors – all take a map function before reduction; congruent dimension arguments, etc.
Dimension arguments. Consistent treatment of "calculate across this [these] dimension[s]" input arguments, what types are allowed etc, consider whether doing these as keyword args might be desired.
Mutating/non-mutating pairs. Check that non-mutating functions are paired with mutating functions where it makes sense and vice versa.
Tuple vs. vararg. Check that there is general consistency between whether functions take a tuple as the last argument or a vararg.
Unions vs. nullables vs. errors. Consistent rules on when functions should throw errors, and when they should return Nullables or Unions (e.g. parse/tryparse, match, etc.).
Support generators as widely as possible. Make sure any function that could sensibly work with generators does so. We're pretty good about this already, but I'm guessing we've missed a few.
Output type selection. Be consistent about whether "output type" API's should be in terms of element type or overall container type (ref Functions that return arrays with eltype as input should use container type instead? #11557 and RFC/WIP: Support array type as input for functions returning AbstractArray instance #16740).
Pick a name. There are a few functions/operators with aliases. I think this is fine in cases where one of the names is non-ASCII and the ASCII version is provided so people can still write pure-ASCII code, but there are also cases like
<:
which is an alias forissubtype
where both names are ASCII. We should pick one and deprecated the other. We deprecatedis
in favor of===
and should do similarly here.Consistency with DataStructures. It's somewhat beyond the scope of Base Julia, but we should make sure that all of collections in DataStructures have consistent APIs with those provided by Base. The connection in the other direction is that some of those types may inform how we end up designing the APIs in Base since we want them to extend smoothly and consistently.
NaNs vs. DomainErrors. See NaN vs wild (or, what's a DomainError, really?) #5234 – have a policy for when to do which and make sure it is followed consistently.
Collection <=> generator. Sometimes you want a collection, sometimes you want a generator. We should go through all our APIs and make sure there's an option for both where it makes sense. Once upon a time, there was a convention to use an uppercase name for the generator version and a lowercase name for the version that's eager and returns a new collection. But no one ever paid any attention to that, so maybe we need a new convention.
Higher order functions on associatives. Currently some higher order functions iterate over associative collections with signature
(k,v)
– e.g.map
,filter
. Others iterate over pairs, i.e. with signaturekv
, requiring the body to explicitly destructure the pair intok
andv
– e.g.all
,any
. This should be reviewed and made consistent.Convert vs. construct. Allow conversion where appropriate. E.g. there have been multiple issues/questions about
convert(String, 'x')
. In general, conversion is appropriate when there is a single canonical transformation. Conversion of strings into numbers in general isn't appropriate because there are many textual ways to represent numbers, so we need to parse instead, with options. There's a single canonical way to represent version numbers as strings, however, so we may convert those. We should apply this logic carefully and universally.Review completeness of collections API. We should look at the standard library functions for collections provided by other languages and make sure we have a way of expressing the common operations they have. For example, we don't have a
flatten
function or aconcat
function. We probably should.Underscore audit.
The text was updated successfully, but these errors were encountered: