Go Down

Topic: Print commands are not consistent (Read 1 time) previous topic - next topic

mem

#15
Jul 22, 2009, 08:14 pm Last Edit: Jul 22, 2009, 08:15 pm by mem Reason: 1
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.

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: [Select]
int myvar = 32;

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


whereas this doesn't:

Code: [Select]
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





mem

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:
[font=Courier New]  int myvar = 32;
 Serial.print(myvar);  // prints out "32" [/font]
whereas this doesn't:
[font=Courier New]  byte myvar = 32;
 Serial.print(myvar);  // prints out a space [/font]


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



Granted.  PROVIDED they wanted to print a space.

b

mem

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

mellis

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.

retrolefty

#21
Jul 24, 2009, 01:03 am Last Edit: Jul 24, 2009, 01:04 am by retrolefty Reason: 1
Oh, does that mean unicode support is also on the agenda? Just kidding  ;D

Lefty


Go Up