Harley Rana
Junior Devvie  
Java games rock!
|
 |
«
Posted
2003-04-02 04:56:55 » |
|
Hey guys, its a personal question, close to the heart of all game programmers. How do you name vectors?
We got a list to choose from : vec3,vect3,Vec3,Vect3,Vector3,Vector3f,float3,and many more.
What do you like?
|
|
|
|
cfmdobbie
Senior Devvie    Medals: 1
Who, me?
|
 |
«
Reply #1 - Posted
2003-04-02 05:22:39 » |
|
I'm going to call all mine "Jennifer".
|
Hellomynameis Charlie Dobbie.
|
|
|
Matzon
|
 |
«
Reply #2 - Posted
2003-04-02 06:05:52 » |
|
I like that the vectors (indeed any field) are named after their purpose (No! I am not going to discuss the purpose of "Jennifer"). None of my fields are ever called vec3 or likewise. cameraPosition is so much more understandable than vec3.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Breakfast
|
 |
«
Reply #3 - Posted
2003-04-02 06:23:59 » |
|
I like names that make up sentences that BA might have said, so I call them things like "jibba", "jabba", "crazy" and "foo". It makes for very readable code too. If you're howlin' mad.
|
|
|
|
GergisKhan
Junior Devvie  
"C8 H10 N4 O2"
|
 |
«
Reply #4 - Posted
2003-04-02 13:11:01 » |
|
Breakfast - that was very painful.
I'm using some crazy form of weak Hungarian (I think it is) or something like that, so I'd choose something like v3fIdentifier, where Identifier is what this thing's purpose is. I also abstain on what v3fJennifer might be for. *evil grin*
|
gK
"Go. Teach them not to mess with us." -- Cao Cao, Dynasty Warriors 3
|
|
|
jbanes
|
 |
«
Reply #5 - Posted
2003-04-02 13:18:56 » |
|
Please! No Hungarian notation! Hungarian notation only makes code less readable instead of more! If you can't identify your variable types, you need to clean up your code so you can see your definitions. After all, Hungarian notation was developed at MICROSOFT of all places. That should be a good tipoff that it's not a solution for clean code.
|
|
|
|
GergisKhan
Junior Devvie  
"C8 H10 N4 O2"
|
 |
«
Reply #6 - Posted
2003-04-02 13:40:18 » |
|
I agree with the MS comment, though I disagree on the readability. I *HAVE* been using this scheme for almost four years now, and it's just what is comfortable for me. As was mentioned earlier, it is an opinion.
|
gK
"Go. Teach them not to mess with us." -- Cao Cao, Dynasty Warriors 3
|
|
|
Breakfast
|
 |
«
Reply #7 - Posted
2003-04-02 13:42:45 » |
|
Hungarian notation was developed by MS? Why is it called Hungarian notation? Why not Microsoftian Notation? Were the people of hungary even consulted?
|
|
|
|
GergisKhan
Junior Devvie  
"C8 H10 N4 O2"
|
 |
«
Reply #8 - Posted
2003-04-02 13:43:49 » |
|
The gentleman who created it was Hungarian, I believe....
... goes along with how you get things like Reverse Polish Notation (which I think is absolutely brilliant, btw).
|
gK
"Go. Teach them not to mess with us." -- Cao Cao, Dynasty Warriors 3
|
|
|
jbanes
|
 |
«
Reply #9 - Posted
2003-04-02 13:57:22 » |
|
Love RPN. You can do math, left to right without ever worrying about "decoding" operator priority. My biggest beef with Hungarian notation is that it smacks of a hack on top of a hack. Since the guys at Microsoft could no longer find what their variable definitions were, they created a syntactical standard that put the definitions in the name. Unfortunately, the world got trained to use it, and now we have the joys of code like "hwndMyWindow" even in Java where it's pretty much unnecessary. But you're right, a lot of people use it and are used to it. Which is too bad for them, because I'm always on a crusade to get people to produce nothing but the cleanest code. 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
rgeimer
Senior Newbie 
|
 |
«
Reply #10 - Posted
2003-04-02 15:34:18 » |
|
Don't have a favorite name for vectors, but I usually call my buffers "buffy".
|
|
|
|
cfmdobbie
Senior Devvie    Medals: 1
Who, me?
|
 |
