Developers Archive

List Statistics

  • Total Threads: 675
  • Total Posts: 2049

Phrases Used to Find This Thread

  #1  
03-03-2011 04:41 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-



  #2  
03-03-2011 05:48 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)



  #3  
03-03-2011 06:36 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #4  
04-03-2011 01:08 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #5  
04-03-2011 07:36 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex



  #6  
04-03-2011 07:45 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc


  #7  
04-03-2011 08:24 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.

  #8  
05-03-2011 01:23 AM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #9  
05-03-2011 09:30 AM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #10  
05-03-2011 10:27 AM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc


  #11  
05-03-2011 01:39 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

It’s part of the syntax and semantics of C, Java, etc.

> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #12  
05-03-2011 04:57 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

It’s part of the syntax and semantics of C, Java, etc.

> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Being part of the syntax and semantics of C and being well designed are two very different things.

On Mar 5, 2011, at 5:39, Andrew Davidson <> wrote:

> It’s part of the syntax and semantics of C, Java, etc.
>
>> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>>
>> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>>
>> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>>
>> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>>
>>>
>>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>>
>>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>>
>>> Assuming that library issues and compiler bugs continue to make
>>> it undesirable to turn on "-Wall", do we want to consider starting to
>>> turn on individual warning flags for warnings that are we believe
>>> are particularly likely to be useful to the Arduino audience
>>> ("-Wparentheses", for example)
>>>
>>> BillW
>>>
>>>
>>> _______________________________________________
>>> Developers mailing list
>>>
>>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc



  #13  
05-03-2011 06:33 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

It’s part of the syntax and semantics of C, Java, etc.

> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Being part of the syntax and semantics of C and being well designed are two very different things.

On Mar 5, 2011, at 5:39, Andrew Davidson <> wrote:

> It’s part of the syntax and semantics of C, Java, etc.
>
>> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>>
>> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>>
>> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>>
>> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>>
>>>
>>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>>
>>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>>
>>> Assuming that library issues and compiler bugs continue to make
>>> it undesirable to turn on "-Wall", do we want to consider starting to
>>> turn on individual warning flags for warnings that are we believe
>>> are particularly likely to be useful to the Arduino audience
>>> ("-Wparentheses", for example)
>>>
>>> BillW
>>>
>>>
>>> _______________________________________________
>>> Developers mailing list
>>>
>>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


Yes, they are two different things, but there are also good reasons for
the way C is. An assignment is an expression, which is how C does
for (a = 0; ...; ...)
and
a = b = ...;
It also allows standard C idioms like
while ((c = getchar()) != EOF)
Of course, there are ways to redefine the syntax to allow assignments in
only certain places, but that complicates the language and part of the
beauty of C is its simplicity. In any case, we can't redesign the language.

By the way, it's not in general possible to catch this with regular
expressions. C expression syntax is not regular. For one thing,
regular expressions cannot match nested parentheses. Yes, it's possible
to recognize an assignment at the top level of a conditional:
if (a = ...)
but what about
if (... && (... || (a = ...) || ...))?

On 01/-10/37 11:59, Nicholas Zambetti wrote:
> Being part of the syntax and semantics of C and being well designed are
> two very different things.
>...

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #14  
05-03-2011 10:38 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

It’s part of the syntax and semantics of C, Java, etc.

> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Being part of the syntax and semantics of C and being well designed are two very different things.

On Mar 5, 2011, at 5:39, Andrew Davidson <> wrote:

> It’s part of the syntax and semantics of C, Java, etc.
>
>> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>>
>> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>>
>> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>>
>> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>>
>>>
>>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>>
>>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>>
>>> Assuming that library issues and compiler bugs continue to make
>>> it undesirable to turn on "-Wall", do we want to consider starting to
>>> turn on individual warning flags for warnings that are we believe
>>> are particularly likely to be useful to the Arduino audience
>>> ("-Wparentheses", for example)
>>>
>>> BillW
>>>
>>>
>>> _______________________________________________
>>> Developers mailing list
>>>
>>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


Yes, they are two different things, but there are also good reasons for
the way C is. An assignment is an expression, which is how C does
for (a = 0; ...; ...)
and
a = b = ...;
It also allows standard C idioms like
while ((c = getchar()) != EOF)
Of course, there are ways to redefine the syntax to allow assignments in
only certain places, but that complicates the language and part of the
beauty of C is its simplicity. In any case, we can't redesign the language.

By the way, it's not in general possible to catch this with regular
expressions. C expression syntax is not regular. For one thing,
regular expressions cannot match nested parentheses. Yes, it's possible
to recognize an assignment at the top level of a conditional:
if (a = ...)
but what about
if (... && (... || (a = ...) || ...))?

On 01/-10/37 11:59, Nicholas Zambetti wrote:
> Being part of the syntax and semantics of C and being well designed are
> two very different things.
>...

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Assignment inside of a conditional has been part of C since Thompson and
Ritchie.

In C everything is an expression and all expressions have value.
Assignment is an expression. This is also why you can go a = b = c = 11;

Different people have different preferences on style issues.
Many style issues become practically religious in significance.
I work in myriads of environments, from Linux Kernels, OpenBSD, OS X,
Windows, Java, ...... And they all have strong views (and often
conflicting views) on what is an is not good style.
I have my own - though having to work accross multiple environments
tends to encourage flexibility.

Personally I think

while((erC = read()) >= 0) {
....
}

is clearer and cleaner than other alternatives.



-----Original Message-----
Cc: Arduino Developers <>
Subject: Re: [Developers] Software engineering issue..
Date: Sat, 5 Mar 2011 01:30:26 -0800

Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

--
Dave Lynch DLA Systems
Software Development: Embedded Linux
717.587.7774 http://www.dlasys.net
Over 25 years' experience in platforms, languages, and technologies too
numerous to list.

"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction."
Albert Einstein


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


  #15  
06-03-2011 03:05 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

It’s part of the syntax and semantics of C, Java, etc.

> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Being part of the syntax and semantics of C and being well designed are two very different things.

On Mar 5, 2011, at 5:39, Andrew Davidson <> wrote:

> It’s part of the syntax and semantics of C, Java, etc.
>
>> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>>
>> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>>
>> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>>
>> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>>
>>>
>>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>>
>>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>>
>>> Assuming that library issues and compiler bugs continue to make
>>> it undesirable to turn on "-Wall", do we want to consider starting to
>>> turn on individual warning flags for warnings that are we believe
>>> are particularly likely to be useful to the Arduino audience
>>> ("-Wparentheses", for example)
>>>
>>> BillW
>>>
>>>
>>> _______________________________________________
>>> Developers mailing list
>>>
>>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


Yes, they are two different things, but there are also good reasons for
the way C is. An assignment is an expression, which is how C does
for (a = 0; ...; ...)
and
a = b = ...;
It also allows standard C idioms like
while ((c = getchar()) != EOF)
Of course, there are ways to redefine the syntax to allow assignments in
only certain places, but that complicates the language and part of the
beauty of C is its simplicity. In any case, we can't redesign the language.

By the way, it's not in general possible to catch this with regular
expressions. C expression syntax is not regular. For one thing,
regular expressions cannot match nested parentheses. Yes, it's possible
to recognize an assignment at the top level of a conditional:
if (a = ...)
but what about
if (... && (... || (a = ...) || ...))?

On 01/-10/37 11:59, Nicholas Zambetti wrote:
> Being part of the syntax and semantics of C and being well designed are
> two very different things.
>...

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Assignment inside of a conditional has been part of C since Thompson and
Ritchie.

In C everything is an expression and all expressions have value.
Assignment is an expression. This is also why you can go a = b = c = 11;

Different people have different preferences on style issues.
Many style issues become practically religious in significance.
I work in myriads of environments, from Linux Kernels, OpenBSD, OS X,
Windows, Java, ...... And they all have strong views (and often
conflicting views) on what is an is not good style.
I have my own - though having to work accross multiple environments
tends to encourage flexibility.

Personally I think

while((erC = read()) >= 0) {
....
}

is clearer and cleaner than other alternatives.



