Handmade Network»Forums
29 posts
I enabled the dark theme.
Func call code formatting survey (not as asinine as it sounds)
Edited by drjeats on Reason: updating results
Hey handmade friends, just a survey:

How do you like to split your function calls onto multiple lines? (choose as many as apply)


  1. Open paren on same line

    1
    2
    3
    4
    5
    somefunction(
        first_argument,
        second_argument,
        third_argument
    );
    


  2. Open paren on new line
    1
    2
    3
    4
    5
    6
    somefunction
    (
        first_argument,
        second_argument,
        third_argument,
    );
    


  3. No newline on first argument, align arguments
    1
    2
    3
    somefunction(first_argument,
                 second_argument,
                 third_argument);
    


  4. Break only as needed, no newline on first argument, align arguments
    1
    2
    somefunction(first_argument, second_argument,
                 third_argument, fourth_argument);
    


  5. Break only as needed, just indent subsequent lines
    1
    2
    somefunction(first_argument, second_argument,
        third_argument, fourth_argument);
    


  6. None of the above

  7. Never, or very rarely

The purpose of this is to help me design a little language I'm working on for funsies.


[EDIT]Results, updated not-really-live![/EDIT]

Here are the results, including responses from a couple of other gamedev discord servers.

Believe it or not, there was somebody who has written a #2 or two! However, they did quality it heavily xD

1
2
3
4
5
6
7
Open paren on same line:                                              7
Open paren on new line:                                               1 (but only when it's really big)
No newline on first argument, align arguments:                        5
Break only as needed, no newline on first argument, align arguments:  12
Break only as needed, just indent subsequent lines:                   4
None of the above:                                                    1
Never or very rarely:                                                 1

Mikael Johansson
99 posts / 1 project
Func call code formatting survey (not as asinine as it sounds)
I always do nr4. Nr3 is fine to. The rest looks weird to me.
Oswald Hurlem
59 posts / 1 project
Working on Swedish Cubes for Unity. You could say I'm a real blockhead!!
Func call code formatting survey (not as asinine as it sounds)
Edited by Oswald Hurlem on
1. Unless the arguments lend themselves to obvious groupings, such as
1
2
3
4
memcpy(
    SourceBuffer, SourceBufferSize,
    DestBuffer, DestBufferSize
);


The more "modern" the language, the rarer this is, especially if they have tuples. Example for improbable language which has tuples but not a sized array type:
1
2
3
4
memcpy(
    (SourceBuffer, SourceBufferSize),
    (DestBuffer, DestBufferSize)
);
29 posts
I enabled the dark theme.
Func call code formatting survey (not as asinine as it sounds)
Thanks guys!

Watch me make a languages with tuples, but no sized arrays type..jk. xD

I'm not certain yet I want to add tuples to this, there's a few grammar concerns to work through first :)

Mārtiņš Možeiko
2559 posts / 2 projects
Func call code formatting survey (not as asinine as it sounds)
I use combination of 4 and 5. I don't align arguments much, but I group them depending on what they mean.
For example:
1
2
3
4
HWND window = CreateWindowExW(WS_EX_APPWINDOW, wc.lpszClassName, wc.lpszClassName,
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, instance, &state);

Because x, y, width, height kind of belongs together, I keep them on separate line.
Asaf Gartner
64 posts / 2 projects
Handmade Network Staff
Func call code formatting survey (not as asinine as it sounds)
I usually do #1 when there are lots of arguments or when I want to comment on one or more of the arguments. I also sometimes do the grouping that Oswald and mmozeiko talked about.
I wouldn't mind working with the other styles. I'd probably make a snarky comment about #2 (probably something involving Picasso), but it's fine as well.
Neo Ar
165 posts / 1 project
riscy.tv host
Func call code formatting survey (not as asinine as it sounds)
Edited by Neo Ar on
I tend to do #1 or #3 and usually only if it is over 80 chars as a single line
Simon Anciaux
1337 posts
Func call code formatting survey (not as asinine as it sounds)
Edited by Simon Anciaux on Reason: Typo
I use 4coder line wrapping so it's displayed as 4 but the file doesn't get any new lines.
When I do it manually I use mmozeiko style.
29 posts
I enabled the dark theme.
Func call code formatting survey (not as asinine as it sounds)
Edited by drjeats on Reason: updating results
[EDIT] Moving the results (and updating them) to the first post[/EDIT]

Thank you so much everyone :)
Ben Visness
109 posts / 9 projects
HMN lead.
Func call code formatting survey (not as asinine as it sounds)
I use #1. Any function call with so many arguments I need to break it usually deserves line comments per argument anyway.
29 posts
I enabled the dark theme.
Func call code formatting survey (not as asinine as it sounds)
Thanks Ben :) One more tally for number 1!

(I also moved the results up to the first post)
10 posts
Func call code formatting survey (not as asinine as it sounds)
Number 4
19 posts
Func call code formatting survey (not as asinine as it sounds)
I usually use 3 or 4 depending on whether or not there is an obvious grouping of arguments.
Rayalan Kenyon
11 posts
20 y/o recent college graduate Interested in game development
Func call code formatting survey (not as asinine as it sounds)
#1 with grouping if I want certain arguments to go together
only when the function call makes the line really long (~120+ characters)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
	__sys_state.window = CreateWindowExA(
		0,
		wc.lpszClassName,
		"",
		WS_OVERLAPPEDWINDOW,	
		CW_USEDEFAULT, CW_USEDEFAULT,
		0, 0,
		NULL, NULL,
		instance,
		NULL
	);
29 posts
I enabled the dark theme.
Func call code formatting survey (not as asinine as it sounds)
Updated results, much appreciated :)