«
Reply #11 - Posted
2003-04-02 16:29:30 » |
|
Okay, I was kidding, but I have the horrible feeling you're being serious...  With me, a temporary values are easy - a ByteBuffer will usually be called "bb", a Sprite will probably be "s", "i" is used for iterating over arrays (move on to "j" and "k" if nesting), and "x" and "y" are for iterating over two-dimensional arrays that have some concept of coordinates etc etc. Longer-lived references are similarly standardised, but are descriptive based on use/contents rather than type. I suppose it really doesn't matter what scheme you use as long as you're consistent. I've developed my system so that I can look over code I'd written many moons before and understand what it all means with very little effort. This is helped by good API design and liberal documentation. I think the original question was specifically about the naming of vector types. They're described in so many different ways that I'm sure all of the mentioned forms are present in an API somewhere. I would stay with Capitalisations for class names, and would try to avoid suffixing with "3" - it's not hard to write a class that will represent all the dimensions you throw at it, and remember what it's supposed to be. As for the length of the name (vec/vect/vector), I think that's entirely personal choice. For me, I'd go with "Vector" because I don't like things unnecessarily abbreviated. Ur mileage may vry.
|
Hellomynameis Charlie Dobbie.
|
|
|
Breakfast
|
 |
«
Reply #12 - Posted
2003-04-02 18:04:42 » |
|
When Edsger Dijkstra died last year I read a comment somewhere that not only did he contribute a huge amount to computer science but he was also the only high profile computer scientist to have the classic loop variables i, j and k in order in his name.
|
|
|
|
Harley Rana
Junior Devvie  
Java games rock!
|
 |
«
Reply #13 - Posted
2003-04-03 00:59:40 » |
|
horrible feeling you're being serious... well, half serious, half tounge firmly in place.  Hey cfmdobbie this is what happends when you ask a question, you find out more than you wanted to know.  Hungarian notation was created to solve scope problems in C, so theres not much need for it now. Except hordes of people still love it.  Seems to be really popular with C++ coders. Its just what your used to and like i guess. Im growing fonder of float3. The same naming as the CG language. You won't find any cleaner!  I know im breaking the sacred java rules, but i'll live.
|
|
|
|
mill
Junior Devvie  
popcorn freak
|
 |
«
Reply #14 - Posted
2003-04-03 04:47:53 » |
|
since i'm a XP friend, i always use long informative names. not it's not hard or time consuming to write since either a) i'm fast or b) i press CTRL+SPACE in Eclipse  makes code so much easier to read. one thing that annoys me reading other's code is that people shorten already short variables like Proc for Process! (they do at the university in the OS course, silly) anyway, i like the JCS since 'coding conventions' is one of the xp practices and it's easy to point people to sun's site and read it there. 
|
|
|
|
swpalmer
|
 |
«
Reply #15 - Posted
2003-04-03 14:35:54 » |
|
Hey if we are talking coding conventions lets have a fight about the evils of misplaced parenthesis :-) I hate Sun's 'standard' way.. I like my {} aligned... 1 2 3 4
| if( blah ) { woo(hoo); } |
I've seen some odd alternatives too.. like.. 1 2 3 4
| if( blah ) { ew(yuk); } |
And if I had to name them, I would call them Floyd  .
|
|
|
|
jbanes
|
 |
«
Reply #16 - Posted
2003-04-03 14:52:31 » |
|
I hate Sun's 'standard' way.. I like my {} aligned... Damn straight, skippy!
|
|
|
|
cfmdobbie
Senior Devvie    Medals: 1
Who, me?
|
 |
«
Reply #17 - Posted
2003-04-03 15:42:01 » |
|
Me too!  I like my braces aligned, all apart from in two situations, where I prefer them "split": 1 2 3 4 5
| String[] filenames = { "foo.txt", "baa.rgb", "quux.tar.gz" } ; |
1 2 3 4 5 6
| f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { } }) ; |
I suppose this is because it avoids a hanging equals symbol in the first, and makes the point that it's an inline class definition in the second. It just seems right in those two situations. How about asking whether there's a space before the semi-colon at the end of a statement, spaces immediately padding out parentheses, single-line if/for/do/while constructions with or without braces...  (BTW: yes/no/without)
|
Hellomynameis Charlie Dobbie.
|
|
|
jbanes
|
 |
«
Reply #18 - Posted
2003-04-03 15:48:30 » |
|
if((data = in.read()) >= 0) out.write(data);
Extra spaces take up more width without giving back much readability IMHO. Of course, that's one of those minor points that I'm usually pretty flexible on.
|
|
|
|
Breakfast
|
 |
«
Reply #19 - Posted
2003-04-03 18:41:57 » |
|
Damn right about the aligned parenthesis. I thought I was the only person who thought the open bracket after the declaration looks stupid.
|
|
|
|
Matzon
|
 |
«
Reply #20 - Posted
2003-04-03 18:49:35 » |
|
I thought I was the only person who thought the open bracket after the declaration looks stupid. No there are a couple of you 
|
|
|
|
Ceranith
Senior Newbie 
|
 |
«
Reply #21 - Posted
2003-04-03 21:19:20 » |
|
No there are a couple of you  Yeah, one more here 
|
|
|
|
Harley Rana
Junior Devvie  
Java games rock!
|
 |
