Rename vector types to Vector2, Vector3, Vector4

111 views
Skip to first unread message

Hassan Hayat

unread,
May 4, 2014, 3:57:54 PM5/4/14
to elm-d...@googlegroups.com
Hi there,

I've been playing around with Elm and found it really fun and simple to use. I have been looking at the source code and saw the upcoming webgl support on the webgl branch and I must say that this is exciting. I couldn't help but notice that the data types for vectors and matrices are called V2, V3, V4 and M4x4. It may be just me but at first when I was going through the code it took me a minute or so to figure out what V2, V3 and V4 stood for.

I was wondering if they could be renamed to Vector2, Vector3, Vector4 and Matrix4x4 respectively. I think that given that types are used a lot for documentation, this would help clarify code a lot. 

Cheers,

Hassan Hayat

Evan Czaplicki

unread,
May 4, 2014, 4:18:51 PM5/4/14
to elm-d...@googlegroups.com
Hassan and I talked about this a bit on Reddit. I just tried rewriting the examples with Vector3 and it seemed like a lot. So here's my feeling now:
  • Vector3 - Super clear, perhaps a bit long in realistic code examples
  • Vec3 - Clear enough, short enough, no corresponding thing for M4x4
  • V3 - so short, clear once you are in the club, makes it so people don't feel bad at all annotating things when there's lots of vectors flying around.
I think people doing 3D will be something of an expert audience, so V3 feels fine. I was okay with it, but I've done linear algebra and programmed with OpenGL before. Also, that it is "an expert tool" does not mean we should give up on making it accessible.


--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hassan Hayat

unread,
May 4, 2014, 5:10:01 PM5/4/14
to elm-d...@googlegroups.com
I was just wondering, maybe since these types are to be used in conjunction with glsl that they be named like glsl names them but with a leading capital letter. I didn't realize until you pointed out that you can call it Vec3. It seems like by coincidence Elm already named its types like GLSL (Bool, Float, Int correspond to bool, float, int respectively) so why not just continue with Vec2, Vec3, Vec4, Mat2, Mat3, Mat4. The correspondence then becomes obvious and then there's no questions like "do I have to convert this data type to something glsl can use?" or something, especially since these datatypes don't have to be used to do 3d graphics. 

Evan Czaplicki

unread,
May 4, 2014, 5:20:54 PM5/4/14
to elm-d...@googlegroups.com
Interesting, I did not notice that. I think matching the names in GLSL is a pretty strong argument. So that'd be like this?

Vec2, Vec3, Vec4, Mat3, Mat4

I sort of like Mat4x4 a bit more, but maybe that's not necessary?

Hassan Hayat

unread,
May 4, 2014, 5:26:56 PM5/4/14
to elm-d...@googlegroups.com
Yup. And don't forget Mat2.  

John Mayer

unread,
May 4, 2014, 6:02:43 PM5/4/14
to elm-d...@googlegroups.com

Yes this is a good idea. I like the 4-character versions the best.

Daniël Heres

unread,
May 4, 2014, 6:24:14 PM5/4/14
to elm-d...@googlegroups.com

I would go for names like Vector3. It is the best for both beginners and experts. In linear algebra these are also called vectors, not "V2's".

Hassan Hayat

unread,
May 4, 2014, 6:59:45 PM5/4/14
to elm-d...@googlegroups.com
I've been looking around to see what others have done in similar situations. Turns out that  ThreeJS calls them Vector3 and Matrix4 etc... I guess that the comparison is a bit unfair because there are no type annotations in Javascript so it's more important to have very clear names in JS. But I checked out the typescript version of ThreeJS and they also call them Vector3 and Matrix4 and stuff.

Haskell's vector library calls the vector type "Vector" but haskell has a generic vector type that's kinda like an array. If you do scroll down in the wiki, you can see that whenever they show examples of having a vector with known dimension size they call it Vec3 or Vec4. But Haskell doesn't have to deal with having GLSL code mixed in with Haskell code as an important part of its workflow. 

Idris calls them Vect but I think the extra "t" is ugly. 

Hope this helps.

I just felt the need to comment on this because libraries like ThreeJS have made 3D graphics and WebGL accessible to so many people, including beginners and people with little knowledge of linear algebra. 

John Mayer

unread,
May 4, 2014, 8:00:00 PM5/4/14
to elm-d...@googlegroups.com

No I definitely think "V3" is too short. But I'm worried about line-length for complex types. Maybe using the regular GLSL names is a nice idea.

End of the day, I don't really mind which way it goes.

Alexander Berntsen

unread,
May 5, 2014, 10:38:56 AM5/5/14
to elm-d...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 04/05/14 23:20, Evan Czaplicki wrote:
> Interesting, I did not notice that. I think matching the names in
> GLSL is a pretty strong argument. So that'd be like this?
>
> Vec2, Vec3, Vec4, Mat3, Mat4
As someone with an OpenGL game programming background, this is my
preferred naming convention.
- --
Alexander
alex...@plaimi.net
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlNnooAACgkQRtClrXBQc7VktgD+Kmu76PcXcisEoYDw61T5ep/d
PhXvuPzD1uHYNJhR7DcBAKdxPp4J7ry6dU6ks/Yzy/2IhtY2J3RsRVyfppcT8q3S
=QvLh
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages