quote:Original post by AdmiralBinary
1) I believe it does. It was intended to show that, IMO, right-hand-constants are more readable.
IT DOES NOT SHOW THAT.
It shows that most people put the constant on the left. That''s all it does.
It doesn''t show that it''s less readable to do so. I would say that in the vast majority of cases, people don''t put the constant on the left simply because the idea never occurred. It never occurred to me until I read about it. But it''s no less readable -- one still has to look at both the variable being compared, and the value it''s being compared to.
quote:2) No, it''s not. And the fact that most people don''t do it supports my case. Where did these people learn to code? From coding books written by professionals. It may not be "undesirable", but IMO it is unreadable.
This does not show that it''s less readable, it shows that it''s less common, the two are not the same. There is a lot of poorly-written books out there, there is a hell of a lot of bad programmers out there. Just because they don''t do such a thing does not make it less readable.
quote:3) As a matter of fact, it does. More people will be familiar with the style that is more common. Therefore, code that uses a more common style will be more readable.
You have made a number of steps here without supporting evidence. In any case, did you consider that being less familiar might result in it being read better?
People tend to read what they expect -- this is in part why it can often be easier to see stupid mistakes in other people''s code; each time they read it they see what they thought they wrote, rather than what they actually did write.
With the variable on the left, constant on the right, the expectation of it being an equality test might cause them to not see the omitted = sign. They''ll read what they expect -- an equality test -- and not what''s actually there -- an assignment.
Putting the constant on the left might actually force people to stop and actually *read* what was written. In which case the less "readable" form becomes the form that actually gets read.
However, I don''t believe that it is less readable. It doesn''t obfuscate the meaning or anything like that, after all.
quote:4) Forget it. I was simply pointing out that it is not improbable that people will never make this mistake.
O_O.
Evidence would suggest that this is a fairly common mistake to make.
quote:This is a matter of opinion.
That lots of parts of C++ are parsed right-to-left?
quote:Also, please don''t try and dictate to me what language I should use. I have completed several working applications with it, and have never even considered switching on the grounds that it is "so hard to read".
I didn''t do anything of the sort. I simply suggested that if you found right-to-left parsing so unreadable then you may well find other langauges significantly easier.
quote:OMG, are you doing this on purpose? I didn''t say you were "wrong to suggest that always putting the constant on the LHS can trap errors"! I suggested that it would decrease readability.
And I suggest that it won''t. I suggest that when reading the statement, one has to read both sides, and that the ordering is immaterial.
quote:You didn''t "suggest" the practice. You proclaimed that it is "good coding practice" (I''m getting so sick of those words...)
Well, no, I suggested that leaving oneself open to runtime errors is bad practice.
quote:Look, let''s just forget the whole LHS/RHS thing - you''re simply picking me up on that because you can''t face the main point of my post, which is that you are putting across your style as "good coding practice", and putting down any other style as "bad coding practice".
It''s not a simple stylistic issue -- stylistic issues are things like indentation and so on, which make *no* difference to the code. This is something a bit different.