Questions tagged [coding-style]

**DO NOT USE! This tag refers to an entirely opinionated subject and is therefore no longer on-topic.** Questions that follow coding style and conventions.

DO NOT USE! This tag refers to an entirely opinionated subject and is therefore no longer on-topic.

Questions that follow coding style and conventions.

Coding-style or Programming style is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help to avoid introducing errors.

Questions relating to coding style: stylistic issues like braces and indentation or larger issues like refactoring, size of functions, and so forth.

Where can I ask these questions?

  • Process-level questions about coding conventions or style guides may be on-topic for Software Engineering. That also covers design-level questions

  • If you want to improve your style, you can ask for a Code Review.

  • Questions that ask for the “best style” or for advice in a specific situation are too subjective and/or too broad.

7652 questions
457
votes
14 answers

Why do most fields (class members) in Android tutorial start with `m`?

I know about camel case rules, but I'm confused with this m rule. What does it stand for? I'm a PHP developer. "We" use first letters of variables as indication of type, like 'b' for boolean, 'i' for integer and so on. Is 'm' a Java thing? Does it…
pambuk
  • 4,966
  • 4
  • 19
  • 20
422
votes
14 answers

Vim 80 column layout concerns

The way I do 80-column indication in Vim seems incorrect:set columns=80. At times I also set textwidth, but I want to be able to see and anticipate line overflow with the set columns alternative. This has some unfortunate side effects: I can't set…
cdleary
  • 63,281
  • 49
  • 155
  • 190
398
votes
13 answers

#pragma once vs include guards?

I'm working on a codebase that is known to only run on windows and be compiled under Visual Studio (it integrates tightly with excel so it's not going anywhere). I'm wondering if I should go with the traditional include guards or use #pragma once…
Matt Price
  • 38,782
  • 9
  • 34
  • 43
362
votes
17 answers

Declaring multiple variables in JavaScript

In JavaScript, it is possible to declare multiple variables like this: var variable1 = "Hello, World!"; var variable2 = "Testing..."; var variable3 = 42; ...or like this: var variable1 = "Hello, World!", variable2 = "Testing...", variable3…
Steve Harrison
  • 103,209
  • 15
  • 83
  • 71
352
votes
7 answers

Good Haskell source to read and learn from

What are some open source programs that use Haskell and can be considered to be good quality modern Haskell? The larger the code base, the better. I want to learn from their source code. I feel I'm past the point of learning from small code…
luispedro
  • 6,669
  • 3
  • 33
  • 45
328
votes
23 answers

What's the purpose of using braces (i.e. {}) for a single-line if or loop?

I'm reading some lecture notes of my C++ lecturer and he wrote the following: Use Indentation // OK Never rely on operator precedence - Always use parentheses // OK Always use a { } block - even for a single line // not OK, why ??? Const object…
JAN
  • 18,509
  • 49
  • 147
  • 268
305
votes
7 answers

Coding Conventions - Naming Enums

Is there a convention for naming enumerations in Java? My preference is that an enum is a type. So, for instance, you have an enum Fruit{Apple,Orange,Banana,Pear, ... } NetworkConnectionType{LAN,Data_3g,Data_4g, ... } I am opposed to naming…
Walter White
305
votes
12 answers

Should methods in a Java interface be declared with or without a public access modifier?

Should methods in a Java interface be declared with or without the public access modifier? Technically it doesn't matter, of course. A class method that implements an interface is always public. But what is a better convention? Java itself is not…
Benno Richters
  • 14,488
  • 14
  • 38
  • 41
304
votes
14 answers

What open source C++ static analysis tools are available?

Java has some very good open source static analysis tools such as FindBugs, Checkstyle and PMD. Those tools are easy to use, very helpful, runs on multiple operating systems and free. Commercial C++ static analysis products are available. Although…
jnancheta
  • 5,968
  • 8
  • 23
  • 18
299
votes
10 answers

Which comment style should I use in batch files?

I've been writing some batch files, and I ran into this user guide, which has been quite informative. One thing it showed me was that lines can be commented not just with REM, but also with ::. It says: Comments in batch code can be made by using a…
MikeFHay
  • 7,264
  • 4
  • 24
  • 43
294
votes
2 answers

80-characters / right margin line in Sublime Text 3

You can have 80-characters / right margin line in Netbeans, Text Mate and probably many, many more other IDEs. Is it possible to have it in Sublime Text 3 as well? Any option, plugin etc.?
trejder
  • 15,841
  • 23
  • 110
  • 207
291
votes
11 answers

Acronyms in CamelCase

I have a doubt about CamelCase. Suppose you have this acronym: Unesco = United Nations Educational, Scientific and Cultural Organization. You should write: unitedNationsEducationalScientificAndCulturalOrganization But what if you need to write the…
gal007
  • 5,504
  • 5
  • 35
  • 58
279
votes
26 answers

When is JavaScript's eval() not evil?

I'm writing some JavaScript code to parse user-entered functions (for spreadsheet-like functionality). Having parsed the formula I could convert it into JavaScript and run eval() on it to yield the result. However, I've always shied away from using…
Richard Turner
  • 11,186
  • 5
  • 31
  • 37
277
votes
9 answers

Why is it recommended to have empty line in the end of a source file?

Some code style tools recommend this and I remember seeing some unix command line tools warning about missing empty line. What is the reasoning for having an extra empty line?
Petteri H
  • 10,877
  • 11
  • 60
  • 94
256
votes
9 answers

Why does PEP-8 specify a maximum line length of 79 characters?

Why in this millennium should Python PEP-8 specify a maximum line length of 79 characters? Pretty much every code editor under the sun can handle longer lines. What to do with wrapping should be the choice of the content consumer, not the…
pcorcoran
  • 7,146
  • 6
  • 26
  • 26