Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tevong

Programming syntax

This topic is 6087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to develop good coding habits, and looking at other programs while learning DirectX I noticed a few things. I tend to use counter in my loops for counter=1 to 20 While most people use i for i=1 to 20 Is there a particular reason for this? Also some variable names have i attached before them like the iFont object. Why do some have it others not? In Direct3D some have the prefix m like mD3D8. What is hungarian notation? intMyInteger? I usually use MyInteger or other meaningful names but without it''s type.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Tevong
for counter=1 to 20

While most people use i

for i=1 to 20

Is there a particular reason for this?

Yeah - "i" is shorter. Personally, if it's a choice between "i" and "counter", then I'd go for "i", just because it's quicker to write. But if it's a choice between "i" and some meaningful name, then I'd use the meaningful name.

As for hungarian notation, I don't bother - but it's just personal preference (unless you work for a company that requires certain naming conventions).

John B

[edited by - JohnBSmall on April 19, 2002 6:26:43 PM]

Share this post


Link to post
Share on other sites
I think 'i' stands for 'index', then follow j,k,l and so on for inner loops (or outer, in the same code block) :
{
for i...
for j...
for k...
}
Or :
{
for i...
for j...
for k...
}
Not really a standart but commonly used for its speed!

[edited by - Bloodscourge on April 19, 2002 6:49:17 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Tevong
In Direct3D some have the prefix m like mD3D8.


m is often used to denote a member variable in a class.

quote:
What is hungarian notation? intMyInteger? I usually use MyInteger or other meaningful names but without it''s type.


Hungarian notation is a way of naming variables to clarify their type and use. As always Google is your friend here.

Share this post


Link to post
Share on other sites
IMO i dislike Hungarian, and developed my own style, which is what most people do anyway , I look at in the way as.. if you don''t know what information you''re handling.. you''re not going to be able to handle it so if you''re resorting to looking at the notation infront of the variable to remember what it does, i''d suggest looking at the probably slapped up tech document you wrote to figure out what it does
But you can argue the fact that if someone reads your code they''re gonna have a problem unless you use something standard like hungarian notation. But, as the majority of people here on gamedev don''t have programming jobs or mega projects with lots of programmers, develop your own style that suits you personally i use camel-case for my variables, eg..


myIntegerVariable := 15;
playersNickname := ''(1)Player'';


without the first hump at the beginning of the variable

and for constants...


MY_CONSTANT = 4.12;
PI = 3.14159;


I use uppercase and the _ to denote words(camel case doesn''t work for some reason )

As I use Delphi.. I do conform to 1 standard(or call it three ) which is the T, P and C prefix for Types, Pointers and Classes respectively, only because everyone who uses Delphi sticks to it(or should do ).


PMyType = ^TMyType;

TMyType = record
...
...
end;

Share this post


Link to post
Share on other sites
Please stop. We''ve had enough of these "my personal notation" threads. Search the site for them. The general consensus seems to be that applying type warts to your variables is bad practice, with Magmai Kai Holmlor being the major hold out.

Thank you and have a nice day.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
quote:
Original post by AfTeRmAtH
A good place to find "good" coding syntax is in the DirectX SDK, and other micro$oft code.

[ my engine ][ my game ][ my email ]
SPAM



According to who????



"And that''s the bottom line cause I said so!"

Cyberdrek
danielc@iquebec.com
Founder
Laval Linux

/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

Share this post


Link to post
Share on other sites
http://ootips.org/hungarian-notation.html

You decide yourself. I have to agree with the article!

I personally like this method, it stays consistant with porting, and makes more sense, not to mention less to type sometimes.

typedef unsigned char Uint8;
typedef signed char Sint8;
typedef unsigned short Uint16;
typedef signed short Sint16;
typedef unsigned int Uint32;
typedef signed int Sint32;

[Yes, I copied this straight off SDL_types.h]

Yes, SDL and OpenGL use this method. Their code is portable

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!