Loading...
Logo
Processing Forum
I was just starting to write a class for vectors and noticed that my normalize method appears as blue. It doesn't seem to cause an error. When is it problematic to use text that Processing highlights?

Here is the class so far (far from done):
Copy code
  1. class Vec {
  2.   float x, y, z;
  3.   Vec() {
  4.     x = 0;
  5.     y = 0;
  6.     z = 0;
  7.   }
  8.   Vec(float inX, float inY, float inZ) {
  9.     x = inX;
  10.     y = inY;
  11.     z = inZ;
  12.   }
  13.   void normalize() {
  14.     float mag = sqrt(x*x+y*y+z*z);
  15.     x /= mag;
  16.     y /= mag;
  17.     z /= mag;
  18.   }
  19. }
Edit: The text that is highlighted is normalize

Replies(5)

For writing classes for general use, I believe any highlighted names should be avoided.
Processing framework API has lots of defined constants, classes and methods we don't know about much!
It is an indication that name may be in use now or is planned for future use or maybe it has been deprecated already!
But better safe than sorry!  

But on second thought, since normalize() is encapsulated inside your "homemade" class Vec, and also it needs to be instantiated before calling it; I guess it's pretty safe.

The only collateral effect is that if normalize is valid for some Processing version, you won't be able to use it inside your class anymore, since it got overridden (polymorphism) by yours!  

Although the highlighting may confuse others who may end up using your class!
In addition to GoToLoop's explanations, I would say that PDE highlighting isn't perfect, far from it. Particularly in v.1.5.1...
It isn't context sensitive, so it cannot distinguish mousePressed from mousePressed(). size is a valid variable name (and, as said, even more valid as field name), but it will be highlighted as size().
A draw() method will be highlighted like the draw() function, but it is safe inside a class.
And so on.
You have to be careful, but if you don't have syntax errors nor strange behavior (to distinguish from your own bugs...), it should be OK. If in doubt, just ask in this forum!
Well, that is significantly more complicated than I was hoping :p

Will Processing at least always warn me when I'm doing something wrong then? Or should I just avoid highlighted text when in doubt?
As me and PhiLhotold yo already, it seems pretty safe to use highlighted words.
The highlighting itself is the most Processing can do as a warning feature.
Only by testing your class you can be sure it's really alright!
" Will Processing at least always warn me when I'm doing something wrong then?"
It depends... If you make a variable or constant hiding a name used by Processing, well you only loose the access to this variable. Naming a variable the same name than a function (and reciprocally) is safe.