New answers tagged

1

The following C++ program compiles with nary a peep from clang, even with warnings set to the the highest possible level (-Weverything): #include <iostream> int main () { std::cout << (1 < 3 < 2) << '\n'; } The gnu compiler suite on the other hand nicely warns me that comparisons like 'X<=Y<=Z' do not have their mathematical ...


4

Most mainstream languages are (at least partially) object-oriented. Fundamentally, the underlying principle of OO is that objects send messages to other objects (or themselves), and the receiver of that message has complete control over how to respond to that message. Now, let's see how we would implement something like a < b < c We could evaluate ...


18

These are binary operators, which when chained, normally and naturally produce an abstract syntax tree like: When evaluated (which you do from the leaves up), this produces a boolean result from x < y, then you get a type error trying to do boolean < z. In order for x < y < z to work as you discussed, you have to create a special case in the ...


23

Why is x < y < z not commonly available in programming languages? In this answer I conclude that although this construct is trivial to implement in a language's grammar and creates value for language users, the primary reasons that this does not exist in most languages is due to its importance relative to other features and the unwillingness of ...


9

Computer languages try to define the smallest possible units and let you combine them. The smallest possible unit would be something like "x < y" which gives a boolean result. You may ask for a ternary operator. An example would be x < y < z. Now what combinations of operators do we allow? Obviously x > y > z or x >= y >= z or x > y >= z or maybe ...


2

It's simply because the language designers didn't think of it or didn't think it was a good idea. Python does it as you described with a simple (almost) LL(1) grammar.


8

In many programming languages, x < y is a binary expression that accepts two operands and evaluates to a single boolean result. Therefore, if chaining multiple expressions, true < z and false < z won't make sense, and if those expressions successfully evaluate, they're likely to produce the wrong result. It's much easier to think of x < y as a ...


0

Each item itself This all should work much alike event-driven system. Parent entity should give orders to its Items, and Items should check with their state to see if and how they can perform that action. Even if it is as simple as reading 1-2 public properties for the Parent, it is still better for encapsulation to not do so and let Items check their ...


0

Visibility is often something you want to aggregate so you can tell a whole group of objects to hide or show themselves together. Even so it's still best let each object test and paint itself. I'm a big believer in tell don't ask. To me the object oriented world is divided into behavior objects that tell you nothing about their state, and data objects ...


1

At least in OO + event driven interfaces: GUI objects, including the window pane itself, have event listeners who are triggered with user actions. Those event listeners call a method which then send messages to other GUI elements (or to themselves). But... once a GUI element receives an message (like myButton.setVisible(false);) it renders itself ...



Top 50 recent answers are included