On Tue, May 12, 2015 at 12:03 PM, James Douglas <jdouglas(a)wikimedia.org>
wrote:
Howdy search team,
Would anyone be interested in collaborating on style guides for Java, PHP,
and any other languages we tend to use amongst ourselves?
It would be super handy to have a reference to reach for when considering
alternative design patterns, plus it would be a lot of fun to think about
how (and why) we might prefer one style over another.
It would also make a convenient way when onboarding new folks (of whom
there will be many) to get them quickly ramped up on how to sling code, WMF
Search Team style.
Also also it would make a convenient way for code reviewers to say "Yo
James, this is totally not Haskell, stop trying to make everything a
monad!".
Thoughts?
Yes sure.
For a starting point in Java, perhaps we could use Effective Java[1] as a
template, and (bias alert) sprinkle in some Functional Programming in
Java[2] for good measure.
I'd go with Google's style guide
<https://google-styleguide.googlecode.com/svn/trunk/javaguide.html> as a
starting point. Its been a while since I read it but I remember it being
pretty good. For the most part the actual code layout stuff is handled by
checkstyle. Stuff like indent 4 spaces, no spaces around parrens and crap.
Until we upgrade to Java 8 I'm inclined to keep functional programming to a
minimum like they talk about on the guava guide
<https://code.google.com/p/guava-libraries/wiki/FunctionalExplained>. Its
really useful for lazy structures but its super verbose.
In the Elasticsearch plugins I try to follow the Elasticsearch and Lucene
style which is pretty loose. They almost never use the functional idioms in
Guava and aren't big on setters and getters.
I certainly appreciate Haskell but I think it works because it has:
* Bind syntax
* Strong type inference
* Easy lambdas (maybe too easy)
* Laziness
None of which Java 7 has. Java 8's going to have better lambdas but that's
it. So I think you have to be weary what you pull from Haskell into Java. I
think its easier with Scala because its closer. I just think we should use
these tools where they are obviously good but not for cases where
imperative work is more idiomatic in Java.
For PHP, I have no idea what I'm doing, but I have
an interesting
Functional Programming in PHP[3] book on my desk that y'all can borrow.
For the most part I want us to stay close to MediaWiki's style. Right or
wrong, it'd be crazy to go against it. Kevin mentioned in a reply that I
just got that there is a style guide. I honestly haven't read it - I just
tried to make my code look like the other code. Ooops.
Nik