Archived

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

Programming syntax

This topic is 5752 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
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
quote:
Hungarian notation is a way of naming variables to clarify their type and use.

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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites