Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Code style in Clojure

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.assembla.com/wiki/show/clojure/Clojure_Library_Coding_Standards
Hope this help.
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also want to check this:
http://en.wikibooks.org/wiki/Learning_Clojure/Coding_Conventions
http://techbehindtech.com/2010/12/09/clojure-good-coding-guidelines/
 
Stian Almaas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic