Top "Coding-style" questions

**DO NOT USE!

Styling multi-line conditions in 'if' statements?

Sometimes I break long conditions in ifs onto several lines. The most obvious way to do this is: if (cond1 == …

python coding-style if-statement
How do I return multiple values from a function?

The canonical way to return multiple values in languages that support it is often tupling. Option: Using a tuple Consider …

python coding-style return return-value
Python `if x is not None` or `if not x is None`?

I've always thought of the if not x is None version to be more clear, but Google's style guide and …

python coding-style nonetype boolean-expression pep8
Why use def main()?

I've seen some code samples and tutorials that use def main(): # my code here if __name__ == "__main__": main() But why? …

python coding-style
Creating an empty list in Python

What is the best way to create a new empty list in Python? l = [] or l = list() I am asking …

python performance list coding-style timeit
typeof !== "undefined" vs. != null

I often see JavaScript code which checks for undefined parameters etc. this way: if (typeof input !== "undefined") { // do stuff } This …

javascript coding-style
Single quotes vs. double quotes in Python

According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?

python coding-style
Iterate through a C++ Vector using a 'for' loop

I am new to the C++ language. I have been starting to use vectors, and have noticed that in all …

c++ coding-style for-loop iterator
What's the best way to convert a number to a string in JavaScript?

What's the "best" way to convert a number to a string (in terms of speed advantage, clarity advantage, memory advantage, …

javascript string performance coding-style numbers
What is the standard Python docstring format?

I have seen a few different styles of writing docstrings in Python, is there an official or "agreed-upon" style?

python coding-style documentation docstring