You’re right, it’s not. But those of us who dislike the underscore feel that it is analogous, and the underscores annoy us to a significantly lesser, but still non-negligible, degree.
Then again, there are many of us who find the lack of underscores in base to separate words annoying, to a non-negligible degree.
Actually, the Julia contributing guide says the following:
try to adhere to a 92 character line length limit
use upper camel case convention for modules, type names
use lower case with underscores for method names
it is generally preferred to use ASCII operators and identifiers over Unicode equivalents whenever possible
That does seem very clear - why aren’t the core team following their own guide?
Is inverse_hyperbolic_sine(x)
really preferable to asinh(x)
?
That’s a straw man argument - I don’t think anybody has suggested that at all.
We’ve been talking about function names that are composed of more than one English word, not common mathematical abbreviations.
The stdlib functions that become sufficiently commonly used acquire a similar status to standard math library functions, I think. Then I would propose my argument applies.
Can you give some examples? If you are talking about things like the C/C++/Posix functions such as isgraph
, isalpha
etc, I’d make a cleaner API for base Julia (I had a PR over 2 years ago to do just that), and put the isalpha
etc. abbreviations into a Posix
module, just like I’d put MATLAB abbreviations into a Matlab
module.
readdir
, for instance.
I would make that read_directory
, for sure.
chown
then becomes change_owner_and_or_group
?
I’d leave it in a Posix
module as chown
, and attempt to come up with some more generic function with keywords for a Julia API for operating on file metadata.
I would be totally fine with
sine(x, inverse = true, hyperbolic = true)
and if I had my wuthers we’d have
file_metadata(owner = 2, group = 2)
Where are you copy / pasting from? Don’t decent editors have an easy way to view the docs inline?
I think Emacs is a more than decent editor, but I am unaware of a way of pulling up the Julia help for an operator or method in Emacs, even with julia-mode.el
. Has support for that been added?
Also, this is very important: code is read much more than it is written (Microsoft recommends not relying on something like Intellisense, that only helps when writing)
From the author of the Handbook of Agile Programming, Robert C Martin:
“Indeed, the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. …[Therefore,] making it easy to read makes it easier to write.”
Using my julia-repl
mode, C-c C-d
sends @doc <symbol>
to the repl. Not as nice as a tooltip, but an OK solution until LanguageServer support matures.
Oh, but that doesn’t work in the normal Julia editing mode (unless it was added in a later version).
But that still doesn’t help readability, just like the article from the Microsoftie said, you shouldn’t have to rely on something like Intellisense to understand the code.
It’s worst that it looked. Not only is_windows
is deprecated but we can’t do
julia> iswindows()
ERROR: UndefVarError: iswindows not defined
it has to be
julia> Sys.iswindows()
true
Was allowing both ways considered? As Nim language allows; e.g. function cum_sum
could be used as cumsum, or I believe cumSum (in Nim, but is there some Unicode case issue in general for such?).
Or other way, for function cumsum, making ok to add _ arbitrarily, as we do for number literals, e.g. 1_000_000.
I see the downsides of not having consistency, but there could be a default way to show without _ (that the user could override, to get to see, e.g. for this function):
help?> print_shortest
search: print_shortest
print_shortest(io, x)
I also see: Uniform Function Call Syntax - Wikipedia
proposed (as of 2016) for addition to C++ by Bjarne Stroustrup[5] and Herb Sutter[4]
To be consistent you should want e.g. g_c_d function and arg_max. How would you like if you could define functions e.g. “is hit” with _ (or even, just Non-breaking space - Wikipedia or any other that may be appropriate Zero-width space - Wikipedia or Zero-width joiner - Wikipedia)
and the REPL would not show the [zero-width]space but rather use alternating colors when showing code? And you could skip those invisible Unicode “letters” on use.
As I’ve said before, I believe underscores should be used consistently when separating words, but gcd
is not a word, and also it is a standard mathematical function name, just like sin
, cos
, tan
, so for two reasons it should not have underscores.