Skip to main content
GameDev.net gamedev.net
🔒 Locked

Programming syntax

Started by Tevong Apr 19, 2002 at 5:08 PM 12 replies 1.5k views
Original Post
Tevong
Tevong
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.
Signed: T_
intransigent-seal
intransigent-seal
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]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
BloodScourge
BloodScourge
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]
I know that I don't know nothing... Operation Ivy
Dobbs
Dobbs
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.
aftermath
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
Rate me up.
Zanthos
Zanthos
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;
Oluseyi
Oluseyi
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!
Cyberdrek
Cyberdrek
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
[Cyberdrek | ]
i8degrees
i8degrees
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
"I am governed by none other than the Laws of the Universe."
DrPizza
DrPizza
quote:
Hungarian notation is a way of naming variables to clarify their type and use.

Sure, if by "clarify" you mean "obfuscate".

char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;} /*** drpizza@battleaxe.net ***/
Tevong
Tevong
One last question: If I have a set of procedures to manipulate something like my patient record. For example one for adding the details to a listview, one for deleting it etc.. Should I put these procedures in a separate module or keep the procedures on the form? What I''m doing is putting all my procedures in different modules, one module callde patient.bas for example which contains all the procedures relating to patients. Should this be kept on the form? After reading this:

"Write modular code whenever possible. For example, if your application displays a dialog box, put all the controls and code required to perform the dialog''s task in a single form. This helps to keep the application''s code organized into useful components and minimizes its runtime overhead. "

I think I should rethink how I organise my procedures..
Signed: T_
psyberia
psyberia
Personally, I use modules to declare global variables or objects and put my functions into a class.
For example, you may have a globals.bas that holds

Public clsPatients as new Patients
Public bIsNewPatient as boolean

Then in Patients.cls you might have

Public Function AddNewPatient(strPatientInfo as string) as boolean
....
End Function

Public Function RemovePatient(intPatientID as integer) as boolean
...
End Function

And finally, in your form

Sub Command1_whenclickedon()
clsPatients.AddNewPatient("George")
End Sub

Sub Command2_whenclickedon()
clsPatients.RemovePatient(1)
End Sub

Something like that.

Just my coding style. Everyone will give you different answers.
~"What''s this red button do?"
Oluseyi
Oluseyi
hungarian notation
C what
Is it just me...
Coding Standards in the Workplace
Coding to Ease Large Project Maintenance
How do you code in general?
variable naming
Hungarian notation

(Mo'' than) nuff said.

Now, as to your other question, put the procedures in a separate module because they could be reused by other forms that might need to manipulate the records.

[ 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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.