Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [operators]

Regarding programming languages, operators are constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. From Wikipedia: http://en.wikipedia.org/wiki/Operator_%28programming%29

Filter by
Sorted by
Tagged with
93 votes
7 answers
16k views

Short circuit evaluation, is it bad practice?

Something that I've known for a while but never considered is that in most languages it is possible to give priority to operators in an if statement based on their order. I often use this as a way to ...
innova's user avatar
  • 1,041
89 votes
25 answers
47k views

Ternary operator considered harmful? [closed]

For example, would you prefer this one-liner int median(int a, int b, int c) { return (a<b) ? (b<c) ? b : (a<c) ? c : a : (a<c) ? a : (b<c) ? c : b; } or an if/else solution ...
20 votes
15 answers
5k views

What are bit operators good for? [closed]

Programming languages often come with various bit operators (e.g. bitwise left- and right shift, bitwise AND, OR, XOR...). These don't get used though very much, or at least such has my experience ...
Anto's user avatar
  • 11.2k
73 votes
2 answers
8k views

Why do bitwise operators have lower priority than comparisons?

Could someone explain the rationale, why in a bunch of most popular languages (see note below) comparison operators (==, !=, <, >, <=, >=) have higher priority than bitwise operators (&, |, ^...
SF.'s user avatar
  • 5,156
50 votes
9 answers
19k views

Why didn't == operator string value comparison make it to Java?

Every competent Java programmer knows that you need to use String.equals() to compare a string, rather than == because == checks for reference equality. When I'm dealing with strings, most of the ...
TtT23's user avatar
  • 1,552
27 votes
9 answers
13k views

What is the benefit of having the assignment operator return a value?

I'm developing a language which I intend to replace both Javascript and PHP. (I can't see any problem with this. It's not like either of these languages have a large install base.) One of the things ...
billpg's user avatar
  • 611
3 votes
3 answers
1k views

Specifics of Switch and If statements

Why do we need the switch statement if there is the if statement? Why can't we use several ifs like if(a==1) do this1; if(a==2) do this2; ... instead of switch (a) { case(1): {do ...
user114292's user avatar
13 votes
3 answers
3k views

How useful are infix operators in a programming language?

How useful are infix operators in a programming language? Are they worth the extra complexity they provide? Can you provide any examples where infix operators are better suited to the problem that can'...
Casebash's user avatar
  • 7,662
12 votes
11 answers
13k views

Examples of operator overloading, which make sense [closed]

While I learning C#, I found that, the C# supports operator overloading. I have problem with good example which: Make sense (ex. adding class named sheep and cow) Is not an example of concatenation ...
Paweł Sołtysiak's user avatar
5 votes
4 answers
2k views

Lexing: One token per operator, or one universal operator token?

When lexing, what would be the best way to tokenize operators? Would one just create a BinaryOperator token, or a separate token for every single binary operator? Examples: PlusOperator, MinusOperator,...
Jeroen's user avatar
  • 613