Skip to main content

Questions tagged [coding-style]

Coding style is a set of guidelines that helps readability and understanding of the source code.

1353 votes
14 answers
279k views

I often talk to programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's ...
585 votes
1 answer
76k views

I have recently seen a few URIs containing the query parameter "utf8=✓". My first impression (after thinking "mmm, looks cool") was that this could be used to detect a broken character encoding. So, ...
Gary's user avatar
  • 24.4k
329 votes
36 answers
397k views

Should curly braces be on their own line or not? What do you think about it? if (you.hasAnswer()) { you.postAnswer(); } else { you.doSomething(); } or should it be if (you.hasAnswer()) { ...
310 votes
2 answers
550k views

I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names I'm not clear on whether this refers to the file name of a module/class/package. If I had one example ...
darkace's user avatar
  • 3,211
301 votes
19 answers
246k views

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why. public void SomeFunction(bool someCondition) { if (someCondition) ...
271 votes
21 answers
237k views

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) { ...
202 votes
14 answers
93k views

I was involved in a programming discussion today where I made some statements that basically assumed axiomatically that circular references (between modules, classes, whatever) are generally bad. ...
dash-tom-bang's user avatar
187 votes
15 answers
79k views

I have an acquaintance, a more seasoned developer than me. We were talking about programming practices and I was taken aback by his approach on 'if' statements. He insists on some practices regarding ...
Patsuan's user avatar
  • 1,647
175 votes
24 answers
118k views

This is a minor niggle, but every time I have to code something like this, the repetition bothers me, but I'm not sure that any of the solutions aren't worse. if(FileExists(file)) { contents = ...
174 votes
24 answers
27k views

I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code. My code is primarily "scripting" type stuff - things to test mathematical ...
auden's user avatar
  • 1,656
168 votes
6 answers
69k views

This is a bit pedantic, but I've seen some people use Id as in: private int userId; public int getUserId(); and others use: private int userID; public int getUserID(); Is one of these a better name ...
Adam's user avatar
  • 2,211
153 votes
14 answers
125k views

In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what ...
Spring's user avatar
  • 1,763
147 votes
6 answers
18k views

Generally I use private methods to encapsulate functionality that is reused in multiple places in the class. But sometimes I have a large public method that could be broken up into smaller steps, each ...
Jordak's user avatar
  • 931
141 votes
5 answers
88k views

Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an ...
Oak's user avatar
  • 5,365
138 votes
18 answers
54k views

This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't ...

15 30 50 per page
1
2 3 4 5
71