Skip to main content

Timeline for How small should functions be?

Current License: CC BY-SA 3.0

28 events
when toggle format what by license comment
Jan 30 at 5:29 comment added Tejas Parnerkar As someone said, its opinion based. Ideally it should be "small" -- i try not to exceed 20 lines of code per method. But again, the main measure I try to aim for is single responsibility principle. If the method gets too big, it means the code is doing too much, hence there arises a need to contemplate if a refactor is needed.
Jan 30 at 0:41 answer added Kain0_0 timeline score: 0
Jan 25 at 14:37 review Close votes
Jan 30 at 3:04
Jan 25 at 14:20 history protected gnat
Jan 24 at 17:26 answer added gnasher729 timeline score: 0
Jan 24 at 13:51 answer added Atif timeline score: 0
Dec 15, 2017 at 5:40 history tweeted twitter.com/StackSoftEng/status/941543567549517826
Dec 10, 2017 at 13:47 review Close votes
Dec 15, 2017 at 3:05
Dec 10, 2017 at 12:24 answer added user204677 timeline score: 2
Jun 6, 2017 at 6:13 answer added Derek Elkins left SE timeline score: 9
Jun 6, 2017 at 5:59 answer added Vincent timeline score: 0
Jun 6, 2017 at 1:09 comment added Frank Hileman This is only opinion based.
Jun 6, 2017 at 0:43 answer added Rhys Johns timeline score: 0
Jun 5, 2017 at 23:06 answer added Cort Ammon timeline score: 4
Jun 5, 2017 at 21:25 answer added Sascha timeline score: 0
Jun 5, 2017 at 21:07 comment added jpmc26 Size is a heuristic, not a measure. A long function can be good, and a short function can be bad. Shorter is usually easier to follow, but this isn't an absolute. As such, long length just a clue that should make you step back and evaluate. Short functions where everything is divided up too much can also make it hard to follow. If you have a very short function, it should encapsulate some specific, probably shared functionality. The thing you should be focusing on is readability and maintainability, not length.
Jun 5, 2017 at 20:29 comment added Kevin Workman Honestly, you're probably overthinking this. I wouldn't worry too much about stuff like this. If you're still learning the basics, you should write code that you understand and gets the job done, and then move on. Anything you write now will look like garbage to you in 6 months (that's a consequence of learning), so don't waste too much time trying to polish everything. Stuff like this becomes more natural with experience. Get the experience by moving onto the next thing.
Jun 5, 2017 at 19:04 comment added gnat see also Should I extract specific functionality into a function and why?
Jun 5, 2017 at 19:03 comment added gnat Possible duplicate of One-line functions that are called only once
Jun 5, 2017 at 18:52 answer added candied_orange timeline score: 41
Jun 5, 2017 at 18:42 review Close votes
Jun 14, 2017 at 3:08
Jun 5, 2017 at 18:33 comment added Laiv How little functionality is too little? ask to the function name: Does the code do what the name is saying to do? If Yes, then the function has exactly the length it must have. (Optimizations aside). As @Johnwu says, readability is key factor
Jun 5, 2017 at 18:23 comment added John R. Strohm Possible duplicate of What should be the maximum length of a function?
Jun 5, 2017 at 18:06 answer added John Wu timeline score: 15
Jun 5, 2017 at 18:04 answer added Timothy Truckle timeline score: -3
Jun 5, 2017 at 18:02 comment added R Sahu You might find the answers to How is wrapping an expression as a function be Clean Code? useful.
Jun 5, 2017 at 17:57 review First posts
Jul 5, 2017 at 17:59
Jun 5, 2017 at 17:57 history asked CS2020 CC BY-SA 3.0