Questions tagged [conventions]

A generic tag covering any accepted method of doing things, which could include naming, spacing, coding, commenting, etc.

A generic tag covering any accepted method of doing things, which could include naming, spacing, coding, commenting, etc.

1073 questions
2089
votes
43 answers

When should I use double or single quotes in JavaScript?

console.log("double"); vs. console.log('single'); I see more and more JavaScript libraries out there using single quotes when handling strings. What are the reasons to use one over the other? I thought they're pretty much interchangeable.
aemkei
  • 10,657
  • 6
  • 34
  • 29
616
votes
20 answers

When to use the different log levels

There are different ways to log messages, in order of fatality: FATAL ERROR WARN INFO DEBUG TRACE How do I decide when to use which? What's a good heuristic to use?
raoulsson
  • 12,122
  • 11
  • 38
  • 61
581
votes
7 answers

Should I use past or present tense in git commit messages?

I read once that git commit messages should be in the imperative present tense, e.g. "Add tests for x". I always find myself using the past tense, e.g. "Added tests for x" though, which feels a lot more natural to me. Here's a recent John Resig…
Skilldrick
  • 65,202
  • 32
  • 168
  • 226
372
votes
7 answers

Is there a standardized method to swap two variables in Python?

In Python, I've seen two variable values swapped using this syntax: left, right = right, left Is this considered the standard way to swap two variable values or is there some other means by which two variables are by convention most usually…
WilliamKF
  • 36,283
  • 61
  • 170
  • 271
241
votes
9 answers

What is trunk, branch and tag in Subversion?

Possible Duplicate: What do “branch”, “tag” and “trunk” really mean? What is a trunk, branch and tag in Subversion and what are the best practices to use them? What tools can I use for Subversion in Visual Studio 2008?
Hemanshu Bhojak
  • 15,934
  • 15
  • 46
  • 60
220
votes
6 answers

Python __str__ versus __unicode__

Is there a python convention for when you should implement __str__() versus __unicode__(). I've seen classes override __unicode__() more frequently than __str__() but it doesn't appear to be consistent. Are there specific rules when it is better…
Cory
  • 18,463
  • 16
  • 85
  • 82
194
votes
7 answers

Convert Enumeration to a Set/List

Is there some one-liner bridge method to dump a given Enumeration to java.util.List or java.util.Set? Something built-in like Arrays.asList() or Collection.toArray() should exist somewhere, but I'm unable to find that in my IntelliJ debugger's…
Anton K
  • 3,796
  • 4
  • 23
  • 37
177
votes
6 answers

How do I add the contents of an iterable to a set?

What is the "one [...] obvious way" to add all items of an iterable to an existing set?
Ian Mackinnon
  • 11,717
  • 10
  • 48
  • 62
168
votes
8 answers

Are there any Java method ordering conventions?

I've got a large-ish class (40 or so methods) that is part of a package I will be submitting as course-work. Currently, the methods are pretty jumbled up in terms of utility public/private etc. and I want to order them in a sensible way. Is there a…
fredley
  • 29,323
  • 39
  • 131
  • 223
164
votes
11 answers

How to organize large R programs?

When I undertake an R project of any complexity, my scripts quickly get long and confusing. What are some practices I can adopt so that my code will always be a pleasure to work with? I'm thinking about things like Placement of functions in source…
Dan Goldstein
  • 21,713
  • 17
  • 34
  • 41
159
votes
16 answers

How do I pronounce "=>" as used in lambda expressions in .Net

I very rarely meet any other programmers! My thought when I first saw the token was "implies that" since that's what it would read it as in a mathematical proof but that clearly isn't its sense. So how do I say or read "=>" as…
Christopher Edwards
  • 6,364
  • 8
  • 39
  • 53
156
votes
9 answers

Swift: guard let vs if let

I have been reading about Optionals in Swift, and I have seen examples where if let is used to check if an Optional holds a value, and in case it does – do something with the unwrapped value. However, I have seen that in Swift 2.0 the keyword guard…
lmiguelvargasf
  • 40,464
  • 32
  • 169
  • 172
152
votes
5 answers

Where to define custom error types in Ruby and/or Rails?

Is there a best practice for defining custom error types in a Ruby library (gem) or Ruby on Rails application? Specifically: Where do they belong structurally in the project? A separate file, inlined with the relevant module/class definition,…
coreyward
  • 68,091
  • 16
  • 122
  • 142
138
votes
10 answers

Is it pythonic to import inside functions?

PEP 8 says: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. On occation, I violate PEP 8. Some times I import stuff inside functions. As a general rule, I…
codeape
  • 89,707
  • 22
  • 139
  • 171
126
votes
39 answers

Should one use < or <= in a for loop

If you had to iterate through a loop 7 times, would you use: for (int i = 0; i < 7; i++) or: for (int i = 0; i <= 6; i++) There are two considerations: performance readability For performance I'm assuming Java or C#. Does it matter if "less…
Eugene Katz
  • 5,082
  • 7
  • 36
  • 49
1
2 3
71 72