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

Question: How to accomplish common function call formatting #3

Open
jordwalke opened this issue Dec 31, 2014 · 3 comments
Open

Question: How to accomplish common function call formatting #3

jordwalke opened this issue Dec 31, 2014 · 3 comments

Comments

@jordwalke
Copy link
Collaborator

It is very common to format source code as follows:

(* In ML languages with space separated "arguments" *)
let result =  myFunction x y {
  key1= 'long';
  key2='long';
}

// In JS style languages with parenthesis-wrapped comma-delimited arguments
var result = myFunction (x, y, {
  key1: 'long',
  key2: 'long'
});

It's even difficult for me to articulate exactly when this is the preferred formatting but I'll try:

  • The entire line will not fit within the allotted space and some line breaking is required.
  • Having the last argument to a function break into several lines eliminates any need for the //previous// items on the line to have to break onto new lines.

For example, suppose the following samples cannot fit onto a single line. Here are some correct (and incorrect) formatting examples:

 (* _Incorrect_ because even after last argument is broken,
     the original line is still too long *)
 let result =  myFunction reallyLongArgument reallyReallyLongArgument {
   key1= 'long';
   key2='long';
 }
 (* _Correct_ Every argument would need to be placed on their own lines *)
 let result =  myFunction
   reallyLongArgument
   reallyReallyLongArgument
   {key1= 'long'; key2='long'}




 (* _Incorrect_ because in order to fit the first line, the final
   argument had to be place on its own line.
 *)
 let result =  myFunction supposeThisIsReallyLong reallyReallyLongArgument {
   key1= 'long';
   key2='long';
 }
 anotherArgument

 (* _Correct_ *)
 let result =  myFunction
   supposeThisIsReallyLong
   reallyReallyLongArgument
   {key1= 'long'; key2='long'}
   anotherArgument



 (* _Incorrect_ because the last two arguments had to have
   their bodies broken up.
 *)
 let result =  myFunction reallyLongArgument reallyReallyLongArgument {
   key1= 'long';
   key2='long';
 } {
    key1='long';
    key2='long';
 }

 (* _Correct_*)
 let result =  myFunction
   reallyLongArgument
   reallyReallyLongArgument
   {key1= 'long'; key2='long'}
   {key1='long'; key2='long'}
@mjambon
Copy link
Member

mjambon commented Nov 28, 2015

For the last example, is the following correct, assuming each field is really long?

let result =  myFunction
   reallyLongArgument
   reallyReallyLongArgument
   {
     key1= 'long';
     key2='long'
   }
   {
     key1='long';
     key2='long'
   }

@jordwalke
Copy link
Collaborator Author

Yes, and I believe Easy_format would format the final example exactly like that if the keys had grown too long.

@mjambon
Copy link
Member

mjambon commented Nov 28, 2015

I would try to format the list of arguments as a Label(List(arguments 1..N-1), argument N). No guarantee.

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

2 participants