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

learn more… | top users | synonyms

84
votes
16answers
24k views

Why aren't user-defined operators more common?

One feature I miss in from functional languages is the idea that operators are just functions, so adding a custom operator is often as simple as adding a function. Many procedural languages allow ...
63
votes
15answers
2k views

I don't understand the arguments against operator overloading

I just read one of Joel's articles in which he says: In general, I have to admit that I’m a little bit scared of language features that hide things. When you see the code i = j * 5; … in C ...
61
votes
32answers
15k 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 ...
41
votes
6answers
6k 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 ...
37
votes
2answers
2k 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 (&, |, ...
27
votes
3answers
2k views

Why does the boolean type in C++ support `++` but not `--`?

Why does the operator -- not exist for bool whereas it does for operator ++? I tried in C++, and I do not know if my question apply to another language. I will glad to know also. I know, I can use ...
25
votes
10answers
3k views

Is there any reason why most programming languages don't have '!>' (not greater than) and '!<' (not less than) operators?

I wonder if there is any reason - or if it is just an accident of history - that there are no !> and !< operators in most programming languages? a >= b (a greater OR equals b) could be ...
21
votes
9answers
2k 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 ...
18
votes
15answers
3k 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 ...
17
votes
3answers
7k views

What is the name of ** in python?

When programming Python I sometimes do a ** to make a conversion. I understand what it does but what data structures am I manipulating? A dict and what is the other? An array? Is there a name for the ...
14
votes
3answers
2k views

Why isn't the arrow operator in C++ just an alias of *.?

In c++, the * operator can be overloaded, such as with an iterator, but the arrow (->) (.*) operator does not work with classes that overload the * operator. I imagine that the preprocessor could ...
11
votes
11answers
6k views

Examples of operator overloading, which make sense

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 ...
11
votes
6answers
4k views

What are the advantages of using bitwise operations? [closed]

Following reading the latest CodeProject newsletter, I came across this article on bitwise operations. It makes for interesting reading, and I can certainly see the benefit of checking if an integer ...
11
votes
2answers
2k views

Bitwise-OR vs Adding Flags

I've seen others use Bitwise-OR to combine flags before: #define RUN 0x01 #define JUMP 0x02 #define SHOOT 0x04 const byte madPerson = RUN | JUMP | SHOOT; That's also the way I do it. But I've ...
11
votes
7answers
727 views

Are operators clearer to read than keywords or functions? [closed]

It's a bit subjective, but I'm hoping to get a clearer understanding of what factors make an operator clear to use vs obtuse and difficult. I've been considering language designs recently, and one ...
9
votes
4answers
2k views

Instantiating Null Objects with Null-Coalescing Operator

Consider the following typical scenario: if(myObject == null) { myObject = new myClass(); } I'm wondering what is thought of the following replacement using the null-coalescing operator: ...
9
votes
4answers
1k views

Using PHP's ternary operator with only two arguments

I was recently reviewing some of my code and noticed that in a fit of absent-mindedness, I'd left a structure like the following: $guid = empty($subscription->guid) ? : $subscription->guid; ...
8
votes
2answers
598 views

What is the justification for Python's power operator associating to the right?

I am writing code to parse mathematical expression strings, and noticed that the order in which chained power operators are evaluated in Python differs from the order in Excel. From ...
6
votes
3answers
630 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 ...
5
votes
2answers
2k views

Do any languages use =/= for the inequality operator?

Wikipedia says: Not equal The symbol used to denote inequation — when items are not equal — is a slashed equals sign "≠" (Unicode 2260). Most programming languages, limiting themselves ...
5
votes
3answers
7k views

Ternary operator (condition ? foo : bar) and the XOR (^) operator

I have read in a recent code review that both ternary operator (condition ? foo : bar) and the XOR operator ^ are rarely used in Java. Is it true? If yes, is this because they are less readable? or ...
5
votes
2answers
379 views

Why isn't exponentiation hardware-implemented?

Why is there no exponentiation operation in hardware, even though many languages have builtin operators for it? Is it because even hardware implementations would need to use the same algorithm as ...
4
votes
2answers
604 views

What do you call parentheses operators?

In most programming languages documentation where they talk about operators +-*/=<> they also include ()[] as operators. There are unary operators, multiplicative operators, additive operators, ...
4
votes
8answers
978 views

Comparison of operator overloading abuse in different languages

A common argument against operator overloading is that it can be and is abused, e.g. A+B doing something completely different to addition. Examples are often quoted in C++ snippets, where the ...
4
votes
1answer
234 views

Implicit Conversion Operators for Value Types in C#

I’ve come across this blog article: Implicit Conversion Operators are Bad. The article discourages the use of implicit conversion with reference types. The article describes problems caused by ...
3
votes
2answers
754 views

Why do more languages not support ===

I mean it as it is used in JavaScript. Just curious why this is not supported in more languages? Like Java for example does not have it? Seems to be a very useful operator to have.
3
votes
3answers
493 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 ...
3
votes
7answers
472 views

Why would one overload the && and & operator?

The same question goes for | and ||. Why would one overload or 'use' the & and && operator? The only use i thought of are Bitwise Ands for int base types (but not float/decimals) using ...
3
votes
1answer
231 views

How do you set and check a single bit in a programming language that does not support bitwise operations?

I'm using a programming language (more a scripting language) that does not support any bitwise operators like AND, OR, XOR, NOT (and shift as well). Common arithmetic and logical operations like + - ...
3
votes
2answers
550 views

Which are the fundamental stack manipulation operations?

I'm creating a stack oriented virtual machine, and so I started learning Forth for a general understanding about how it would work. Then I shortlisted the essential stack manipulation operations I ...
3
votes
2answers
236 views

Greater than or identical to?

While browsing my code in a weakly-typed language I was seeing that I've trained myself to use identity (===) where logical. Then I came across a greater (or less) than or equal to (>=), and it ...
2
votes
4answers
326 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, ...
2
votes
4answers
176 views

What should I call the less-than and similar operators?

Most programming languages support operators similar to the following 6, which are spelled here as in C. == != < <= > >= I'm aware of several terms used to include all of these ...
2
votes
1answer
274 views

Languages supporting unicode logic operators

Are there any programming languages that support the use of unicode logic operators? For example, many programming languages use "!=" as the "does not equal" operator, but in mathematics the symbol ...
2
votes
1answer
106 views

How does the ? make a quantifier lazy in regex [closed]

I've been looking into regex lately and figured that the ? operator makes the *,+, or ? lazy. My question is how does it do that? Is it that *? for example is a special operator, or does the ? have ...
1
vote
2answers
334 views

Should ** bind more tightly than !, ~?

Designing a programming language, I'm including the ** exponentiation operator. In Fortran and Python, the two languages I know of which have this operator, it binds more tightly than unary minus, ...
1
vote
2answers
314 views

Speeds of << >> multiplication and division

You can use << to multiply and >> to divide numbers in python when I time them I find using the binary shift way of doing it is 10x faster than dividing or multiplying the regular way. ...
1
vote
1answer
71 views

Operator distributivity in expressions - syntactic sugar

When writing boolean expressions out, you often have to use something of the type: A == any of B1, ..., Bn C < all of D1, ..., Dm But in code you have to use expanded forms: A == B1 or ... or A ...
1
vote
5answers
881 views

Is Operator Overloading supported in C

Today when I read about the LCC (Windows) compiler, I found out it has the implementation for operator overloading. I'm puzzled because after a bit of Goggling, it has been confirmed that operator ...
0
votes
3answers
380 views

Any languages use the '=>' and '=<' operators? [closed]

I'm just curious if there are any programming languages that use the '=>' and '=<' operators for something. I wonder why these are not commonly used when their variant '<=' and '>=' are so ...
0
votes
4answers
3k views

Can I change operator precedence and associativity in C++?

As the title says, I find it useful to be able to overload operators. Is it possible to also change the way the operators are parsed by specifying the precedence and associativity of overridden ...
0
votes
3answers
349 views

Using Power of 2 numbers to represent types

Let's say that we have some values, represented by power of 2: TYPE_1 = 1 TYPE_2 = 2 TYPE_3 = 4 TYPE_4 = 8 ... I need to store some of these types in one value. Example: To represent TYPE_1 with ...
0
votes
1answer
104 views

Is it correct to call the assignment symbol an “operator” when it is actually a statement?

In some languages (C++, Java, Ruby, etc.) an assignment returns a value and can be used in an expression: x = (y = z); // ok, 'x' gets the value of 'z' In other languages (Ada, VHDL), an ...
0
votes
5answers
188 views

Why is it bad to use redundancy with logical operators? [duplicate]

I'm moving over to work on a library that a fellow developer has been writing. It's full of == true and == false, which I find crazy frustrating to read. I've tried asking him to quit doing it, but ...
0
votes
1answer
306 views

Overloading Operators - C++

I was experimenting with new overloaded operators, I have created one void operator and another one that returns something when it's called: #include <iostream> struct chichachicha{ int ...
0
votes
1answer
79 views

Missing `$` like operators in Haskell

Below I've produced what I believe to be a summary of the standard $ like operators for various classes in Haskell. There's some gaps however. Following the applicative pattern, you would think those ...
0
votes
2answers
251 views

How to extract operators from the grammar productions for conflict resolution in LALR parser?

Is there some standardized or widely accepted algorithm for picking up operators in shift/reduce conflicts in LALR parser? The question is naive, my problem is not with implementing my solution, but ...
0
votes
0answers
44 views

Correct name for expression tree merging

Suppose some n-ary tree, representing some expression: A and (B and (C or D)) or (B and (C or E)) A / \ B B / \ / \ C D C E And consider ...
-1
votes
1answer
269 views

Is this common amongst many languages?

In C++, the integer variable bar evaluates to 1 in this code int foo = 0; int bar = ++foo; and 0 in this code int foo = 0; int bar = foo++; Is this behavior prevalent in most popular languages?