-----Original Message-----
Cc: Arduino Developers <>
Subject: Re: [Developers] Software engineering issue..
Date: Sat, 5 Mar 2011 01:30:26 -0800

Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

--
Dave Lynch DLA Systems
Software Development: Embedded Linux
717.587.7774 http://www.dlasys.net
Over 25 years' experience in platforms, languages, and technologies too
numerous to list.

"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction."
Albert Einstein


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


On Mar 5, 2011, at 11:57 AM, Nicholas Zambetti wrote:

> Being part of the syntax and semantics of C and being well designed are two very different things.

THank you Nick. If it were a matter of keeping to the syntax and semantics of C, I wouldn't have bothered with Arduino in the first place.
_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)

  #16  
21-03-2011 07:39 PM
Developers member admin is online now
User
 

In many ways this:

if (0 == howbig) {
...
}

Should be better than the following:

if (howbig == 0) {
...
}

Because in case we write accidentaly:

if (0 = howbig) {
...
}

The compiler will issue a syntactic error..

But in case of that:

if (howbig = 0) {
...
}

The compiler will accept it and there is a logical error..

Happy Hacking!

--
Efstathios Xatzikiriakidis (Lafs).
Informatics & Communications Engineer BSc.

Website: http://www.efxa.org/

-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
-END GEEK CODE BLOCK-


There is a style document: http://arduino.cc/en/Reference/StyleGuide

I think you found an issue that could be documented more clearly in
the guide. All examples in the guide do not show 0 == howbig as a
precedent.


--Rick


On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
Tom (Igoe) is in charge of the examples, so we do (or should do)
whatever he prefers there.

On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
<> wrote:
> In many ways this:
>
> if (0 == howbig) {
>   ...
> }
>
> Should be better than the following:
>
> if (howbig == 0) {
>   ...
> }
>
> Because in case we write accidentaly:
>
> if (0 = howbig) {
>   ...
> }
>
> The compiler will issue a syntactic error..
>
> But in case of that:
>
> if (howbig = 0) {
>   ...
> }
>
> The compiler will accept it and there is a logical error..
>
> Happy Hacking!
>
> --
> Efstathios Xatzikiriakidis (Lafs).
> Informatics & Communications Engineer BSc.
>
> Website: http://www.efxa.org/
>
> -BEGIN GEEK CODE BLOCK-
> Version: 3.12
> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
> -END GEEK CODE BLOCK-
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
I'm with dave, I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader. You're testing the value of the variable, so to say "if foo equals zero" makes more sense than "if zero equals foo".

t.



On Mar 3, 2011, at 1:36 PM, David A. Mellis wrote:

> I prefer "if (foo == 0) {}" and so I use it in the core and libraries.
> Tom (Igoe) is in charge of the examples, so we do (or should do)
> whatever he prefers there.
>
> On Thu, Mar 3, 2011 at 11:41 AM, Efstathios Xatzikiriakidis
> <> wrote:
>> In many ways this:
>>
>> if (0 == howbig) {
>> ...
>> }
>>
>> Should be better than the following:
>>
>> if (howbig == 0) {
>> ...
>> }
>>
>> Because in case we write accidentaly:
>>
>> if (0 = howbig) {
>> ...
>> }
>>
>> The compiler will issue a syntactic error..
>>
>> But in case of that:
>>
>> if (howbig = 0) {
>> ...
>> }
>>
>> The compiler will accept it and there is a logical error..
>>
>> Happy Hacking!
>>
>> --
>> Efstathios Xatzikiriakidis (Lafs).
>> Informatics & Communications Engineer BSc.
>>
>> Website: http://www.efxa.org/
>>
>> -BEGIN GEEK CODE BLOCK-
>> Version: 3.12
>> GCS d- s+: a- C UL P+ L+++ E+ W+++ N++ o K- w- O-
>> M V- PS PE- Y PGP+ t 5 X R !tv b++ DI- D G e+ h* r+++
>> -END GEEK CODE BLOCK-
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
On Thu, Mar 3, 2011 at 8:41 AM, Efstathios Xatzikiriakidis <
> wrote:
>
> But in case of that:
>
> if (howbig = 0) {
> ...
> }
>
> The compiler will accept it and there is a logical error..


