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.

7804 questions
181
votes
31 answers

Why use prefixes like m_ on data members in C++ classes?

A lot of C++ code uses syntactical conventions for marking up data members. Common examples include m_memberName for public members (where public members are used at all) _memberName for private members or all members Others try to enforce using…
VoidPointer
  • 17,651
  • 15
  • 54
  • 58
180
votes
12 answers

Is nested function a good approach when required by only one function?

Let's say that a function A is required only by function B, should A be defined inside B? Simple example. Two methods, one called from another: def method_a(arg): some_data = method_b(arg) def method_b(arg): return some_data In Python we…
nukl
  • 10,073
  • 15
  • 42
  • 58
179
votes
4 answers

Why should I use var instead of a type?

Possible Duplicate: ReSharper and var After I have installed ReSharper it demands(by warnings) that I use var whenever possible, for example UnhandledExceptionEventArgs ue = (UnhandledExceptionEventArgs) t; ReSharper wants to turn it into var ue…
IAdapter
  • 62,595
  • 73
  • 179
  • 242
179
votes
8 answers

Are there any coding standards for JavaScript?

What are the established coding standards for JavaScript?
Pafjo
  • 4,979
  • 3
  • 23
  • 31
178
votes
5 answers

Python style - line continuation with strings?

In trying to obey the python style rules, I've set my editors to a max of 79 cols. In the PEP, it recommends using python's implied continuation within brackets, parentheses and braces. However, when dealing with strings when I hit the col limit,…
sjmh
  • 3,330
  • 4
  • 23
  • 27
177
votes
8 answers

Is it good style to explicitly return in Ruby?

Coming from a Python background, where there is always a "right way to do it" (a "Pythonic" way) when it comes to style, I'm wondering if the same exists for Ruby. I've been using my own style guidelines but I'm thinking about releasing my source…
Sasha Chedygov
  • 127,549
  • 26
  • 102
  • 115
176
votes
14 answers

do..end vs curly braces for blocks in Ruby

I have a coworker who is actively trying to convince me that I should not use do..end and instead use curly braces for defining multiline blocks in Ruby. I'm firmly in the camp of only using curly braces for short one-liners and do..end for…
Blake Taylor
  • 9,217
  • 5
  • 38
  • 41
175
votes
15 answers

Is it a bad practice to use an if-statement without curly braces?

I've seen code like this: if(statement) do this; else do this; However, I think this is more readable: if(statement){ do this; }else{ do this; } Since both methods work, is this simply a matter of preference which to use or would…
jerebear
  • 6,503
  • 4
  • 31
  • 38
174
votes
14 answers

What's the deal with a leading underscore in PHP class methods?

While looking over various PHP libraries I've noticed that a lot of people choose to prefix some class methods with a single underscore, such as public function _foo() ...instead of... public function foo() I realize that ultimately this comes…
nocash
  • 3,687
  • 4
  • 19
  • 12
173
votes
16 answers

Unique ways to use the null coalescing operator

I know the standard way of using the null coalescing operator in C# is to set default values. string nobody = null; string somebody = "Bob Saget"; string anybody = ""; anybody = nobody ?? "Mr. T"; // Returns Mr. T anybody = somebody ?? "Mr. T";…
173
votes
112 answers

What was the strangest coding standard rule that you were forced to follow?

When I asked this question I got almost always a definite yes you should have coding standards. What was the strangest coding standard rule that you were ever forced to follow? And by strangest I mean funniest, or worst, or just plain odd. In each…
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
171
votes
12 answers

Switch statement fall-through...should it be allowed?

For as long as I can remember I have avoided using switch statement fall-through. Actually, I can't remember it ever entering my consciousness as a possible way to do things as it was drilled into my head early on that it was nothing more than a bug…
Fostah
  • 11,398
  • 10
  • 46
  • 55
169
votes
9 answers

Good or bad practice? Initializing objects in getter

I have a strange habit it seems... according to my co-worker at least. We've been working on a small project together. The way I wrote the classes is (simplified example): [Serializable()] public class Foo { public Foo() { } private Bar…
John Willemse
  • 6,608
  • 7
  • 31
  • 45
166
votes
17 answers

Is there a good reason to use upper case for SQL keywords?

The default seems to be upper case, but is there really any reason to use upper case for keywords? I started using upper case, because I was just trying to match what SQL Server gives me whenever I tried to create something, like a new stored…
Hertanto Lie
  • 8,832
  • 7
  • 28
  • 27
164
votes
6 answers

Private vs Protected - Visibility Good-Practice Concern

I've been searching and I know the theoretic difference. public - Any class/function may access the method/property. protected - Only this class and any subclasses may access the method/property. private - Only this class may access the…
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308