Pages: 1 [2]   Go Down
Author Topic: Print commands are not consistent  (Read 1516 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think the OP is confused as to the difference between "print"ing an int versus a uint8_t.
I don't think the OP was confused about the difference, he wanted a different behaviour – for similar reasons to the one you posted.

I would think that the current Arduino behaviour was borrowed from Processing. Those familiar with Java will be comfortable with the way it works now. There are a few things that Arduino borrowed from Processing that seem odd to C/C++ programmers but the underlying principle has been do make Arduino intuitive to non-technical people and I think the way print works now does that better then the more rigorous behaviour being proposed in this thread.

Anyway, changing the behaviour would break existing code so I think we need to get used to it.
« Last Edit: July 22, 2009, 01:15:48 pm by mem » Logged

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

FWIW, I don't think anything rigorous was proposed.  It's purely semantical.  It's about interface consistency - which is HIGHLY desirable for newcomers.

Try telling someone new to the Arduino community that this works as expected:

Code:
int myvar = 32;

Serial.print(myvar);  // prints out "32"

whereas this doesn't:

Code:
byte myvar = 32;

Serial.print(myvar);  // prints out a space

I don't want to dwell on this, because it would take enormous effort to have the current Print class changed (even though it's a tiny change).  We have to live with the quirks in the system.  It wouldn't be life if we didn't!

b




Logged


London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It's purely semantical.  It's about interface consistency - which is HIGHLY desirable for newcomers.

Try telling someone new to the Arduino community that this works as expected:
 int myvar = 32;
  Serial.print(myvar);  // prints out "32"

whereas this doesn't:
 byte myvar = 32;
  Serial.print(myvar);  // prints out a space

I am happier telling someone new to programming that
  Serial.print(' ');
Prints a space (not the number 32)


Logged

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Granted.  PROVIDED they wanted to print a space.

b
Logged


London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my experience people new to programming expect Serial.print('A'); to print the character A
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Except that 'A' is a signed char and byte is an unsigned char, so that they can behave differently.  I actually think that now that we've added Serial.write(), we should change the behavior of print(byte), but we would need to figure out how to communicate the change.
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16564
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, does that mean unicode support is also on the agenda? Just kidding  ;D

Lefty

« Last Edit: July 23, 2009, 06:04:06 pm by retrolefty » Logged

Pages: 1 [2]   Go Up
Jump to: