Humm I thought i could program but what is wrong

Started by
46 comments, last by Leadorn 22 years ago
quote:I would write it like that, because that''s how I think -- 0 <= x < maximum, as it''s what I''m used to from mathematics.

Oops - a slip o'' the keyboard? If it''s the way you think, fine - I wish you well. However, everyone thinks differently, and just because someone doesn''t think/code the same as you doesn''t mean they are coding wrong. So, it all boils down to a matter of personal preference - not good coding practice.
quote:Those two are equivalent.

So are (x+50 > MAX_X+50) and (x > MAX_X). What''s your point?

---------------

#define TRUE 0
#define FALSE 1
//MUAHAHAHAHAAAA!
Advertisement
I debated jumping in on this war here, but I guess my debative side just took over.

(0 == x) and (x == 0). It's an equality statement. It doesn't matter which side you put what on. The only reason some may say readability is lost is because they're so used to seeing equality var == const. I've been programming for about 5 years now and I've always done var == const. I've seen it everywhere and it sunk in. After reading Pizza's post, all new code involving equality I've written const == var. Clever idea. It's not about style, it's a healthy suggestion. Everybody is just so afraid to change. If most books, professionals, and teachers all showed you const == var, we wouldn't be having this discussion.

To sum up, whoever doesn't like const == var, don't use it. All of my future code (not that anyone will ever look at it) will use this, and I would be excited to come across this in the future when I look into somebody else's code.



[edited by - lackluster on March 24, 2002 2:44:47 AM]
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.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
Blha blha blha.

I''ll come back in a few years, when my programming has become better. C ya guys.


And remember to use ++ instead of =+1; Otherwise the compiler will create a temp variable.

I''ve learned one good thing. Dont post anything before you are totaly sure it''s correct. But that I cant do, so i will never post anything.

Thanks guys.
wow this thread is so much fun.
please continue...

now the Dr. is right, 0 = x will make bug free compiling a much easier task,
but the admiral is correct in saying that the way the Dr. has made his suggestions was totaly bad.

I must do this: nothing personal, I just like watching fire burn...

as for the original Dr. comments:
#include <iostream.h> is bad
#include <stdlib.h> is bad ... yada yada yada,
what a load of crap.

please, we''re counting charcters in a fixed length array.

use std:string... why?

if I can gurrenty that my input will always be N characters long (N being a #define)
why do I need to use "safe" std:string objects?

and about += being bad practice? there are bad optimizers???? get a grip, when was the last time you worked (by your own free will) with a bad optimizer since the begining of this millenium?

and one last thing I remember seeing something like: 0 <= x < NUMBER
to whoever wrote it: this is a sure way to make a bug... try :
x = -2;
-5 <= x < -1

cheers.


I am what I am, more or less
and my site rocks
www.geocities.com/roam_fire
I think
I am what I am, more or less :)and my site rockswww.geocities.com/roam_fireI think
Hey Roam! I know you from the DC. Cool isometric engine BTW...

quote:That lots of parts of C++ are parsed right-to-left?

No, that "There is loss of readability."
quote: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.

Dammit. I can''t disagree with that

Anyway, as far as Dr. Pizza''s "suggestions" go, I still disagree with the way they were put and with a coupla the suggestions themselves. However, I can understand how it would be safer to follow the LHS constant routine. The fact that I would find it unnatural to read is my opinion, my problem, and - I guess - totally irrelevant.

OK, Doctor, you win on the LHS constant thing, and although I won''t be using it in my code (<- last, pathetic gesture of defiance ), I can understand that it would be beneficial for people to get used to. No hard feelings?

---------------

#define TRUE 0
#define FALSE 1
//MUAHAHAHAHAAAA!
DrPizza, just shut the fuck up already.

You''re arguing over the appearance of pixels on a monitor.

WHO GIVES A SHIT.

Go do something worthwhile like show little kids how to tie their shoes the safe STL way.
Sporty, this whole site is about pixels on a monitor - that''s the point.

This thread has got out of hand. If anyone needs answers to some of the specific questions, please post new threads.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

This topic is closed to new replies.

Advertisement