Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function arguments in multiple lines. #17

Open
cossio opened this issue May 29, 2022 · 9 comments
Open

Function arguments in multiple lines. #17

cossio opened this issue May 29, 2022 · 9 comments

Comments

@cossio
Copy link
Contributor

cossio commented May 29, 2022

# Yes 
function my_large_function(argument1, argument2,
                           argument3, argument4,
                           argument5, x, y, z)

# No
function my_large_function(argument1, 
                           argument2,
                           argument3, 
                           argument4,
                           argument5,
                           x,
                           y,
                           z)

Any reason not to prefer the Blue style advice here:

function my_large_function(
    argument1, argument2,
    argument3, argument4,
    argument5, x, y, z
)
    # code
end

Notably, when there are many arguments in multiple lines, no argument is placed on the same line as the function name.
All arguments are at the same, one-level, indentation, so there is no custom indentation here and there are no alignment issues if, say, the function name changes.
Also, the closing parenthesis is alone in its own line, making very clear when the argument list stops and the code begins.
However it'd be fine that not every argument is on its own line (as enforced by Blue, but relaxed here).

@ChrisRackauckas
Copy link
Member

One per line is insane to read when you get to like 30 keyword arguments. Closing parenthesis is fine on its own line though.

@YingboMa what do you think?

@isaacsas
Copy link
Member

Given that a column width is being enforced, it shouldn’t be hard to see the closing parenthesis if it is on the same line as arguments. There is something to be said for saving vertical space too.

@isaacsas
Copy link
Member

It also (to my eyes), breaks the convention that the indentation can be quickly scanned to see where a function ends. Now one has to actively ignore parentheses that arise at the same indentation level (will editors handle that without issues when one uses code folding?).

@cossio
Copy link
Contributor Author

cossio commented May 29, 2022

Code folding is indeed a bit strange when the closing parenthesis is not indented. You get two folds: One for the args and another for the function body. But maybe that can be solved on the VS Code Julia Extension? julia-vscode/julia-vscode#2907

@isaacsas
Copy link
Member

That doesn’t seem too bad! But there are many different editors people use, and I’d worry a decent number of them may have issues.

@YingboMa
Copy link
Member

One per line is insane to read when you get to like 30 keyword arguments. Closing parenthesis is fine on its own line though.

Yeah, I agree. I made sure JuliaFormatter preserves

function my_large_function(argument1, argument2,
                           argument3, argument4,
                           argument5, x, y, z)
    ...
end

@cossio
Copy link
Contributor Author

cossio commented May 31, 2022

@YingboMa Is it guaranteed to preserve:

function my_large_function(
    argument1, argument2,
    argument3, argument4,
    argument5, x, y, z
)
    # code
end

too?

@ronisbr
Copy link

ronisbr commented Jun 26, 2023

Just my 2 cents.

Here I think BlueStyle version is better, especially when you have a lot of keywords with large names. Take a look at this snippet from PrettyTables.jl with BlueStyle and SciMLStyle:

    pinfo = _print_info(
        data;
        alignment = alignment,
        cell_alignment = cell_alignment,
        cell_first_line_only = cell_first_line_only,
        compact_printing = compact_printing,
        formatters = formatters,
        header = header,
        header_alignment = header_alignment,
        header_cell_alignment = header_cell_alignment,
        max_num_of_columns = max_num_of_columns,
        max_num_of_rows = max_num_of_rows,
        limit_printing = limit_printing,
        renderer = renderer,
        row_labels = row_labels,
        row_label_alignment = row_label_alignment,
        row_label_column_title = row_label_column_title,
        row_number_alignment = row_number_alignment,
        row_number_column_title = row_number_column_title,
        show_header = show_header,
        show_row_number = show_row_number,
        show_subheader = show_subheader,
        title = title,
        title_alignment = title_alignment
    )


    pinfo = _print_info(data; alignment = alignment,cell_alignment = cell_alignment,
                        cell_first_line_only = cell_first_line_only,
                        compact_printing = compact_printing, formatters = formatters,
                        header = header, header_alignment = header_alignment,
                        header_cell_alignment = header_cell_alignment,
                        max_num_of_columns = max_num_of_columns,
                        max_num_of_rows = max_num_of_rows, limit_printing = limit_printing,
                        renderer = renderer, row_labels = row_labels,
                        row_label_alignment = row_label_alignment,
                        row_label_column_title = row_label_column_title,
                        row_number_alignment = row_number_alignment,
                        row_number_column_title = row_number_column_title,
                        show_header = show_header, show_row_number = show_row_number,
                        show_subheader = show_subheader, title = title,
                        title_alignment = title_alignment)

IMHO is way easier to work with the first version to fix problems or update something.

@isaacsas
Copy link
Member

The counterpoint is that the blue style uses a lot more vertical screen space, thereby increasing the chance of being unable to fit all the code in a function on a single screen (especially on laptop screens). I find that a lot more of an obstacle than having multiple parameters per line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants