Does line wrapping help with code readability?
Is there a generally accepted etiquette for using line continuations?
Why use this:
SomeMethod(int someInt, Object someObject, String someString, bool someBool) { ... }
Instead of this:
SomeMethod(int someInt, Object someObject, String someString, bool someBool) { ... }
Edit: re-worded my question from line continuation to line wrapping
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
History: The name C is derived from an earlier programming language called BCPL (Basic Combined Programming Language). BCPL had another language based on it called B: the first letter in BCPL.
Now that we've clarified that this isn't to do with actual line-continuation characters and simply line-wrapping - you tell me. This:
IEnumerable<int> orderIDs = context.Customers.Where(c => c.CustomerID >= 1 && c.CustomerID <= 10).Select(c => c.Orders).SelectMany(o => o).OrderBy(o => o.OrderDate).Select(o => o.OrderID);
Or this?
IEnumerable<int> orderIDs = context .Customers .Where(c => c.CustomerID >= 1 && c.CustomerID <= 10) .Select(c => c.Orders) .SelectMany(o => o) .OrderBy(o => o.OrderDate) .Select(o => o.OrderID);
Which would you rather read?
Line continuations are not used in C#, since an explicit line terminator (;
) is required.
If you're asking, in terms of style, whether it's a good idea to break a line into multiple lines, that's debatable. The StyleCop rules force a line to either be defined on a single line, or for every element to be on a separate line. I personally think this is a good guideline, and I usually choose to break a line completely into its parts if it's too long to fit into a good 80-90 character wide editor.
Edit in response to your new question:
In this case, I would follow the guidelines above. Personally, in your specific case, I'd leave this on one line:
SomeMethod(int someInt, Object someObject, String someString, bool someBool) { ... }
This is a nice, short moethod declaration, and I see no reason to split it. I'd only split it if the number of arguments, and the lengths of the types, became far to long for one line of text.
If you do split it, however, I'd split it into separate lines for each argument:
SomeMethod( int someInt, Object someObject, String someString, bool someBool) { ... }
This way, at least it's obvious how and why it's split, and a developer won't accidentally skip one argument since two are on a single line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With