You’re totally right that Base Julia has a very different implicit style guide than I’ve been using. That’s intentional since I find that some of the Base Julia code is a little hard to read at times. I’ve also been bitten by the absence of important type constraints in Base before (think of when show(io) used to have no type information), so I’ve tended towards initially conservative typing until it’s clear that looser typing is needed.
I’m not sure there’s much benefit in having rules that involve personal judgement because reasonable people can make different judgements. So I’d rather have no rule at all (and just let things happen as they may) than try to formalize a rule whose application can’t be reliably checked by a linting program. Coming from R, I’m pretty strongly opposed to Matlab's precedence rule for “:”. I find it hard to read and really wish that it hadn't made it impossible for us to match R’s formula syntax. The “:” operator’s precedence is by far the part of Julia that I most dislike (which, of course, is why I’m such a big fan of Julia, since that’s a minor problem to have as your worst quality.) The for loops thing is one where I don’t have strong feelings, but tend to prefer consistency. I see the appeal of using “=“ in some contexts, but find it easier to avoid using different things to express the same concept. — John On Dec 31, 2013, at 10:54 AM, Stefan Karpinski <[email protected]> wrote: > I would mention that the vast majority of Base Julia, although it's fairly > internally consistent, does not follow a lot of these rules. In particular, > the whitespace rules and some of the type annotation rules, and "for x in" vs > "for x =". I tend to follow rules that require a bit of judgement, but > therefore convey some subtle information about the code. > > Whitespace. I don't use spaces when calling functions that are mathy: f(x,y). > I do, on the other hand, tend to use spaces when calling non-mathy functions: > endswith(str, substr). I think that math expressions should be spaced so that > they're readable and I'm not sure that a fixed set of rules does that, > although no spaces for tighter operations and spaces for looser operations is > the trend. I rely heavily on Matlab precedence of arithmetic versus ":". > > For loops. When the right-hand-side is a range like 1:n then I use =. When > the r-h-s is an opaque object that we're iterating over, then I use in. > Examples: > > for i = 1:n > # blah, blah > end > > for obj in collection > # blah, blah, blah > end > > > > On Tue, Dec 31, 2013 at 10:01 AM, John Myles White <[email protected]> > wrote: > One of the things that I really like about working with the Facebook codebase > is that all of the code was written to comply with a very thorough internal > style guideline. This prevents a lot of useless disagreement about code > stylistics and discourages the creation of unreadable code before anything > reaches the review stage. > > In an attempt to emulate that level of thoroughness, I decided to extend the > main Julia manual’s style guide by writing my own personal style guideline, > which can be found at https://github.com/johnmyleswhite/Style.jl > > I’d be really interested to know what others think of these rules and what > they think is missing. Right now, my guidelines leave a lot of wiggle room. > > — John > >