gcc gives a warning:

$ gcc -Wall -O3 gcc_test.c
gcc_test.c: In function ‘main’:
gcc_test.c:24: warning: suggest parentheses around assignment used as truth
value

Definitely not worth the convoluted style.

- Alex


Alex Leone wrote:
> $ gcc -Wall -O3 gcc_test.c
> gcc_test.c: In function ‘main’:
> gcc_test.c:24: warning: suggest parentheses around assignment used as
> truth value
>
> Definitely not worth the convoluted style.

Arduino build does not include -Wall. Which might be good or bad.

Ãlvaro

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from. Though, not warning them at all when you're using a language like C++ is pretty unfair, too.

There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages. It wouldn't be a short-term solution, but something to consider in the longer term perhaps.

= Mike

On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:

> Alex Leone wrote:
>> $ gcc -Wall -O3 gcc_test.c
>> gcc_test.c: In function ‘main’:
>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>> truth value
>>
>> Definitely not worth the convoluted style.
>
> Arduino build does not include -Wall. Which might be good or bad.
>
> Álvaro
>
> _______________________________________________
___________________________________________________

Posted on the Developers mailing list. Go to http://arduino.cc/mailman/listinfo/developers_arduino.cc to subscribe.
On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:

> I prefer if (foo == 0), so I use it in the examples too. Even though
> it may cause the error you mention, it's conceptually clearer for
> the reader.

Assuming that library issues and compiler bugs continue to make
it undesirable to turn on "-Wall", do we want to consider starting to
turn on individual warning flags for warnings that are we believe
are particularly likely to be useful to the Arduino audience
("-Wparentheses", for example)

BillW


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Nicholas Zambetti wrote:
> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

Some examples include:

unsigned bytes;
while ((bytes=readfile())) {
}

while ((bytes=readfile()>0)) {
}

Although yes, you can do it other way, but that would involve an if.
Note however the explicit parenthesis, to tell compiler that that is what we actually want.

Ãlvaro
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

It’s part of the syntax and semantics of C, Java, etc.

> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>
> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>
> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>
> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>
>>
>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>
>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>
>> Assuming that library issues and compiler bugs continue to make
>> it undesirable to turn on "-Wall", do we want to consider starting to
>> turn on individual warning flags for warnings that are we believe
>> are particularly likely to be useful to the Arduino audience
>> ("-Wparentheses", for example)
>>
>> BillW
>>
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Being part of the syntax and semantics of C and being well designed are two very different things.

On Mar 5, 2011, at 5:39, Andrew Davidson <> wrote:

> It’s part of the syntax and semantics of C, Java, etc.
>
>> Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?
>>
>> In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.
>>
>> It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.
>>
>> On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:
>>
>>>
>>> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>>>
>>>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>>>
>>> Assuming that library issues and compiler bugs continue to make
>>> it undesirable to turn on "-Wall", do we want to consider starting to
>>> turn on individual warning flags for warnings that are we believe
>>> are particularly likely to be useful to the Arduino audience
>>> ("-Wparentheses", for example)
>>>
>>> BillW
>>>
>>>
>>> _______________________________________________
>>> Developers mailing list
>>>
>>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc


Yes, they are two different things, but there are also good reasons for
the way C is. An assignment is an expression, which is how C does
for (a = 0; ...; ...)
and
a = b = ...;
It also allows standard C idioms like
while ((c = getchar()) != EOF)
Of course, there are ways to redefine the syntax to allow assignments in
only certain places, but that complicates the language and part of the
beauty of C is its simplicity. In any case, we can't redesign the language.

By the way, it's not in general possible to catch this with regular
expressions. C expression syntax is not regular. For one thing,
regular expressions cannot match nested parentheses. Yes, it's possible
to recognize an assignment at the top level of a conditional:
if (a = ...)
but what about
if (... && (... || (a = ...) || ...))?

On 01/-10/37 11:59, Nicholas Zambetti wrote:
> Being part of the syntax and semantics of C and being well designed are
> two very different things.
>...

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
Assignment inside of a conditional has been part of C since Thompson and
Ritchie.

