Click here to Skip to main content
14,640,818 members

The Insider News

   

The Insider News is for breaking IT and Software development news. Post your news, your alerts and your inside scoops. This is an IT news-only forum - all off-topic, non-news posts will be removed. If you wish to ask a programming question please post it here.

Get The Daily Insider direct to your mailbox every day. Subscribe now!

 
GeneralRe: New Thunderbolt security flaws affect systems shipped before 2019 Pin
David O'Neil11-May-20 6:39
professionalDavid O'Neil11-May-20 6:39 
GeneralRe: New Thunderbolt security flaws affect systems shipped before 2019 Pin
Nelek11-May-20 7:05
protectorNelek11-May-20 7:05 
GeneralRe: New Thunderbolt security flaws affect systems shipped before 2019 Pin
Richard Deeming11-May-20 9:32
mveRichard Deeming11-May-20 9:32 
NewsWriting more succinct C# Pin
Kent Sharkey10-May-20 10:00
staffKent Sharkey10-May-20 10:00 
GeneralRe: Writing more succinct C# Pin
Super Lloyd10-May-20 16:01
MemberSuper Lloyd10-May-20 16:01 
GeneralRe: Writing more succinct C# Pin
Bernhard Hiller10-May-20 20:58
MemberBernhard Hiller10-May-20 20:58 
GeneralRe: Writing more succinct C# Pin
Member 798912210-May-20 21:36
MemberMember 798912210-May-20 21:36 
GeneralRe: Writing more succinct C# Pin
Member 798912210-May-20 22:53
MemberMember 798912210-May-20 22:53 
I never understood how putting braces on a separate line "improves readability". Imagine a fiction text, a short story or novel, where each comma, semicolon or full stop is put on a line by itself: Would that improve readability?

To me: Certainly not. 30-40 years ago, technical documentation was ridden by a wave of "Structured writing": Everything should be a bullet point, a paragraph, a chapter in an n-level structure (with no limit on n - I saw one manual of thirteen chapter levels!), or whatever. Anything but "unstructured text" - a two-paragraph sentence was a sign of missing structure. The structure was the essential thing. I had a feeling that contents was somewhere between inessential and absent. Fortunately, the most extreme "structured writing" ideas faded away.

If a programmer does not have the mental capacity to process both a premise and a conclusion as a whole, as one unit, but demand a format that says, e.g.

- We are deviating from a linear sequence of actions: This is a break of flow, so we will prepare you for it by adding a blank line before this break.
- We are going to chekck out something, so look out: Here is an 'if'
- Even though you now know we will test something, we add puctuation to tell you where the condition starts: an opening parenthesis.
- Now comes the condition: age < 12
- To make sure that you understand that we are done with the condition, we have added a closing parentheses.
- Even though we are done with the condition and ready to go on with the action, we have added an opening brace so that there is no doubt that the action starts here.
- To make sure that you don't overlook the fact that this is a conditional action, we put that brace on a new line.
- On the next line, we have stated the action: charge = child_fare
- To make sure that you understand which actions are conditional, we have indented those statements by four positions.
- To make sure that you see that this is one complete action, we have added a semicolon at the end.
- To make sure that you see that this is the end of all conditional actions, we have marked it with a closing brace.
- To make sure that you don't overlook that this is the end of the conditional actions, we have put the closing brace on a line by itself.
- To make sure that you don't overlook that we now return to actions that are unconditionally executed, we set it off by a blank line.

All of this is explicitly expressed when code goes like (C style):
[blank line]
if (age < 12)
{
    charge = childfare;
}
[blank line]
rather than (Pascal style):
if age < 1 then charge = childfare;
Pascal does require the 'then' keyword, but the closing semicolon may be superfluous, needed only if what follows is a block. (A single statement is a block.)

Lots of C programmers insist that adding a lot of non-action syntactic elements, such as parentheses, braces, blank lines, ..., although they provide no problem/action specific information, they are essential for understanding problem or solution actions. We do mentally process the entire list of "decorations" quoted above to gain this understanding. I am not claiming that costs a lot of effort, but it is there.

I see it as a reminiscence of the 'structured writing' idea, of 'structure before conents'. Obviously you e.g. indicate (usually by indenting) a set of conditional actions. If (the language designers wasn't capable of handling a single action as a block, so you must add braces around it, or or require you to put parentheses around a condition), you must of course {do that}. But I do !confuse syntactical workarounds with readability!

I know from experience that it helps to double space my code when showing it to others. Even if the opening brace is at the end of the line above, that is inessential - the other person may even overlook that there is a completely blank line before, say, the loop body (rather than a brace line). He may overlook that there are blank lines between every statement: Some people put blank lines around every "structured" statement, such as if-statements, so the difference from double-spacing is minimal.

You might argue that doublespacing improves readability indeed. Then, leave it to the display or print function! When you work on a method of 30-40 statements, you should be able to see all on the screen, without having to scroll up and down over three screenfuls!
GeneralRe: Writing more succinct C# Pin
Eddy Vluggen11-May-20 2:55
professionalEddy Vluggen11-May-20 2:55 
GeneralRe: Writing more succinct C# Pin
Member 798912211-May-20 4:42
MemberMember 798912211-May-20 4:42 
GeneralRe: Writing more succinct C# Pin
Eddy Vluggen11-May-20 4:59
professionalEddy Vluggen11-May-20 4:59 
GeneralRe: Writing more succinct C# Pin
Member 798912211-May-20 6:27
MemberMember 798912211-May-20 6:27 
GeneralRe: Writing more succinct C# Pin
Eddy Vluggen11-May-20 7:06
professionalEddy Vluggen11-May-20 7:06 
GeneralRe: Writing more succinct C# Pin
Member 798912211-May-20 7:14
MemberMember 798912211-May-20 7:14 
GeneralRe: Writing more succinct C# Pin
Eddy Vluggen11-May-20 7:23
professionalEddy Vluggen11-May-20 7:23 
GeneralRe: Writing more succinct C# Pin
David O'Neil11-May-20 5:10
professionalDavid O'Neil11-May-20 5:10 
GeneralRe: Writing more succinct C# Pin
Nelek11-May-20 7:13
protectorNelek11-May-20 7:13 
GeneralRe: Writing more succinct C# Pin
Member 798912211-May-20 7:33
MemberMember 798912211-May-20 7:33 
GeneralRe: Writing more succinct C# Pin
#realJSOP11-May-20 1:11
mva#realJSOP11-May-20 1:11 
GeneralRe: Writing more succinct C# Pin
Member 798912211-May-20 1:32
MemberMember 798912211-May-20 1:32 
GeneralRe: Writing more succinct C# Pin
#realJSOP11-May-20 2:05
mva#realJSOP11-May-20 2:05 
GeneralRe: Writing more succinct C# Pin
Member 798912211-May-20 6:19
MemberMember 798912211-May-20 6:19 
GeneralRe: Writing more succinct C# Pin
Kevin McFarlane11-May-20 6:45
MemberKevin McFarlane11-May-20 6:45 
NewsScientists obtain 'lucky' image of Jupiter Pin
Kent Sharkey10-May-20 10:00
staffKent Sharkey10-May-20 10:00 
GeneralRe: Scientists obtain 'lucky' image of Jupiter Pin
Nelek11-May-20 7:16
protectorNelek11-May-20 7:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.