This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # alda (5)
- # bangalore-clj (1)
- # beginners (9)
- # bigdata (1)
- # boot (51)
- # carry (1)
- # cider (9)
- # cljs-dev (22)
- # clojars (39)
- # clojure (118)
- # clojure-brasil (1)
- # clojure-czech (8)
- # clojure-france (2)
- # clojure-italy (5)
- # clojure-korea (9)
- # clojure-russia (9)
- # clojure-spec (17)
- # clojure-uk (42)
- # clojurescript (48)
- # core-async (1)
- # emacs (3)
- # figwheel (1)
- # funcool (3)
- # hoplon (39)
- # klipse (51)
- # lein-figwheel (4)
- # leiningen (2)
- # luminus (5)
- # off-topic (245)
- # om (18)
- # onyx (19)
- # parinfer (1)
- # pedestal (18)
- # re-frame (47)
- # reagent (19)
- # ring-swagger (1)
- # specter (18)
- # untangled (93)
- # vim (8)
- # yada (56)
@paulspencerwilliams One word answer "readability"! Longer answer: Developers spend most of their time reading and comprehending code, often written by someone else. Readability is very subjective but you can do so much in 3 lines of Clojure I would favour small fns
@paulspencerwilliams I agree about too many small fns to some extent but I think the really hard thing to do in Clojure (or any other lang) is to decide on what namespaces do (SRP). Get this right and I think the number of fn's takes care of itself. P.S. you'll never finish refactoring NS and adding more until your s/w end of lifes
@paulspencerwilliams strongly in favour of splitting here. Not just for testability (though that’s a side benefit) nor for reusability (though it’s good to DRY up code) - but for expressiveness - any function that is over a screen long is likely to be too hard to understand for a new pair of eyes.
@paulspencerwilliams I'm rather ambivalent about function size. In my view it's not necessarily easier to reason about a ns with lots of small functions, given the increased indirection that entails. But I do believe functions should do one thing. Call me a heretic but I think the argument for testability involves design trade-offs which can actually harm good design.
@korny haha, over a screen length! It’s all about norms. To me, a large function is around 10 - 15 LoC
I prefer well designed regression tests, coarse enought to make function size irrelevant.
You can write an entire web API in one function. I'm not persuaded that doing so is 'wrong' on the basis of function size alone.
@paulspencerwilliams sorry, I should have included the context that I’m working on a 13” macbook 🙂 So in my current font “screen length” is 28 lines (repl takes up 1/3 of the screen)
I’d agree that 10-15 lines is about my comfort zone, but I wouldn’t say “oh my god that’s horrible” until I got to 25 lines or so. I’d probably split before then because of other reasons - it’s hard to have a function that does just one thing that’s 25 lines long.
There are obvious exceptions though - especially when the line gets blurred between code and configuration. If it’s really config not code, then a whole lot of other rules apply.
(I’m saying this because I’m setting up some restful routes, which is way beyond a screenful at the moment 😉 )
@malcolmsparks I'd agree with the fns do one thing but due to the expressiveness that generally that means they're smaller. However it all depends on what you think is "one [atomic] thing"
I think maps make the line count harder. I try to keep my functions short, but if they're creating maps throughout that process, they tend to gain 5loc just from the map.
@dominicm yeah I think the moral is not the LOC as this is irrelevant but how easily parsed by a developer. So I can parse a Java method of 30 LOC easily but 30 LOC on Clojure is more dense.
@agile_geek I don't agree, I think the LOC is actually irrelevant. It may correlate that more easily understood code happens to have smaller functions, but it doesn't follow that reducing the size of functions makes code more easily understood.
@malcolmsparks I obviously didn't express myself well. I also think LOC are irrelevant
@korny wow - 28*3/2=42 lines of screen 😞 i get 79 lines of code in emacs on my mbpr15... i wonder if we therefore have very different sensitivities about what is 'long' ?
@malcolmsparks it's more the complexity "factor". So I agree about one thing but frequently you can break things down into smaller and smaller "one things"
@dominicm it's one simple way I've used for many years to manage this problem in Java
@mccraigmccraig if I need more context I maximise the editor window or shrink the font or both. Or if available, plug in to an external monitor.
@mccraigmccraig also I keep the font big because I’m getting old and tiny fonts tire my eyes 🙂
@korny alternatively create multiple splits on the buffer. Then you can view the different scopes separate to the part you're figuring out. Do this a lot on my laptop
I like using cyclomatic complexity as a metric, but haven’t found good tools to measure it consistently in all languages - especially clojure 🙂
There is a downside to lots of small functions which stops me a embracing them wholeheartedly, and that is the naming problem - all these functions need to be named, that's often cognitively taxing when programming, and you can end with all these bullshit functions with bullshit names that give the illusion of 're-usability' but in reality are far too tied to their domain to be generally useful. And there's also the problem that once you have a small (public) function, some other ns can 're-use' it and then you've created a coupling you didn't expect. For that reason I think the DRY principle is hugely over-valued (and this point was very well made in the original article: https://medium.com/@rdsubhas/10-modern-software-engineering-mistakes-bc67fbef4fc8#.txrola3hf - which is well worth a read imo)