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

I enabled the dark theme.

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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

Mikael Johansson
100 posts / 1 project
Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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
66 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)
2 years, 10 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)
);
30 posts

I enabled the dark theme.

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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 :)

Mārtiņš Možeiko
2075 posts / 1 project
Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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.
Asaf Gartner
41 posts

Handmade Network Staff

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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.
岩倉 澪
144 posts / 1 project

riscy.tv host

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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
Simon Anciaux
794 posts
Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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.
30 posts

I enabled the dark theme.

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 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 :)
Ben Visness
48 posts

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

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 months ago
I use #1. Any function call with so many arguments I need to break it usually deserves line comments per argument anyway.
30 posts

I enabled the dark theme.

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 months ago
Thanks Ben :) One more tally for number 1!

(I also moved the results up to the first post)
11 posts
Func call code formatting survey (not as asinine as it sounds)
2 years, 10 months ago
Number 4
17 posts
Func call code formatting survey (not as asinine as it sounds)
2 years, 10 months ago
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)
2 years, 10 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
	);
30 posts

I enabled the dark theme.

Func call code formatting survey (not as asinine as it sounds)
2 years, 10 months ago
Updated results, much appreciated :)