87
ultrono
8y

"Only one level of indentation per method". This image just made my day :)

Comments
  • 3
    Wow. This is coded badly
  • 2
    I'm ashamed to say some of my quick and dirty scripts look similar. Usually clean them up into multiple functions in a separate file when I can.
  • 5
    @tisaconundrum At least it's better than a single if that is long 1000 characters and chained with ands...
  • 2
    One level of indentation is a good rule of thumb, but not always achievable. especially in JS.
  • 0
    It looks like multiple users can share the same e-mail address. ^^
  • 1
    @Greggergalactic
    In the case of Promises -- and especially serial Promise trees -- this is extremely difficult to do.

    CoffeeScript:

    function = (args) ->
    externalPromiseService(args)
    .then (resolve_value) ->
    # code (interior)
    , (err) ->
    # catch

    That's three levels of indenting before getting to your code. You can offload the interior to another method, but you've still exceeded the rule-of-thumb by two levels. Serial Promises require three levels of boilerplate, and breaking those levels out decreases their readability.
  • 1
    @Greggergalactic
    Yeah, I totally agree. 🙁
  • 3
    Nesting, nesting, nesting.

    If you turn it to the left
    it kind of looks like the iron
    throne.
  • 0
  • 0
    @andros705 they're actually quite useful. But if you want to yell at JavaScript for supporting them, you should include a few others in your tirade: Ruby, Lisp, Python, Haskell, C++/C#, Java, Go, Lua, Perl, PHP, R, Rust, Scala ...
Add Comment