Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic