<p>I tell my students this.  Pick a style and be consistent.  You will see religious wars over</p>

<pre><code>for(...)
{
    code
}
</code></pre>

<p>and </p>

<pre><code>for(...){
    code
}
</code></pre>

<p>Both are FINE. Pick one and be consistent.  I find the first easier to use because it makes finding curly brace errors butt simple.  But some prefer the other and that is AOK with me.  </p>

CC BY-SA 3.0
2017-07-06T23:29:14.950Z
I just recently heard the second style described as "Egyptian brackets" which totally cracked me up (also the style I use)
Mike Zamansky
CC BY-SA 3.0
2017-07-07T00:12:48.933Z
Yes, both are fine, but we all know the second method is better...=P
auden
CC BY-SA 3.0
2017-07-07T03:10:35.300Z
warning: missing space before opening brace
Cœur
CC BY-SA 3.0
2017-07-07T04:51:43.067Z
Ctrl + A, Ctrl + Shift + F.
pojo-guy
CC BY-SA 3.0
2017-07-07T21:23:29.423Z
If you accidentally comment out the `for` line, the first will still (unfortunately) compile, and the second will give you an error. :/
3Dave
CC BY-SA 3.0
2017-07-08T01:43:55.977Z
My habit: comment out the body of the loop.  Not a problem.
ncmathsadist
CC BY-SA 3.0
2017-07-08T17:48:05.250Z
@pojo-guy you don't need to Ctrl + A
Evorlor
CC BY-SA 3.0
2017-07-10T09:12:05.390Z
@DavidLively Uh... not really. That would have to be one weird for loop - are you in the habit of declaring the indexing variable outside of the loop? Unless you're doing pointer arithmetic, you're most likely going to get an undefined/undeclared variable error. The only case where you could reasonably expect commenting out the for line to compile would be the equivalent of `for (;;)` or `while (true)`. That can certainly lead to interesting errors, but they're also the kinds of loops that need a lot of scrutiny regardless :)
Luaan
CC BY-SA 3.0
2017-07-10T15:50:11.543Z
I declare the loop variable in the loop's initializer.  On second thought, most of the time I just comment out the whole thing, esp if it's a while loop.
ncmathsadist
CC BY-SA 3.0
2017-07-06T22:59:11.377Z
2017-07-07T00:47:32.687Z
2017-07-07T00:47:32.687Z
ncmathsadist
<p>The simple way is to use an IDE that does it for you - say Eclipse. Then you can be a bit sloppy for a few minutes and get it cleaned up. You can define the style you like in the options. You can pass your code to a buddy who has a different style and it gets transformed with a click or two. </p>

<p>But one option you have is to suggest to your students that they "ain't writing crap". They are writing literature. They are writing poetry. If it is beautiful you will find it easier to live with. E. E. Cummings cared a lot about indentation. </p>

<p>A coding style is a garment that you live in. It should be a comfortable one. Make it so. </p>

<p>A friend who is a lisp expert claims he can see the intent of a piece of lisp code (properly indented and parenthesized) at a glance. He means it literally. All he sees is the pattern of indentation. I have a guess that you can reach that level in Python. Java being less compact in general might not enable that as well. </p>

<p>However, you can sometimes see that a piece of code is <em>broken</em> by glancing at its indentation structure. </p>

<hr>

<p>Old person horror story. I once worked in Pascal on IBM mainframe terminals. You put a space before every semicolon since the search function would only work on contiguous blocks so mumble and mumble; required different searches. You always "spaced out" every identifier and regretted it when you didn't.  </p>

CC BY-SA 3.0
2017-07-07T02:48:47.003Z
Buffy and I must be from the same timeline! +1 for "let the IDE do it".
pojo-guy
CC BY-SA 3.0
2017-07-08T03:09:08.210Z
Lisp, IIRC, has the advantage (for that kind of thing) that its predominant indentation styles depend somewhat on the length of the function/special name on the previous line. Imagine if for loops were indented one space further than if blocks.
Random832
CC BY-SA 3.0
2017-07-08T17:28:06.463Z
I do a lot of my programming in terminal at the command line and am a power vi user.
ncmathsadist
CC BY-SA 3.0
2017-07-07T00:46:56.127Z
2017-07-07T00:46:56.127Z
Buffy
<p>I briefly discuss spacing, braces, and general readability. Then I open Eclipse and demonstrate [Ctrl]+a, [Ctrl]+i. This instantly indents your code according to a default standard (which is configurable). Since there are so many concepts to cover in class and limited time, this is one shortcut we take.</p>

