Jump to content
nikaragua86

Is it correct to always set the attribute type in vex wrangle code ?

Recommended Posts

Hello, friends! I`ve got some issues when started coding in vex with the default float type attribute creation, so i got a habit to always set the attribute type, even in calculations, to prevent the possibility of attribute type errors.

Like this for example:

v@direction = v@initial_position - v@P;

It works fine, and i am really comfortable with it,  but I wonder is it correct in the meaning of

1) Good programming style. 

2) VEX language work under the hood - maybe VEX is re-declaring the attributes again, when they are used in this way.

Thank you!

Share this post


Link to post
Share on other sites

there is no downside to doing that as far as I am aware, except you have to type a few more characters.

However it is looked at as extremely good practice to do so, so I would continue doing it if I were you

Share this post


Link to post
Share on other sites

Prefer not to add type for global variables like @P, @N, @v.... but if there is a custom variable like f@mysuperval, yes it must be.

Share this post


Link to post
Share on other sites

I only add type if the attribute is unknown to Houdini and it's not a float. Using @ for unknown attributes will declare it as a float.

Share this post


Link to post
Share on other sites

In my opinion explicitly typing your attributes is good practice;
in particular, for not accidentally using floats when you can/should use integers(if you want to check against specific numbers)

if(x==6) is way better than if(x==6.0) for example,

Share this post


Link to post
Share on other sites

It's not essential in the same wrangle node. But if you declare an attribute in wrangle node and assign it to some other attribute in another wrangle node, it becomes essential. Like you declare a vector attribute like this :

v@x = set(1,2,4);

And if in another wrangle node you assign it to another new vector attribute :

v@y = @x;

In geometry spreadsheet, you will get only first element of attribute x in all elements of y :

y[0] = 1

y[1] = 1

y[2] = 1

This happens as it considers @x to float.

To resolve this... You shall have to declare data type again :

v@y = v@x;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×