In C everything is an expression and all expressions have value.
Assignment is an expression. This is also why you can go a = b = c = 11;

Different people have different preferences on style issues.
Many style issues become practically religious in significance.
I work in myriads of environments, from Linux Kernels, OpenBSD, OS X,
Windows, Java, ...... And they all have strong views (and often
conflicting views) on what is an is not good style.
I have my own - though having to work accross multiple environments
tends to encourage flexibility.

Personally I think

while((erC = read()) >= 0) {
....
}

is clearer and cleaner than other alternatives.



-----Original Message-----
Cc: Arduino Developers <>
Subject: Re: [Developers] Software engineering issue..
Date: Sat, 5 Mar 2011 01:30:26 -0800

Why is assignment in a conditional supported at all? Are there any situations where there is no other solution?

In the best case, it makes for code that is difficult to read, and in the worst case, a mistake that's difficult to spot.

It's fairly easy to check for in a regexp, maybe it's worth displaying a more friendly warning? The GCC one is rather abstruse.

On Mar 4, 2011, at 17:23, "William \"Chops\" Westfield" <> wrote:

>
> On Mar 4, 2011, at 5:08 AM, Tom Igoe wrote:
>
>> I prefer if (foo == 0), so I use it in the examples too. Even though it may cause the error you mention, it's conceptually clearer for the reader.
>
> Assuming that library issues and compiler bugs continue to make
> it undesirable to turn on "-Wall", do we want to consider starting to
> turn on individual warning flags for warnings that are we believe
> are particularly likely to be useful to the Arduino audience
> ("-Wparentheses", for example)
>
> BillW
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc

--
Dave Lynch DLA Systems
Software Development: Embedded Linux
717.587.7774 http://www.dlasys.net
Over 25 years' experience in platforms, languages, and technologies too
numerous to list.

"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction."
Albert Einstein


_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)


On Mar 5, 2011, at 11:57 AM, Nicholas Zambetti wrote:

> Being part of the syntax and semantics of C and being well designed are two very different things.

THank you Nick. If it were a matter of keeping to the syntax and semantics of C, I wouldn't have bothered with Arduino in the first place.
_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)
In terms of collecting error information in the Compiler.java file.
There is a MessageSiphon object that collects the errors. That could
be folded into a logging object, and all error information could be
via something something like log4j.


Do you have llvm information? I'd like to do a test configuration with
it if it's available.

--Rick

On Fri, Mar 4, 2011 at 3:24 PM, Mike Smith <> wrote:
>
> The Arduino build also suppresses warnings, which isn't necessarily a bad thing as GCC's warning (and error) messages are pretty terrible and certainly something you might want to shield new users from.  Though, not warning them at all when you're using a language like C++ is pretty unfair, too.
>
> There's been some progress on an AVR backend for llvm, which would get you the clang frontend's (vastly better) error messages.  It wouldn't be a short-term solution, but something to consider in the longer term perhaps.
>
>  = Mike
>
> On Mar 4, 2011, at 11:45 AM, Álvaro Lopes wrote:
>
>> Alex Leone wrote:
>>> $ gcc -Wall -O3 gcc_test.c
>>> gcc_test.c: In function ‘main’:
>>> gcc_test.c:24: warning: suggest parentheses around assignment used as
>>> truth value
>>>
>>> Definitely not worth the convoluted style.
>>
>> Arduino build does not include -Wall. Which might be good or bad.
>>
>> Álvaro
>>
>> _______________________________________________
>> Developers mailing list
>>
>> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>
>
> _______________________________________________
> Developers mailing list
>
> http://arduino.cc/mailman/listinfo/developers_arduino.cc
>



--
President
Fair Use Building and Research (****) Labs
http://****labs.org

_______________________________________________
Developers mailing list

http://arduino.cc/mailman/listinfo/developers_arduino.cc
)







NewsArc Lists  |  Culture Pages   |  Computing Archive  |  Media-Pages
Link to this page on your blog or website by copying the HTML code below and pasting it into your site: