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.

1143 questions
870
votes
22 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
  • 14,978
  • 11
  • 44
  • 68
682
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
  • 69,215
  • 34
  • 177
  • 229
436
votes
8 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
  • 41,123
  • 68
  • 193
  • 295
242
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
  • 16,972
  • 16
  • 49
  • 64
231
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
  • 22,772
  • 19
  • 94
  • 91
223
votes
6 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 Kraievyi
  • 4,182
  • 4
  • 26
  • 41
200
votes
11 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
  • 63,191
  • 45
  • 217
  • 228
193
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
  • 13,381
  • 13
  • 51
  • 67
185
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
  • 32,953
  • 42
  • 145
  • 236
173
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
  • 77,547
  • 20
  • 137
  • 166
168
votes
10 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
  • 24,229
  • 18
  • 37
  • 41
158
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,589
  • 8
  • 43
  • 57
153
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
  • 97,830
  • 24
  • 159
  • 188
151
votes
3 answers

What is the canonical YAML naming style

I am designing a new YAML file, and I want to use the most standard style of naming. Which is it? Hyphenated? - job-name: ... lower_case_with_underscores? - job_name: ... CamelCase? - jobName: ...
John McGehee
  • 9,117
  • 9
  • 42
  • 50
129
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,208
  • 7
  • 40
  • 49
1
2 3
76 77