«
Reply #22 - Posted
2003-04-04 00:25:12 » |
|
Ive beeing learning and looking at more c++ lately, and the styles have really rubed off on me. Like next line braces, and more use of abbrivated variable/class names. But still havn't picked up hungarian notation, which is so common. I think using abbrivations can be overused, but there are some cases where it works. Like when the meaning is clear, and its used all over the place, like vectors.  Regularly i thank the kind souls that gave us eclipes, and its code formater. I never would have been able to make an inner listener with out them. 
|
|
|
|
Harley Rana
Junior Devvie  
Java games rock!
|
 |
«
Reply #23 - Posted
2003-04-04 00:30:05 » |
|
While we are talking formating, what is style comments do you like?  Im thinking more for personal readability than java doc compliance.
|
|
|
|
GergisKhan
Junior Devvie  
"C8 H10 N4 O2"
|
 |
«
Reply #24 - Posted
2003-04-04 12:37:33 » |
|
Jumping in late, but.... I don't care for non-aligned braces at all. I WANT to see my code blocks, and virtually every editor I have used does some form of highlighting if you put the cursor at one brace or another (even vi does this, just hit % and it takes you to its pair). As for spacing, I'm a spacing freak. I prefer spaces before parenthesis, except for class cast like this: temp = (Image) vImages.next(); if ( temp != null ) { // Do something here } And no space when there's nothing between the (). Comments? What are those???? *evil grin* (For me, I just like straight javadoc, or a // one liner for explanation.) Further question: who likes their variables aligned, and what convention do you use? 1 2 3
| int x; Object y; DataBuffer z; |
|
gK
"Go. Teach them not to mess with us." -- Cao Cao, Dynasty Warriors 3
|
|
|
Breakfast
|
 |
«
Reply #25 - Posted
2003-04-04 12:47:45 » |
|
I don't align the variables, that seems a bit excessive, but I am quite careful to always declare the same types together.
I find that I don't usually need much more than the javadoc comments- as long as you keep methods short, splitting the really long ones up if necessary, you can usually work out what is going on. And For some reason I find going back through my own Javadocs quite satisfying. I don't know why.
|
|
|
|
swpalmer
|
 |
«
Reply #26 - Posted
2003-04-04 21:00:50 » |
|
I sometimes align variables that are related, with spaces, so tab sizes don't bugger them up. It depends on how different the 'type' identifiers are in length too.. if the variable name will get 'hidden' in a crevice I add spaces to pull it out. e.g. in: 1 2 3
| MegaBlasterLevel level; int score; SuperDuperSpaceShip ship; |
I would push 'score' out to line up with 'level'
|
|
|
|
oNyx
|
 |
«
Reply #27 - Posted
2003-04-04 22:50:37 » |
|
Hey if we are talking coding conventions lets have a fight about the evils of misplaced parenthesis :-) I hate Sun's 'standard' way.. I like my {} aligned... 1 2 3 4
| if( blah ) { woo(hoo); } |
I've seen some odd alternatives too.. like.. 1 2 3 4
| if( blah ) { ew(yuk); } |
And if I had to name them, I would call them Floyd  . i used the 2nd style for some years. switched awhile ago to the first one, cuz it was much easier to type with textpad :> if i had to name em, i would call em block-style A and block-style B. sounds cold and techie doesnt it? =) "sun's way" is called "hugging brackets" (or summin like that)... dunno i hate it too  and names for other stuff... mh... 1 2 3 4 5 6 7 8 9 10
| int bs = 0; int bsX=666; int bsA=0; int bsY=60;
int[][] exx=new int[MAX_STUFF][3]; int ex=0;
int[][] hh=new int[MAX_STUFF][3]; int h=0; |
somewhat scary isnt it? :>
|
|
|
|
oNyx
|
 |
«
Reply #28 - Posted
2003-04-04 22:59:54 » |
|
[...] I would push 'score' out to line up with 'level' it would look better but it wouldnt increase readability (imo). 1 2 3 4 5 6 7 8 9
| g.fillRect(0, 0,640,60); g.fillRect(0,420,640,60); [...] for(x=0;x<MAX_STUFF;x++) { pp [x][1]= 0; exx[x][2]=62; hh [x][1]= 0; } |
in this two cases it makes more sense. u can read it much better, cuz the values wich have summin in common are next to each other. btw that r parts from my highly ineffective 4k game, wich isnt finished yet :>
|
|
|
|
erikd
|
 |
«
Reply #29 - Posted
2003-04-11 07:06:09 » |
|
For what it's worth, I learned to like the 'sun' way of brackets although I really hated it at first. It makes the code more compact while keeping readability and sometimes even enhances it in case of larger functions (I like keeping an overview and I hate scrolling through code). In fact I like the sun conventions in general.
|
|
|
|
|