r/FlutterDev • u/ConvenientChristian • Oct 08 '26
Discussion What should the maximum length for a function be in a Vibe Coded Flutter app
I just gave Codex a goal to refactor my code to have a maximum function length of 30 lines and increase code reuse in the process. While doing the task, it found plenty of opportunities for code reuse and also reused work done in the app multiple times, making the app run faster.
This seems like a good result, but I don't have a good sense of whether the maximum length would be 15, 20, 30, or 40 lines. What opinions do you have?
0
Upvotes
3
u/into_void Oct 08 '26
It's hard to define a maximum length. Everyone has a different taste. However one function should do one work. How do I define whether it is one work or not? As uncle Bob says if you can extract a method by clicking in the ide then it is still not one work. I personally keepy functions within 5-8 lines. Mostly 3 lines. I extract the logically lower level task into a seperate function.
9
u/diz_array Oct 08 '26
🙄
2
u/Nitish_kalita Oct 08 '26
Ask AI
1
u/AnnualAdventurous169 Oct 08 '26
If it can confortably fit in your working memory its probably fine, if not, too long.
1
u/JohnnyJohngf Oct 08 '26
It’s a weird question, but if you insist I would say limit parameters number, not the length.
1
u/battlepi Oct 08 '26
1
u/RandalSchwartz Oct 08 '26
If there's a chunk of code inside your function that seems collectively to handle a single step in your algorithm, especially if you block it off with comment lines, that's a good candidate for extraction as a separate function. Luckily, modern IDEs can do that for you, including determining what you'll have to pass to the new extracted function.
1
u/dangling-feet Oct 08 '26
Definitely 42.