News for hackers. Stuff that matters.
Re:Want cleaner code? Use the rule of six by marginalia_nu on Saturday September 24, 2022 @03:17PM (#32965718)
Emphasis on well-named. Naming things is hard.

Maybe not relevant in simple toy examples, but you don't have to look far until to find a function that isn't so easy to name.

Re:Want cleaner code? Use the rule of six by lamontcg on Saturday September 24, 2022 @05:17PM (#32966597)
Emphasis also on "bunch of lines".

Usually when I see one-line functions they cost more in short term memory than they save. There's good exceptions to this with something like a horrible conditional that is necessarily horrible so you can bust it out into a method with a doc comment about the horribleness, its history, and its subtle madness. But developers that just break out one-line methods all over the place wind up writing hard to understand code.

Re:Want cleaner code? Use the rule of six by Shaanie on Sunday September 25, 2022 @04:49AM (#32969874)
One-line functions are also nice when a comment would've been warranted otherwise. But yes, easy to go overboard with it.
Re:Want cleaner code? Use the rule of six by nmz on Saturday September 24, 2022 @03:43PM (#32965950)
its also a level of indirection... It's sad but functions often slow performance down. but this depends on the language.
Re:Want cleaner code? Use the rule of six by marginalia_nu on Saturday September 24, 2022 @03:51PM (#32966025)
Can't be many languages where that matters in 2022. Auto-inlining of short functions was a thing in the 1990s.
Re:Want cleaner code? Use the rule of six by extasia on Sunday September 25, 2022 @10:08AM (#32971481)
This may be true for compiled langs. In interpreted langs this is not the case. Function calls in Python for example are notoriously expensive.
Re:Want cleaner code? Use the rule of six by nmz on Sunday September 25, 2022 @11:05AM (#32972019)
Beat me to it. Yes, I ran a quick benchmark[0] and not running a function always wins. now, one may argue that you are running a call, but if the interpreter was smart it would convert the small function calls to just a noops.

[0]: https://github.com/Nomarian/crapbenchmarks/tree/main/call

  Summary
  'Perl/nofunc' ran
    1.63 ± 0.30 times faster than 'Perl/func'
    1.73 ± 0.34 times faster than 'Lua/nofunc'
    2.11 ± 0.55 times faster than 'Lua/func'
    9.37 ± 1.62 times faster than 'Python/nofunc'
   12.18 ± 1.90 times faster than 'TCL/nofunc'
   16.02 ± 2.58 times faster than 'TCL/func'
   18.64 ± 3.02 times faster than 'Python/func'
Re:Want cleaner code? Use the rule of six by dTal on Sunday September 25, 2022 @06:59PM (#32977287)
If you're hand-wringing about the performance impact of function calls, Python is probably the wrong choice anyway.
Re:Want cleaner code? Use the rule of six by dqpb on Saturday September 24, 2022 @05:18PM (#32966602)
> Naming things is hard

Naming is hard unless you have a sensible concept hierarchy, and then naming is easy.

Concept hierarchies are hard, unless you have a sensible system model, and then concept hierarchies are easy.

System models are hard, unless you have domain expertise, and then system models are easy.

Re:Want cleaner code? Use the rule of six by marginalia_nu on Saturday September 24, 2022 @05:32PM (#32966705)
Not everything is a neat concept though.

Look at the Porter stemming algorithm for example. It simply does not decompose into something that is easy to put names on.

Re:Want cleaner code? Use the rule of six by dqpb on Saturday September 24, 2022 @06:03PM (#32966926)
> A consonant will be denoted by c, a vowel by v. A list ccc... of length greater than 0 will be denoted by C, and a list vvv... of length greater than 0 will be denoted by V. Any word, or part of a word, therefore has one of the four forms: CVCV ... C CVCV ... V VCVC ... C VCVC ... V

Looks fine to me.

Re:Want cleaner code? Use the rule of six by djbusby on Saturday September 24, 2022 @05:22PM (#32966631)
Domain expertise is hard.