tell me guys what would you prefer:

function a(){
function b(p1,p2,p3,p4,p5,p6){.


function a(){

function b(

if you read this rant before expanding, you got a complete context on how what function a is, its calling b 2 times and how function b looks.

if instead of the first option, i had used 2nd block, you wouldn't even know the 2nd param of b function without expanding this rant.

my point?
i prefer to keeping unnecessary info on one line. and w lot of linters disagree by splitting up the code. and most importantly , my arrogant tl disagree by saying he prefers the splitted code "for readability" and becaue "he likes code this way, old-eng1 likes this and old-eng2 likes this" .

why tf does an ide have horizontal a scrolling option available when you are too stupid to use it?

ok, i know some smartass is going to point that i too can use vertical scrolling, but hear me out: i am optimising this!

case 1 : a function with 7 params is NOT split into 7 lines. lets calculate the effort to remember it
- since all params could have similar charactersticks ( they will be of some type, might have defaults, might be a suspendable/async function etc), each param will take similar memory-efforts points. say 5sp each.
- total memory-efforts= 5sp *7 = 35 sp.
- say a human has 100 sp of fast memory storage, he can use the remaining 65 sp for loading say 5 small lines above or below.
- but since 5 lines above are already read and still visible on screen, they won't be needed to be loaded again nd again, nd we can just check the lines below.
- thus we are able to store 65+35+65 = 165 sp or about 11 lines of code in out fast memory for just a 100sp brain storage

case 2 function with 7 params IS split into 7 lines.
- in this case all lines are somewhat similar. 5sp for param lines as they are still similar which implies same 35sp for storing current function and params
- remaining 65sp can only be used to store next 5 lines of 13sp as the previous code is no longer visible.
- plus if you wanna refresh the code above, you gotta scroll, which will result in removing bottom code from screen , and now your 65sp from bottom code is overwritten by 65sp of top code.
- thus at a time, you are storing only 6 lines worth of code info. this makes you slow.

this is some imaginary math, but i believe it works

  • 4
    Your argument about a person's memory is kinda flawed. You should define the function input/output, and forget about the implementation of the other function.

    Indented correctly, the second version gives a visual break between function declaration and function implementation. I think is useful.

    If parameters are similar, I'd argue separate lines matters more, because good names matter more, and if they're in a list you can more easily spot the difference (or lack thereof).
  • 3
    if it fits on my screen without scrolling. I do option 2. otherwise
    break it into lines.

    If there are more than 5 arguments I'd consider grouping them together somehow

    Having to scroll horizontally means a break from flow. Id have to take my hand off the keyboard to move my mouse.

    So yeah. not ideal
  • 1
    Also, scrolling horizontally would remove all the code on the left, only to read a couple parameters. I don’t like that.
    Usually I have word wrap on in my vim, so I don’t care too much which version to use. I usually just go with whatever the linter thinks is good for the language.
  • 1
    Ah the old horizontal vs vertical discussion.

    Let's start with a simple fact: Exceeding a line length of more than 100-120 chars in a line makes reading code painful.


    Because your eyes play ping pong.
    Funny as it sounds it's true.

    Your eyes have to read horizontal left to right, you scroll a line down, then you read left to right, next line etc.

    At worst, you have to scroll a line and lose the focus as the beginning of the line gets lost due to scrolling.

    Meaning you have to remember the line, the contents of the line, scroll horizontal, scroll back, find the beginning of the line, go down one line, start reading left to right.

    Sounds unpleasant? It is.

    Which is why imho anyone who thinks that writing > 120 chars in a line is okay needs to get some serious whacking. It makes reading code unpleasant, as the eyes get pretty strained and it's easy to loose focus.

    That's why imho the 2nd style is definitely better.

    There's another reason...

    Our brain has a very funny problem. It is too easily tricked sometimes.

    Vertical style creates breaks which imho reduce the brain's tendency to error out on error correction.

    If you wanna play a fun game:

    Write 10 words which have a very small Levenshtein-Damerau distance down, one horizontal, the other vertical.

    Same, fame, game, tame, lame, ...


    Dunno if there is something scientific here, but most people I've played this game with immediately say that the vertical style makes it easier to spot the difference of one char.

    With horizontal, the more words, the more "tenuous" it gets.

    I really hate it when people try to shove everything in a line no matter what.

    It's most of the time an unnecessary strain, just for the sake of not having to scroll down. You have to scroll down anyways, so just use that to make it easier for everyone else involved.
  • 1
    i use both variants, it depends on the situation. If the length of the parameter list gets excessive, i will wrap it into multiple lines, regardless if they're only a few or not. At the end of the day it's about readability for the human, the computer doesn't care after all (exceptions apply ofcourse).
  • 3
    The IDE can also display all your code on one line, doesn't mean you should do that.

    Human memory does not work that way. We memorize patterns, not characters. If you can't keep in mind all parameters and commands within a function with some effort that means there's no overarching concept so it should be several functions.

    If there are lots of arguments I want to be able to access information about them by index without scanning the text of the preceding arguments and counting commas.

    Also, with this many arguments one might wonder if this should be a DTO instead, or perhaps a reusable DTO and some additional data.
  • 1
    I have adopted a naming policy last week that works better (for me) than DTO; ingress data is in "bundles", egress data is in "reports". This distinction makes it clearer what the purpose of the object is, and because both words give an impression of not really meaning anything beyond the contents, I find myself more inclined to define new ones for each function with too many arguments or return values, ultimately vastly improving readability.
  • 1
    i dont care.

    zen of python handles it for me, whatever black feels best.
  • 2
    Depends on how long the fn names are and how important/likely that someone will have to attend it will be in the future.

    Then again, I try not to make functions with this many params.
  • 1
    @lorentz like this?

    // query
    function getSession(AuthenticationBundle): CurrentSessionReport

    // command
    function sendEmail(EmailBundle): void
  • 2
    devRant should really have a code tag
Add Comment