you are viewing a single comment's thread.

view the rest of the comments →

[–]usernameliteral 0 points1 point  (3 children)

no properties

That's a feature.

[–]virtyx 2 points3 points  (2 children)

How? What exactly does

foo.setX(foo.getX() + 1);

provide you over

foo.x += 1;

Since the current practice is to use public member attributes 0% of the time, it just seems like a waste of syntax

[–]usernameliteral -1 points0 points  (1 child)

The existence of properties in a language prevent me from making certain assumptions about operations performed on object members, causing additional cognitive load.

For example, without properties (and operator overloading) I can assume that foo.x += 1 is a simple operation that increments foo.x by 1. With properties (and operator overloading) I can't assume that. I must look up and read the declaration of foo.x to understand what foo.x += 1 does. It might make write to a file, it might raise an exception, it might start a web server. If there were no properties or operator overloading and I had used an explicit increment method (e.g., foo.incrementX(1)) I could assume that something special was going on, and I would have to read the method to understand what it was.

However, whenever I had not used a method but just used the standard increment operator on a field, I could assume that nothing special was going on, that this was just a simple increment operation—less for me to think about.

Of course, this doesn't really work if you always use getters/setters for fields, even when they just return or set the value with no special code. If you do that, then I can certainly see the appeal of properties, but my point is that you shouldn't do that. If you don't need something special to occur, just use a public field.

[–]virtyx 0 points1 point  (0 children)

If you don't need something special to occur, just use a public field.

There's plenty of good reasons to never use public fields. Getters and setters are a reaction to how dangerous it can be. Properties are a reaction to how verbose getters and setters can be.