From: Ersek, Laszlo on
In article
<2dddfb45-b0e6-4957-9557-0507cca064cb(a)g26g2000yqn.googlegroups.com>,
ImpalerCore <jadill33(a)gmail.com> writes:

> Are you a staunch member of the '7 == x' because of style, or because
> of the possibility of catching '7 = x' errors?

It became my style after using it consciously for a while. The original
reason was the one you mention as second.


> I personally don't like the style simply because it *is* more mind taxing,
> and it's a result of not seeing code in that style, not writing code in
> that style, and not thinking about code in that style, for about 8 years
> between C++ and C, that my brain has been conditioned that way. I would
> be bold enough to say that a large majority of C programmers are
> conditioned that way, simply from other people's code and books that I've
> seen.

I think I agree. I also think I don't care about how other people, with whom
I don't share a team, write their code :) I will not change my style just to
follow an unrelated majority.


> And the thing is that you may actually like that keyboard better, but
> everyone else will still use the standard keyboard, and still complain
> if they have to use your keyboard.

They have every reason to complain *now*, if they try to use my keyboard
:) Under Linux, I have my own keymap, under Windows, I have my own
keyboard layout dll, created with Microsoft's Keyboard Layout Creator
(available at no charge on their site). My layout dates back to DOS,
where I modified / programmed a TSR in Turbo Pascal so I could input
accented characters *and* source code. I touch-type (with completely
unofficial finger patterns), so when people try to look at the keyboard
for help, they are even more baffled, because I never care what "skin"
the keyboard has, as my layout is independent from that skin.


> The inertia of the original style 'x == 7' is too large enough to overcome
> unless that style has generated so many problems that I'm motivated to try
> out '7 == x'. If you suffered from carpal tunnel syndrome, you may be
> tempted to give the new keyboard a try.

Usually, I adapt quickly to new styles if I'm convinced about their benefits
(or when I realize that I have no choice). I didn't start out with "7 ==
x", I trained myself to write that way. It was inconvenient first, but then
it became natural. I picked up brace style, initialization style etc etc
the same way, gradually. I chose to adopt them.

My touch-typing patterns are completely unofficial and QWERTY dependent
(or more precisely, dependent on my own QWERTY-derivative),*and I
luckily never suffered from RSI, so I have no incentive to try out other
keyboard styles.


> I actually went through this process with single line if statements.
>
> if ( condition )
> statement;
>
> I have been bitten by this syntax (spending hours pouring over code
> where my brain is not registering the syntax error) so many times that
> the bracket style
>
> if ( condition ) {
> statement;
> }
>
> has become my convention. It has saved me time because for whatever
> reason, my brain can deal with the syntax errors better.

Same here (except no spaces around "condition" between the parentheses),
but for other reasons: I like to be able to jump to the end of the block
in my editor, and also to put a comment on the closing brace
occasionally.


> Again, if I have to work with a team, and it's decided to use 'char
> *p', I will gladly acquiesce, but unless I'm forced to code that way
> for a long time, I don't foresee myself changing my ways.

Same here. If we formalize an in-house standard (= coding style) that
prescribes "x == 7", I'll adapt. Consistency is more important than my
idiosyncracies.

Cheers,
lacos
From: Ersek, Laszlo on
In article <lnmxymsesg.fsf(a)nuthaus.mib.org>,
Keith Thompson <kst-u(a)mib.org> writes:

> Would you even consider writing '7 == x' rather than 'x == 7'
> if C's equality and comparison operators were more distinct?
>
> For example, consider a hypothetical C-like language in which the
> equality operator is spelled "=" and the assignment operator is
> "<-", and "==" is a syntax error. (Yes, that would quietly break
> "x<-1"; let's ignore that.)
>
> In such a language, would you ever write "if (7 = x)" in preference
> to "if (x = 7)"? If so, why?

No, I would not have picked up the "7 == x" style in that case.

For example, Pascal has := for assignment and = for equality (IIRC :)). Even
in C, I started out with "x == 7". I was occasionally bitten by
"if (x = 7)" typos. Not very frequently, and most of the time caught by
compiler warnings. However, on some forum somebody brought up "7 == x"
explicitly, and after giving the idea my unrelenting attention :) for a
minute or two, I liked it so much that I trained myself to it.

Cheers,
lacos
From: Richard Heathfield on
pete wrote:
<snip>

> To count down through an array with N elements, I use
>
> size_t i = N;
>
> while (i-- != 0) {
> array[i];
> }

Isn't this where we came in? Or was that another thread?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
From: Tim Streater on
On 05/03/2010 22:29, Ersek, Laszlo wrote:
> In article<lnmxymsesg.fsf(a)nuthaus.mib.org>,
> Keith Thompson<kst-u(a)mib.org> writes:
>
>> Would you even consider writing '7 == x' rather than 'x == 7'
>> if C's equality and comparison operators were more distinct?
>>
>> For example, consider a hypothetical C-like language in which the
>> equality operator is spelled "=" and the assignment operator is
>> "<-", and "==" is a syntax error. (Yes, that would quietly break
>> "x<-1"; let's ignore that.)
>>
>> In such a language, would you ever write "if (7 = x)" in preference
>> to "if (x = 7)"? If so, why?
>
> No, I would not have picked up the "7 == x" style in that case.
>
> For example, Pascal has := for assignment and = for equality (IIRC :)). Even
> in C, I started out with "x == 7". I was occasionally bitten by
> "if (x = 7)" typos. Not very frequently, and most of the time caught by
> compiler warnings. However, on some forum somebody brought up "7 == x"
> explicitly, and after giving the idea my unrelenting attention :) for a
> minute or two, I liked it so much that I trained myself to it.

What about maintenance? Someone later will look at that and waste half a
day trying to see if there's some reason it's written that way.

--
Tim

"That the freedom of speech and debates or proceedings in Parliament
ought not to be impeached or questioned in any court or place out of
Parliament"

Bill of Rights 1689
From: pete on
Richard Heathfield wrote:
>
> pete wrote:
> <snip>
>
> > To count down through an array with N elements, I use
> >
> > size_t i = N;
> >
> > while (i-- != 0) {
> > array[i];
> > }
>
> Isn't this where we came in? Or was that another thread?

I remember writing the same thing once a few weeks ago
but I don't remember which thread.

--
pete
First  |  Prev  |  Next  |  Last
Pages: 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Prev: integer
Next: shared memory question