All Questions

1719
votes
8answers
202379 views

What is The Rule of Three?

What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
1550
votes
5answers
249031 views

What is the copy-and-swap idiom?

What is this idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used? Although it's been mentioned in many places, we didn't have any singular "what i...
3145
votes
11answers
232508 views

Java's +=, -=, *=, /= compound assignment operators

Until today, I thought that for example: i += j; is just a shortcut for: i = i + j; But what if we try this: int i = 5; long j = 8; Then i = i + j; will not compile but i += j; will compile f...
473
votes
6answers
107617 views

Assignment operators in R: '=' and '<-'

What are differences in the assignment operators '=' and '<-' in R? I know that operators are slightly different as this example shows x <- y <- 5 x = y = 5 x = y <- 5 x <- y = 5 # Err...
34
votes
4answers
5840 views

The forgotten assignment operator "=" and the commonplace ":="

The documentation for PL/pgSQL says, that declaration and assignment to variables is done with :=. But a simple, shorter and more modern (see footnote) = seems to work as expected: CREATE OR REP...
22
votes
7answers
20128 views

Multiple assignment and evaluation order in Python

What is the difference between the following Python expressions: # First: x,y = y,x+y # Second: x = y y = x+y First gives different results than Second. e.g., First: >>> x = 1 >&g...
47
votes
6answers
28148 views

Why must the copy assignment operator return a reference/const reference?

In C++, the concept of returning reference from the copy assignment operator is unclear to me. Why can't the copy assignment operator return a copy of the new object? In addition, if I have class A, a...
66
votes
8answers
5907 views

What is the motivation for Scala assignment evaluating to Unit rather than the value assigned?

What is the motivation for Scala assignment evaluating to Unit rather than the value assigned? A common pattern in I/O programming is to do things like this: while ((bytesRead = in.read(buffer)) != ...
67
votes
7answers
45119 views

Shortcut "or-assignment" (|=) operator in Java

I have a long set of comparisons to do in Java, and I'd like to know if one or more of them come out as true. The string of comparisons was long and difficult to read, so I broke it up for readability...
61
votes
11answers
9545 views

Why doesn't Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=)

So for binary operators on booleans, Java has &, |, ^, && and ||. Let's summarize what they do briefly here: JLS 15.22.2 Boolean Logical Operators &, ^, and | JLS 15.23 Conditional-...

Previous Next