CC BY-SA 3.0
2017-07-07T12:52:02.553Z
Hi Edwin! Could you please expand on this further? There really isn't much in this answer.
thesecretmaster
CC BY-SA 3.0
2017-07-07T12:43:02.210Z
2017-07-07T12:55:26.060Z
2017-07-07T12:55:26.060Z
Edwin Torres
<p>Simple answer: Yes.</p>

<ul>
<li>Standardization matters, arbitrary or not.  

<ul>
<li>Imagine if some chose to use punctuation in writing, and some didn't... talk about a nightmare of confusion.  </li>
<li>A basic standardization of code writing usually results with a higher efficiency when having to go back through the code for removals or additions... it will also make the job of whomever is grading the work that much easier.</li>
</ul></li>
</ul>

<p>I'd compare a basic standardization of spacing and braces to the same principal of basic training in the military.</p>

<ul>
<li>Basic training is there to teach one the basics, of which many things taught are not likely to be used by the unit one ends up in, as they will have their own ways of doing things.

<ul>
<li>So while an arbitrary business or project may have it's own standardization, one should still be taught a basic standardization of spacing, braces, and indentation.</li>
</ul></li>
</ul>

CC BY-SA 3.0
2017-07-10T09:17:59.660Z
Well, looking at your text... you chose your own punctuation in writing. The punctuation you're using is *not* proper English (and what style of English are you using anyway? There's many to choose from in the first place). Not a good way of reinforcing your opinion of "standardised formatting is so important" :) Now, I think we can all agree that there's plenty of things that are important - your text would be a lot harder to read if it didn't use periods or spaces. I assume your indentation is intentionally silly. But commas, periods, ellipsis... there's so many valid styles out there :)
Luaan
CC BY-SA 3.0
2017-07-10T14:24:07.597Z
I understand the point of view you're coming from, however I do disagree with it.  


