4

There is something about the Stepdown Rule (high level function at top and low level next) in clean code (Chapter 3, One Level of Abstraction per Function ).
What should I do when I use coffeescript since there is no function declarations in coffeescript.

example:

 seeAMovie = ()->
     BuyTheTicket()
     watch()

 BuyTheTicket = ()->
     //some thing

 watch = () ->
     //some thing

I want to do like this.

user2666750
  • 582
  • 1
  • 7
  • 11
  • `f = (x) -> ...` counts as a function declaration, doesn't it? And you might want to be a bit more explicit about what this *Stepdown Rule* says. – mu is too short Aug 16 '13 at 06:42
  • Stepdown Rule: "We want every function to be followed by those at the next level of abstraction". It mean that we may use a next level function which have not been declared . – user2666750 Aug 16 '13 at 06:52

1 Answers1

9

CoffeeScript doesn't really affect this rule. The rule doesn't have anything to do with declarations, but even if it did, CoffeeScript does have declarations anyway. As @muistooshort said, here's a CoffeeScript function declaration:

functionName = (arg1, arg2) -> 
  functionBodyLine1
  functionBodyLine2

Those parenthesis are optional in the declaration if there are no arguments. Here's an example of the Step-Down Rule in CoffeeScript in action:

highLevel = ->
  doSomethingAlmostAsHighLevel1()
  doSomethingAlmostAsHighLevel2()

doSomethingAlmostAsHighLevel1 = ->
  doSomethingALittleLowerLevel1()

...

Note about your edit: That's perfectly fine and follows the Step-down rule. What is wrong with your sample?

Not mentioned in the book, but Uncle Bob clarified to me that when two functions - at the same level of abstraction - use the same lower level function, they should be ordered like so:

highLevel1 = -> lowLevel()
highLevel2 = -> lowLevel()
lowLevel = -> ...
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356