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

I enabled the dark theme.

#12494 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
95 posts / 1 project
#12495 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months ago

I always do nr4. Nr3 is fine to. The rest looks weird to me.

The biggest obstacle to great software is lack of motivation. Motivate each other!
Instead of reinventing the wheel, we should put chariot wheels on jet planes!
Oswald_Hurlem
Oswald Hurlem
66 posts / 1 project

Working on Swedish Cubes for Unity. You could say I'm a real blockhead!!

#12496 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
30 posts

I enabled the dark theme.

#12497 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
1831 posts / 1 project
#12498 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
34 posts

Handmade Network Staff

#12499 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
岩倉 澪
133 posts / 1 project

riscy.tv host

#12502 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
491 posts
#12503 Func call code formatting survey (not as asinine as it sounds)
1 year, 5 months 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
30 posts

I enabled the dark theme.

#12511 Func call code formatting survey (not as asinine as it sounds)
1 year, 4 months 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
23 posts

HMN technical staff, Handmade Math contributor, web developer, etc.

#12514 Func call code formatting survey (not as asinine as it sounds)
1 year, 4 months ago

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

I enabled the dark theme.

#12515 Func call code formatting survey (not as asinine as it sounds)
1 year, 4 months 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 year, 4 months ago

Number 4
D3zmodos
15 posts
#12525 Func call code formatting survey (not as asinine as it sounds)
1 year, 4 months 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 year, 4 months 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
30 posts

I enabled the dark theme.

#12528 Func call code formatting survey (not as asinine as it sounds)
1 year, 4 months ago

Updated results, much appreciated :)