Perhaps the following two versions of the same S.M.A.R.T Reporting Script I use for FreeNAS would demonstrate my point a bit better.  [S.M.A.R.T Report w/ formatting](https://pastebin.com/raw/rAUyXsMq) & [S.M.A.R.T Report w/o formatting](https://pastebin.com/raw/S7gYthgq)... which do you find easier to read and edit?  

Granted, in an [editor](https://1drv.ms/i/s!Aqp3KD9IuSlugrBVrxKf5QI73TcJyQ) it's a bit better, but not much
JW0914
CC BY-SA 3.0
2017-07-10T14:41:42.660Z
The first. But it's still *your* style of formatting. I'm all for readability, but where's the standardisation you speak so highly of? Is this a common bash formatting standard you're following, or just something that looks good and readable to you? The question is all about the conflicts among standards ("indent with four spaces!"), not the things people tend to agree on ("indent!"). You might be answering a different question. Would a script that uses four spaces (or a tab) to indent instead of your two be any worse (assuming all the other scripts in the context use the same style)?
Luaan
CC BY-SA 3.0
2017-07-10T18:08:10.423Z
No, the OP asked specifically _"Should I require students to follow a standard for assignments and team projects (perhaps conventions of their own choosing), or should I ignore these as trivialities?"_  Perhaps you misread that?  If the script with formatting applied is easier for one to read, then it would also, by default, be easier to grade than a script w/o formatting.
JW0914
CC BY-SA 3.0
2017-07-07T03:32:23.057Z
2017-07-07T03:32:23.057Z
JW0914
<p>Often times students (i am speaking of high-school leveled) dont like to be constraned too much. The important conventions you do enforce should be enough.
If you add more to it then the students might be feeling that you are demanding too much from them and they might enjoy classes less. </p>

<p>However if you still think that spacing is important to you then i suggest letting the students code in a IDE that has auto formatting abilities (*for example intellij Ctrl+Alt+L and eclipse Ctrl+Shift+F, which might suit you because i understand from your last questions that you teach java).</p>

<p>In those IDE the students are responsible for doing correct naming and and some other conventions. Indentation becomes the only thing you need to make sure they learn. If you do choose this method then just make sure they understand why its important to format the code properly. If you want to know how to make them understand it, i'm sure you can ask that here.</p>

CC BY-SA 3.0
2017-07-07T09:16:46.257Z
2017-07-07T09:16:46.257Z
Harry
<p>While all of these are important, some are more important than others.</p>

<ul>
<li>Local consistency over global consistency.</li>
<li>Style over the one true style.</li>
<li>Automation over completeness. (that is settle for a simple set of rules, that can be automated).</li>
</ul>

<p>I have worked of projects where every file had its own style. It was not a problem to read, but when a file had many styles it was. Switching style may take experience. There is more buy in when a person is involved with the decision. Therefore each pupil should choose a style and stick with it.</p>

<p>It is also easier if problems are found automatically and as early as possible. Therefore use an IDE that does it for you. Then as a second level of defence use a lint tool that detects problems. If these two can to do it then it is usually not worth it. However there is still a lot of judgement, that can not so easily be put into rules.</p>

CC BY-SA 3.0
2017-07-07T16:43:03.297Z
2017-07-07T16:43:03.297Z
ctrl-alt-delor
<p>All my workplaces have had a set style-guide and expected me to follow it. In some cases failure to follow the style would result in the build system complaining and lots of finger-pointing.</p>

<p>If your goal is to teach students how to code as a career, then set an arbitrary style-guide and enforce it. Even better would be to use different styles for each assignment.</p>

<p>Teach your students that any modern IDE worth using can be configured to require a style, and they shouldn't be wasting time trying to do such things manually.</p>

CC BY-SA 3.0
2017-07-07T19:55:10.140Z
Your second and third paragraphs seem to contradict each other. If the IDE can do it automatically, what good does asking for a different style in every assignment do?
meriton
CC BY-SA 3.0
2017-07-07T21:28:10.420Z
@meriton that way, they learn to adapt to different styles. I'm not sure that doing it every assignment is a good idea - in fact, that sounds horrible - but learning how to work using uncomfortable conventions is valuable. Take a look at Unreal 3 code sometime. Every Thing Is Capitalized, And The Code Is So Long That Intellesense Does Not Work. It's impossible to look at an identifier and tell what it is.
3Dave
CC BY-SA 3.0
2017-07-07T23:54:39.670Z
@meriton - gets the student used to working in different styles. let the student learn how to configure their editor/IDE to support that style.  Expose the student to different, well-known styles (google's style guide, the linux kernel style guide, etc).
ivanivan
CC BY-SA 3.0
2017-07-07T03:31:49.703Z
2017-07-07T06:45:45.350Z
2017-07-07T06:45:45.350Z
Michael McMaster
<p>As always once you start looking into a topic you will find that there's a whole history and reasoning behind it. </p>

<p>For example the infamous issue of where to place an opening curly bracket does actually make a difference. Placing it on the start of the next line creates a more symmetric image, since both the opening and the closing bracket are at the same indentation level, so this style makes more sense in languages where symmetry is important, like (old-fashioned) C++ with its patterns like new and delete, setup and shutdown, etc.. Using "symmetric" curly braces makes it easier to spot memory or reference leaks when you use objects that need to be cleaned up manually.</p>

<p>On the other hand in languages where you use a lot of anonymous functions like JavaScript or in programming styles that make extensive use of lambda functions there are actually cases where placing the opening curly bracket makes you more prone to bugs. Also I would argue that the readability is improved, since the function body is just part of one value, so to show that you are writing declarative code inside imperative code you may want to place the new line behind the opening curly bracket.</p>

<p>Just like that there's a rationale behind almost every coding style decision, so what I do and what I recommend is that you talk about the reasoning behind different styles and then let the students choose a style of their own.</p>

<p>The only things I would grade in papers and examns would be whether the coding style is consistent and adequate. For example every now and then I find code that was copy-pasted from the internet, which in itself is not an issue, but most tutorials optimize the code for readability on a web page, which of course is very different from what you would do in an IDE.</p>

<p>In the end don't forget that as soon as you start combining languages there is hardly ever one consistent coding style, so you will have to make up your mind which style you want to use anyway.</p>

CC BY-SA 3.0
2017-07-07T07:56:48.353Z
2017-07-07T07:56:48.353Z
Lars Kokemohr
<p>Our two deities are <strong>clarity</strong> and <strong>efficiency</strong>.  </p>

<p>Standardization makes a great deal of sense in industry, where large numbers of programmers may work with the same lines of code and must be able to make sense of each others' choices. However, I don't see value in enforcing particular style guides in an educational setting.</p>

<p>Different companies can require different norms.  If your students eventually enter the industry, a style guide is easy to read through if they can code, and is irrelevant if they can't.</p>

<p>When I teach my kids to worry about indentation, vertical spacing, variable names, etc, I teach them to always use this question as their foundation and their guiding star: <em>"what does</em> <strong><em>this</em></strong> <em>choice communicate?"</em>  </p>

<p>That is honestly already quite a lot to tackle, and I have found that my kids really do start working quite hard and thinking quite deeply about how to make sure that every line of code is as clean and clear as it can be.  </p>

<p>If my students can learn to scale this mountain, why would I ask for 4 spaces in place of a tab?</p>

CC BY-SA 3.0
2017-07-07T18:55:10.230Z
Having been a software architect for years, enforcing coding standards has been part of my responsibilities. Nevertheless, I fully agree with your assessment that this topic does not deserve significant classroom time, and I would wish more educators would take your stance. A consistent coding style is particularly valuable in long-running projects with big teams, but a typical student assignment is neither. Also, I find your emphasis on readability over formatting details spot on, because formatting can be established by automated tools, while naming and design still require human judgment.
meriton
CC BY-SA 3.0
2017-07-06T22:01:02.887Z
2017-07-17T18:33:48.160Z
2017-07-17T18:33:48.160Z
Ben I.
<p>I think placing some emphasis on style and conventions is important, yes -- learning how to follow style guides is a skill worth training and learning to be detail-oriented is an important meta-skill.</p>

<p>That said, I think it's fine to introduce some leniency by allowing students to use whatever convention they want <em>as long as they're consistent</em>, especially for things like curly brace placement or tabs vs spaces. If the goal is to train students to acquire a sense of craftmanship, having them demonstrate they know how to be consistent is enough, I think.</p>

<p>Some formatting rules do seem to be more universal though (across languages and style guides), such as adding spaces around binary operators. It's probably worth enforcing rules like those, to make sure students acquire correct "muscle memory".</p>

<p>I think the answer to your question might also vary depending on age -- the older students are, the more we should expect from them. In particular, once students are at the undergrad level, they're basically adults and expecting them to be detail-oriented seems pretty reasonable to me, especially if they plan on doing CS as a career. After all, sloppiness in the small often tends to translate into sloppiness in the large, and churning out students who think it's ok to cut corners seems somewhat irresponsible to me.</p>

<p>One middle ground between enforcing and ignoring convention would be to provide students with a linter (which they can perhaps tune with your permission?). If you make students responsible for turning in code that perfectly passes the linter as a binary pass/fail sort of thing, you'll make sure standards are maintained without putting too much pressure on the students. This also has the added benefit of being more representative of how development is actually done in industry.</p>

<p>I would probably introduce these tools only after your students have had a chance to develop a sense of consistency and craftsmanship, though.</p>

CC BY-SA 3.0
2017-07-07T09:09:14.623Z
+1 for the comments on consistency. That was my first thought. Let them choose their own style, because it's a fun personal preference to get irrationally angry about (so you'd get plenty of push-back from people who already learnt how to code and decided on their favourite brace style, if you did try to enforce one). But penalise them if they aren't consistent within their own code, or with other code written as part of a group project.
Muzer
CC BY-SA 3.0
2017-07-07T13:59:11.337Z
On the other hand, is it not important to teach students that, out in the real world, you can't always use your preferred style? Getting them used to using tools for formatting (whether it be IDE-based or a script they use, etc.) provides a benefit; I've found that once students get in the habit of using whatever style they want, even when they're in college it's hard to get them to stick to a style guide even when tools are available to easily modify the style.
JAB
CC BY-SA 3.0
2017-07-07T19:08:04.923Z
I disagree strongly. Attention to detail is best reinforced where it actually matters and through natural consequences. For instance, having to track down one's off-by-one errors communicates the need for caring about details far more effectively than being asked to adhere to arbitrary rules "because the teacher said so" ever could. Also, while I fully agree that craftsmanship is important, code formatting is a very small part of that -  and one of the least important ones, because it can be (and often is) fully automated.
meriton
CC BY-SA 3.0
2017-07-07T19:11:25.933Z
That is, if you want to be close to the industry, give your students development environments that automate code formatting. For many languages, even open source development environments can do this :-)
meriton
CC BY-SA 3.0
2017-07-06T22:36:22.653Z
2017-07-07T19:43:35.747Z
2017-07-07T19:43:35.747Z
Michael0x2a
<p>On open source projects and industry teams, there are often detailed style guides about how many spaces should be used for indents, line continuation, etc., and whether braces should go on their own line. While I have my preferences (such as spaces around binary operators), I acknowledge they are somewhat arbitrary. Should I require students to follow a standard for assignments and team projects (perhaps conventions of their own choosing), or should I ignore these as trivialities?</p>

<p>Of course, I would enforce more important conventions, such as proper indentation, appropriate naming, etc.</p>

<p><a href="https://i.sstatic.net/b9VkB.png" rel="noreferrer"><img src="https://i.sstatic.net/b9VkB.png" alt="December 10, 2001, Hackles cartoon, in which 2 programmers dispute formatting of curly braces"></a></p>

CC BY-SA 3.0
2017-07-07T18:04:53.703Z
Teach the students to use the formatter in the IDE they are using.  Eclipse has format as a save action so it happens all the time.  Then you can teach more important stuff.
Thorbjørn Ravn Andersen
CC BY-SA 3.0
2017-07-07T21:12:55.677Z
Start with Python. The problem almost solves itself.
3Dave
CC BY-SA 3.0
2017-07-08T05:50:19.757Z
@DavidLively Would you suggest Tabs, 4 spaces, or 2 spaces for indentation on Python?
phihag
CC BY-SA 3.0
2017-07-08T09:35:47.433Z
@phihag There is an [official style guide](https://www.python.org/dev/peps/pep-0008/) (PEP8) for Python.
Federico Poloni
CC BY-SA 3.0
2017-07-08T14:25:37.667Z
@phihag anything as long as they're consistent. My point was that Python is inherently less forgiving than other languages, not that it is a perfect, self-contained solution.
3Dave
CC BY-SA 3.0
2017-07-09T21:30:52.543Z
I have mentioned this question in meta as an example in a discussion on site scope, and specifically to what extent teaching programming falls within it. People will strong opinions either way may wish to visit https://cseducators.meta.stackexchange.com/q/172/1219
Peter Taylor
<coding-style>
Should teachers enforce standardization of spacing and braces?
# Should teachers enforce standardization of spacing and braces?

(Asked by: username_0 on 2017-07-06)

On open source projects and industry teams, there are often detailed style guides about how many spaces should be used for indents, line continuation, etc., and whether braces should go on their own line. While I have my preferences (such as spaces around binary operators), I acknowledge they are somewhat arbitrary. Should I require students to follow a standard for assignments and team projects (perhaps conventions of their own choosing), or should I ignore these as trivialities?

Of course, I would enforce more important conventions, such as proper indentation, appropriate naming, etc.

[![December 10, 2001, Hackles cartoon, in which 2 programmers dispute formatting of curly braces](https://i.sstatic.net/b9VkB.png)](https://i.sstatic.net/b9VkB.png)

**Tags:** coding-style

> **Comments:**
> **username_1**: Teach the students to use the formatter in the IDE they are using.  Eclipse has format as a save action so it happens all the time.  Then you can teach more important stuff.  
> **username_2**: Start with Python. The problem almost solves itself.  
> **username_3**: @DavidLively Would you suggest Tabs, 4 spaces, or 2 spaces for indentation on Python?  
> **username_4**: @username_3 There is an [official style guide](https://www.python.org/dev/peps/pep-0008/) (PEP8) for Python.  
> **username_2**: @username_3 anything as long as they're consistent. My point was that Python is inherently less forgiving than other languages, not that it is a perfect, self-contained solution.  
> **username_5**: I have mentioned this question in meta as an example in a discussion on site scope, and specifically to what extent teaching programming falls within it. People will strong opinions either way may wish to visit https://cseducators.meta.stackexchange.com/q/172/1219  

---

## 10 answers

### Answer by username_24 on 2017-07-06. Score: 22

Our two deities are **clarity** and **efficiency**.

Standardization makes a great deal of sense in industry, where large numbers of programmers may work with the same lines of code and must be able to make sense of each others' choices. However, I don't see value in enforcing particular style guides in an educational setting.

Different companies can require different norms. If your students eventually enter the industry, a style guide is easy to read through if they can code, and is irrelevant if they can't.

When I teach my kids to worry about indentation, vertical spacing, variable names, etc, I teach them to always use this question as their foundation and their guiding star: *"what does* ***this*** *choice communicate?"*

That is honestly already quite a lot to tackle, and I have found that my kids really do start working quite hard and thinking quite deeply about how to make sure that every line of code is as clean and clear as it can be.

If my students can learn to scale this mountain, why would I ask for 4 spaces in place of a tab?

> **Comments:**
> **username_21**: Having been a software architect for years, enforcing coding standards has been part of my responsibilities. Nevertheless, I fully agree with your assessment that this topic does not deserve significant classroom time, and I would wish more educators would take your stance. A consistent coding style is particularly valuable in long-running projects with big teams, but a typical student assignment is neither. Also, I find your emphasis on readability over formatting details spot on, because formatting can be established by automated tools, while naming and design still require human judgment.  

---

### Answer by username_25 on 2017-07-06. Score: 16

I think placing some emphasis on style and conventions is important, yes -- learning how to follow style guides is a skill worth training and learning to be detail-oriented is an important meta-skill.

That said, I think it's fine to introduce some leniency by allowing students to use whatever convention they want *as long as they're consistent*, especially for things like curly brace placement or tabs vs spaces. If the goal is to train students to acquire a sense of craftmanship, having them demonstrate they know how to be consistent is enough, I think.

Some formatting rules do seem to be more universal though (across languages and style guides), such as adding spaces around binary operators. It's probably worth enforcing rules like those, to make sure students acquire correct "muscle memory".

I think the answer to your question might also vary depending on age -- the older students are, the more we should expect from them. In particular, once students are at the undergrad level, they're basically adults and expecting them to be detail-oriented seems pretty reasonable to me, especially if they plan on doing CS as a career. After all, sloppiness in the small often tends to translate into sloppiness in the large, and churning out students who think it's ok to cut corners seems somewhat irresponsible to me.

One middle ground between enforcing and ignoring convention would be to provide students with a linter (which they can perhaps tune with your permission?). If you make students responsible for turning in code that perfectly passes the linter as a binary pass/fail sort of thing, you'll make sure standards are maintained without putting too much pressure on the students. This also has the added benefit of being more representative of how development is actually done in industry.

I would probably introduce these tools only after your students have had a chance to develop a sense of consistency and craftsmanship, though.

> **Comments:**
> **username_26**: +1 for the comments on consistency. That was my first thought. Let them choose their own style, because it's a fun personal preference to get irrationally angry about (so you'd get plenty of push-back from people who already learnt how to code and decided on their favourite brace style, if you did try to enforce one). But penalise them if they aren't consistent within their own code, or with other code written as part of a group project.  
> **username_27**: On the other hand, is it not important to teach students that, out in the real world, you can't always use your preferred style? Getting them used to using tools for formatting (whether it be IDE-based or a script they use, etc.) provides a benefit; I've found that once students get in the habit of using whatever style they want, even when they're in college it's hard to get them to stick to a style guide even when tools are available to easily modify the style.  
> **username_21**: I disagree strongly. Attention to detail is best reinforced where it actually matters and through natural consequences. For instance, having to track down one's off-by-one errors communicates the need for caring about details far more effectively than being asked to adhere to arbitrary rules "because the teacher said so" ever could. Also, while I fully agree that craftsmanship is important, code formatting is a very small part of that -  and one of the least important ones, because it can be (and often is) fully automated.  
> **username_21**: That is, if you want to be close to the industry, give your students development environments that automate code formatting. For many languages, even open source development environments can do this :-)  

---

### Answer by username_6 on 2017-07-06. Score: 7

I tell my students this.  Pick a style and be consistent.  You will see religious wars over
for(...)
{
    code
}

and 
for(...){
    code
}

Both are FINE. Pick one and be consistent.  I find the first easier to use because it makes finding curly brace errors butt simple.  But some prefer the other and that is AOK with me.

> **Comments:**
> **username_7**: I just recently heard the second style described as "Egyptian brackets" which totally cracked me up (also the style I use)  
> **username_8**: Yes, both are fine, but we all know the second method is better...=P  
> **username_9**: warning: missing space before opening brace  
> **username_10**: Ctrl + A, Ctrl + Shift + F.  
> **username_2**: If you accidentally comment out the `for` line, the first will still (unfortunately) compile, and the second will give you an error. :/  
> **username_6**: My habit: comment out the body of the loop.  Not a problem.  
> **username_11**: @username_10 you don't need to Ctrl + A  
> **username_12**: @DavidLively Uh... not really. That would have to be one weird for loop - are you in the habit of declaring the indexing variable outside of the loop? Unless you're doing pointer arithmetic, you're most likely going to get an undefined/undeclared variable error. The only case where you could reasonably expect commenting out the for line to compile would be the equivalent of `for (;;)` or `while (true)`. That can certainly lead to interesting errors, but they're also the kinds of loops that need a lot of scrutiny regardless :)  
> **username_6**: I declare the loop variable in the loop's initializer.  On second thought, most of the time I just comment out the whole thing, esp if it's a while loop.  

---

### Answer by username_13 on 2017-07-07. Score: 4

The simple way is to use an IDE that does it for you - say Eclipse. Then you can be a bit sloppy for a few minutes and get it cleaned up. You can define the style you like in the options. You can pass your code to a buddy who has a different style and it gets transformed with a click or two.

But one option you have is to suggest to your students that they "ain't writing crap". They are writing literature. They are writing poetry. If it is beautiful you will find it easier to live with. E. E. Cummings cared a lot about indentation.

A coding style is a garment that you live in. It should be a comfortable one. Make it so.

A friend who is a lisp expert claims he can see the intent of a piece of lisp code (properly indented and parenthesized) at a glance. He means it literally. All he sees is the pattern of indentation. I have a guess that you can reach that level in Python. Java being less compact in general might not enable that as well.

However, you can sometimes see that a piece of code is *broken* by glancing at its indentation structure.

---

Old person horror story. I once worked in Pascal on IBM mainframe terminals. You put a space before every semicolon since the search function would only work on contiguous blocks so mumble and mumble; required different searches. You always "spaced out" every identifier and regretted it when you didn't.

> **Comments:**
> **username_10**: username_13 and I must be from the same timeline! +1 for "let the IDE do it".  
> **username_14**: Lisp, IIRC, has the advantage (for that kind of thing) that its predominant indentation styles depend somewhat on the length of the function/special name on the previous line. Imagine if for loops were indented one space further than if blocks.  
> **username_6**: I do a lot of my programming in terminal at the command line and am a power vi user.  

---

### Answer by username_15 on 2017-07-07. Score: 2

I briefly discuss spacing, braces, and general readability. Then I open Eclipse and demonstrate [Ctrl]+a, [Ctrl]+i. This instantly indents your code according to a default standard (which is configurable). Since there are so many concepts to cover in class and limited time, this is one shortcut we take.

> **Comments:**
> **username_16**: Hi Edwin! Could you please expand on this further? There really isn't much in this answer.  

---

### Answer by username_17 on 2017-07-07. Score: 2

Simple answer: Yes.

* Standardization matters, arbitrary or not.
  + Imagine if some chose to use punctuation in writing, and some didn't... talk about a nightmare of confusion.
  + A basic standardization of code writing usually results with a higher efficiency when having to go back through the code for removals or additions... it will also make the job of whomever is grading the work that much easier.

I'd compare a basic standardization of spacing and braces to the same principal of basic training in the military.

* Basic training is there to teach one the basics, of which many things taught are not likely to be used by the unit one ends up in, as they will have their own ways of doing things.
  + So while an arbitrary business or project may have it's own standardization, one should still be taught a basic standardization of spacing, braces, and indentation.

> **Comments:**
> **username_12**: Well, looking at your text... you chose your own punctuation in writing. The punctuation you're using is *not* proper English (and what style of English are you using anyway? There's many to choose from in the first place). Not a good way of reinforcing your opinion of "standardised formatting is so important" :) Now, I think we can all agree that there's plenty of things that are important - your text would be a lot harder to read if it didn't use periods or spaces. I assume your indentation is intentionally silly. But commas, periods, ellipsis... there's so many valid styles out there :)  
> **username_17**: I understand the point of view you're coming from, however I do disagree with it.     Perhaps the following two versions of the same S.M.A.R.T Reporting Script I use for FreeNAS would demonstrate my point a bit better.  [S.M.A.R.T Report w/ formatting](https://pastebin.com/raw/rAUyXsMq) & [S.M.A.R.T Report w/o formatting](https://pastebin.com/raw/S7gYthgq)... which do you find easier to read and edit?    Granted, in an [editor](https://1drv.ms/i/s!Aqp3KD9IuSlugrBVrxKf5QI73TcJyQ) it's a bit better, but not much  
> **username_12**: The first. But it's still *your* style of formatting. I'm all for readability, but where's the standardisation you speak so highly of? Is this a common bash formatting standard you're following, or just something that looks good and readable to you? The question is all about the conflicts among standards ("indent with four spaces!"), not the things people tend to agree on ("indent!"). You might be answering a different question. Would a script that uses four spaces (or a tab) to indent instead of your two be any worse (assuming all the other scripts in the context use the same style)?  
> **username_17**: No, the OP asked specifically _"Should I require students to follow a standard for assignments and team projects (perhaps conventions of their own choosing), or should I ignore these as trivialities?"_  Perhaps you misread that?  If the script with formatting applied is easier for one to read, then it would also, by default, be easier to grade than a script w/o formatting.  

---

### Answer by username_18 on 2017-07-07. Score: 1

Often times students (i am speaking of high-school leveled) dont like to be constraned too much. The important conventions you do enforce should be enough.
If you add more to it then the students might be feeling that you are demanding too much from them and they might enjoy classes less.

However if you still think that spacing is important to you then i suggest letting the students code in a IDE that has auto formatting abilities (\*for example intellij Ctrl+Alt+L and eclipse Ctrl+Shift+F, which might suit you because i understand from your last questions that you teach java).

In those IDE the students are responsible for doing correct naming and and some other conventions. Indentation becomes the only thing you need to make sure they learn. If you do choose this method then just make sure they understand why its important to format the code properly. If you want to know how to make them understand it, i'm sure you can ask that here.


---

### Answer by username_19 on 2017-07-07. Score: 1

While all of these are important, some are more important than others.

* Local consistency over global consistency.
* Style over the one true style.
* Automation over completeness. (that is settle for a simple set of rules, that can be automated).

I have worked of projects where every file had its own style. It was not a problem to read, but when a file had many styles it was. Switching style may take experience. There is more buy in when a person is involved with the decision. Therefore each pupil should choose a style and stick with it.

It is also easier if problems are found automatically and as early as possible. Therefore use an IDE that does it for you. Then as a second level of defence use a lint tool that detects problems. If these two can to do it then it is usually not worth it. However there is still a lot of judgement, that can not so easily be put into rules.


---

### Answer by username_20 on 2017-07-07. Score: 0

All my workplaces have had a set style-guide and expected me to follow it. In some cases failure to follow the style would result in the build system complaining and lots of finger-pointing.

If your goal is to teach students how to code as a career, then set an arbitrary style-guide and enforce it. Even better would be to use different styles for each assignment.

Teach your students that any modern IDE worth using can be configured to require a style, and they shouldn't be wasting time trying to do such things manually.

> **Comments:**
> **username_21**: Your second and third paragraphs seem to contradict each other. If the IDE can do it automatically, what good does asking for a different style in every assignment do?  
> **username_2**: @username_21 that way, they learn to adapt to different styles. I'm not sure that doing it every assignment is a good idea - in fact, that sounds horrible - but learning how to work using uncomfortable conventions is valuable. Take a look at Unreal 3 code sometime. Every Thing Is Capitalized, And The Code Is So Long That Intellesense Does Not Work. It's impossible to look at an identifier and tell what it is.  
> **username_22**: @username_21 - gets the student used to working in different styles. let the student learn how to configure their editor/IDE to support that style.  Expose the student to different, well-known styles (google's style guide, the linux kernel style guide, etc).  

---

### Answer by username_23 on 2017-07-07. Score: 0

As always once you start looking into a topic you will find that there's a whole history and reasoning behind it.

For example the infamous issue of where to place an opening curly bracket does actually make a difference. Placing it on the start of the next line creates a more symmetric image, since both the opening and the closing bracket are at the same indentation level, so this style makes more sense in languages where symmetry is important, like (old-fashioned) C++ with its patterns like new and delete, setup and shutdown, etc.. Using "symmetric" curly braces makes it easier to spot memory or reference leaks when you use objects that need to be cleaned up manually.

On the other hand in languages where you use a lot of anonymous functions like JavaScript or in programming styles that make extensive use of lambda functions there are actually cases where placing the opening curly bracket makes you more prone to bugs. Also I would argue that the readability is improved, since the function body is just part of one value, so to show that you are writing declarative code inside imperative code you may want to place the new line behind the opening curly bracket.

Just like that there's a rationale behind almost every coding style decision, so what I do and what I recommend is that you talk about the reasoning behind different styles and then let the students choose a style of their own.

The only things I would grade in papers and examns would be whether the coding style is consistent and adequate. For example every now and then I find code that was copy-pasted from the internet, which in itself is not an issue, but most tutorials optimize the code for readability on a web page, which of course is very different from what you would do in an IDE.

In the end don't forget that as soon as you start combining languages there is hardly ever one consistent coding style, so you will have to make up your mind which style you want to use anyway.


---

