handmade.network » Forums » Func call code formatting survey (not as asinine as it sounds)
drjeats
29 posts

I enabled the dark theme.

#12494 Func call code formatting survey (not as asinine as it sounds)
1 month ago Edited by drjeats on July 18, 2017, 12:36 a.m. 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

Telash
Mikael Johansson
43 posts
1 project
#12495 Func call code formatting survey (not as asinine as it sounds)
1 month ago

I always do nr4. Nr3 is fine to. The rest looks weird to me.
Oswald_Hurlem
Oswald Hurlem
49 posts
1 project

Self-employed. Working on YAVE and other less ambitious games. Californian, iconoclast. I like angry music + games w/ guns in them.

#12496 Func call code formatting survey (not as asinine as it sounds)
1 month ago Edited by Oswald Hurlem on July 16, 2017, 12:41 a.m.

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)
);
drjeats
29 posts

I enabled the dark theme.

#12497 Func call code formatting survey (not as asinine as it sounds)
1 month ago

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 :)

mmozeiko
Mārtiņš Možeiko
1436 posts
1 project
#12498 Func call code formatting survey (not as asinine as it sounds)
1 month ago

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.
AsafG
Asaf Gartner
29 posts
#12499 Func call code formatting survey (not as asinine as it sounds)
1 month ago

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.
miotatsu
岩倉 澪
107 posts
1 project

riscy.tv host

#12502 Func call code formatting survey (not as asinine as it sounds)
1 month ago Edited by 岩倉 澪 on July 16, 2017, 9:39 a.m.

I tend to do #1 or #3 and usually only if it is over 80 chars as a single line
mrmixer
Simon Anciaux
241 posts
#12503 Func call code formatting survey (not as asinine as it sounds)
1 month ago Edited by Simon Anciaux on July 16, 2017, 2:01 p.m. 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.
drjeats
29 posts

I enabled the dark theme.

#12511 Func call code formatting survey (not as asinine as it sounds)
1 month ago Edited by drjeats on July 17, 2017, 5:07 a.m. Reason: updating results

[EDIT] Moving the results (and updating them) to the first post[/EDIT]

Thank you so much everyone :)
[email protected]
Ben Visness
3 posts

Handmade Math contributor, education beta tester, and general lurker

#12514 Func call code formatting survey (not as asinine as it sounds)
1 month ago

I use #1. Any function call with so many arguments I need to break it usually deserves line comments per argument anyway.
drjeats
29 posts

I enabled the dark theme.

#12515 Func call code formatting survey (not as asinine as it sounds)
1 month ago

Thanks Ben :) One more tally for number 1!

(I also moved the results up to the first post)
the_calling
11 posts
#12520 Func call code formatting survey (not as asinine as it sounds)
1 month ago

Number 4
D3zmodos
8 posts
#12525 Func call code formatting survey (not as asinine as it sounds)
1 month ago

I usually use 3 or 4 depending on whether or not there is an obvious grouping of arguments.
empulse
Rayalan Kenyon
11 posts

20 y/o recent college graduate
Interested in game development

#12527 Func call code formatting survey (not as asinine as it sounds)
1 month ago

#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
	);
drjeats
29 posts

I enabled the dark theme.

#12528 Func call code formatting survey (not as asinine as it sounds)
1 month ago

Updated results, much appreciated :)