• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code style in Clojure

 
Stian Almaas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody!

I wonder if there is an official or de facto code style for clojure. I am trying to pick it up from bits I see on the net and one of the things that I notice is that everyone uses very short names on functions. It seems customary to prefer fewer characters where possible. (Examples: fib rather than fibonacci, str rather then string)

This is the opposite of the trend I have observed in Java over the latest years where the preferance is for long and descriptive naming, helped by auto-completion in the IDEs.

I can decide for myself of course, but is it more usual to have shorter names in clojure?
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course the link talks about coding standards for Clojure libraries, but it is useful any way.
I noticed Clojure coding looks like English, for example:
search-city , walk-the-graph , clean-and-build
IMHO, this is better than:
searchCity, walkTheGraph, cleanAndBuild
Personally, I don't prefer short as the code will looks obfuscated.
Prefer fibonacci instead of fibo, walk-the-graph instead of walk.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
 
Stian Almaas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John!

That was actually more than I asked for, which is wonderful!

The link to the assembla-wiki was perfect. Exactly what I was looking for. Copying what the api developers are doing is probably best. And I can see that they do have a preferance for short names, like x,y for numbers, pred for predicates etc.

I also prefer longer names for functions and vars. I am used to camel case so I don't read that any differently than the dashes used in Clojure. For me it would have been just as easy to go with camel case but I guess it is nice to explicitly see where you call down to Java code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic