The style guide if of course opinionated, and may become more opinionated (and thus clearer) over time. It aims to be specific and gives many code examples.
The style guide is also tried and tested. It has come from a team of more than two dozen Julia programmers (scientists and software engineers), using Julia both for research and in production over the last three years.
We have followed the Blue style in ~100 packages, both internally and externally in our open-source repositories and in other open-source repositories primarily maintained by Invenia folk, and think this style has proven its worth.
Here’s hoping the Blue style will be useful to the wider Julia community!
Overall, it is best to keep the types general to start with and later optimize the using parametric types. Optimizing too early in the code design process can impact your ability to refactor the code early on.
Adding a type parameter is a (silent) performance breaking change. What used to be a concrete type Foo is no longer one, it is now Foo{T}) so people that store ::Foo in their structs will suddenly have a non-concrete type in there. Also, methods that used to were written as f(::Type{Foo}) will no longer match and have to be written as f(::Type{<:Foo}). My point is that introducing a new type parameter is not that simple of a refactoring.
If you do require the use of import then create separate groupings for import and using statements divided by a blank line:
When is import ever required? Personally, I think the import keyword can be removed completely and we just use using Example: hello everywhere and always specify module when extending.
Functions that are only intended for internal use should be marked with a leading underscore
Is this really enforced? I just looked at some random files:
When is import ever required ? Personally, I think the import keyword can be removed completely and we just use using Example: hello everywhere and always specify module when extending.
I don’t know (I don’t think it is), but we cover that case anyway We recommended always using, and personally I agree import could go.
I’m curious: how did you come up with 92 characters per line?
By the way, with automatic wrapping of long lines by editors such as ST3 and Atom I don’t really see a compelling reason to worry about the length of the line of code. But I can see how that making things dependent on the environment in which the code is edited is not ideal.
(As a purely historical note, Eric at Invenia made a start on this 4 (four!) years ago now https://github.com/invenia/JuliaFormat.jl in Julia 0.4. Which probably predates us writing down a style guide )
I wonder if there are some more Julia-specific information available about how does Julia perform in large scale production-level projects, where its easier to use another languages, what platforms and software architectures are better for it, software maintenance and so on?
I was originally taught the 80 rule but I’ve created my own 80-92 rule since using Julia where 80 is a softwrap and 92 is a hard wrap. I’m not sure if this comes of as just inconsistent but it certainly seems to be a more manageable way of doing things.
I guess an off-topic, but breaking or not has to be judged w.r.t exposed API. It is conceivable to expose type API with trailing type parameters being explicitly documented as an implementation detail. This would mean that API-conforming downstream code can only use the types as an upper bound. But I guess it’s not a popular idea.
Thank you for this! I might adopt it in my packages. The style guide is quite extensive and I’ve only skimmed it, but I haven’t found a single major thing I disagree with so far. Everything seems to make sense; it shows that it has been battle-tested. I like that it’s not just blindly based on another language’s / company’s style guide, and I also like that it leaves some wiggle room.
Hurray! I really hope some people will find this useful. It’s at least helped me get used to a consistent way of writing code without having to think about format, and mostly removed style discussions from PRs.