Page 4 of 6

Re: Naming Conventions

Posted: Sat Jul 31, 2010 3:32 am
by Rathinagiri
I like cowboys, because:

- they are individual, enough to they self; no need being together anyone
- they don't know nor obey to any rule, if necessary, poses rules they self
- they are courageous, never afraid of mistake or forget anything
- they haven't any worry on "how works" a tool they made, important is "what" that tool make

I like citizens too, because:

- they are social, couldn't live alone
- they are always obey to rules; discuss and works for change rules when necessary, but always obey existing rules; this make their society worth to live
- they are careful against danger, such as mistake and forget
- they concern on "how works" tools, as far as "what" that tool make; so attach importance to being "understandable" tools they made and tools they will analysis
Oh! words, flowing like a stream!

I want definitely be a cowboy-citizen. :)

Please continue Esgici. I like verbatim.

Re: Naming Conventions

Posted: Sat Jul 31, 2010 11:57 am
by esgici
Thanks Sudip and Rathi :)

Certainly, the life isn't black and white, it's "contrasty", that is there are much of shading, there are many gray.

In reality, we are coding mostly in mixed-style; someone (or sometime) close or far to cowboy. Because every non-casual programmer sooner or later seen and live bad ends of bad style; and using strictly the good style is almost impossible, at least very difficult.

Why difficult ? Because programmers are always rushed for time, never have time to spend for extra occupations; they must work quickly for reaching their target erewhile, before their competitors ( especially in economic manner ). Especially at the beginning, writing according to some coding rules is really annoying and time consuming process.

Another difficulty is, we haven't any "universal" coding style; only some general approaches, for a specific language, posed a specific company, for their own products.

Q: If so, what we must do, continue to bad style ?

A: Definitely NO ! In my opinion, the way is: without overload ourself, make effort stepwise to the good style.

Q: Which coding standard is the best ?

A: We haven't the best, only betters ;)

My suggestion is : the better way is the better to you. Yes, build your own coding standard your self.
But rule 1: Your style must be other than "no style", and 2: Obey always rules of your own style.

to be continued ...
Sudip wrote:Sometimes an enjoyable discussion or chat or in our local language "Adda", doesn't continue without small inputs from the other participants also ...
I liked it, monologue is worst kind of speak ;)

Regards

--

Esgici

Re: Naming Conventions

Posted: Sat Jul 31, 2010 4:27 pm
by Rathinagiri
My suggestion is : the better way is the better to you. Yes, build your own coding standard your self.
I like this a lot. :)

Please do continue Esgici.

Re: Naming Conventions

Posted: Sun Aug 01, 2010 3:58 am
by sudip
Hello,

IMHO, Naming Convention is also related to programming methodology. Structured Programming naming convention may be slightly different from Object Oriented Programming.

Please correct me if I am wrong :)

Re: Naming Conventions

Posted: Sun Aug 01, 2010 12:17 pm
by esgici
sudip wrote:IMHO, Naming Convention is also related to programming methodology. Structured Programming naming convention may be slightly different from Object Oriented Programming.
May be :?

Sadly, I haven't any experience on OOP :(

Regards

--

Esgici

Re: Naming Conventions

Posted: Sun Aug 01, 2010 1:49 pm
by esgici
Hi All

Again me and again the same subject :(

( We means "writing style" no "design style for program logic" by the term "Coding Style" )

Coding, naming, conventions, style ... all of them are for only one goal : readability; that is easy to understand.

So, building a coding style is very simple: when one of your friend ( student, co-worker, or anyone else ) bring/send to you a program file for read ( for search an error, say only your opinion etc ); how it been wrote you want , your coding style must be is that style ;)

I couldn't say "the best style is ..." and posing some rules. I can only say you my own style ( in short as soon as possible :) ):

- Indentation is very important. It must be reflect hierarchy. The rule is simple : every statement block enclosed by a block statement will be intended.

Example :

Code: Select all

  SELE DETY

  WHILE .NOT. EOF()
       ...
       WHILE cDetCode == cMastCode
             IF cDetCode == "abcxyz"
                ...
                 FOR nTransaction := 1 TO nTransCount
                       ...
                       DO CASE 
                             CASE cTransCode == "A"
                              ...
                             CASE cTransCode == "B"
                              ...
                             CASE cTransCode == "C"
                              ...
                             CASE cTransCode == "D"
                              ...
                       END CASE // cTransCode
                       ...
                 NEXT // nTransaction
                 ...
             ENDIF cDetCode == "abcxyz"
       ENDDO // cDetCode == cMastCode
       ...
  ENDDO // .NOT. EOF( DETY )  
  ...
or

Code: Select all

PROC Main()
    IF SetUpFiles()
       ...
       DEFINE WINDOW frm... ;
           ...
           DEFINE MAIN MENU
                ...
              POPUP  "File"
                  POPUP  "New"
                      ITEM  ...
                      ITEM  ...
                      SEPARATOR
                      ITEM  ...
                  END POPUP // New                  
                  ITEM  "Quit"         ...                              
              END POPUP // File
              POPUP  "Help"                                
                  ITEM  "?"  ...
                  ...  
              END POPUP // Help
           END MENU // MAIN
       END WINDOW // frm...
 
    ENDIF //  SetUpFiles()

RETU // Main()
- I'm continuing abbreviate keywords up to four character (fe FUNC, PROC, RETU...). This is an very old habit come very early dBase days :( While that time we have only one program editor embedded in dBase and it had 4 KB ( yes 4096 bytes only :shock: ) capacity. This abbreviation is totally meaningless for now ; but it's very difficult quitting old habits. Perhaps this abbreviation like me more readable :?

- Instead of building and using long program file, long modules (procedure of function), I'm taking care of taking it short as soon as possible ( divide and conquer ;) ).

- We talked much on prefixing variable names. Naming conventions doesn't only prefixing, beside prefix, name itself is important and not only for variables, for all identifiers, including modules ( procedures and functions) too.

I'm using upper letters for keywords and module names of system ( Habour or HMG). I don't understand, someones so to say hates upper letters :? For me, everything that serve readability is useful.

My conventions for names of identifiers (including module names) is:

- Every name must reflect and/or remind its function.

- Name may consist with one or more word. Words may abbreviated, but this abbreviation must reflect, remind the word without losing the meaning.

- Every word ( abbreviated or not ) in the name begin with upper letter and continue lower ones.

- Though possible, don't begin names one with or more "_" (underscore); this way used by system.

Examples :

cABC : cFirstAttempt
nXYZ : nUnDefinedItem
nIndex : nFieldIndx
cName : cCoustmrName
dDate : dBirthDate
lTrue : lSaved
cNATB Name of author of this book) : cAuthName

( I haven't any comment for single letter names :( )

And at last commenting !

Comments are comments and at point of view of readability, they are valuable as soon as how they are so much .

That is all, folks :D

Please forgive long speaking and please remind me if any point left missing.

Regards

--

Esgici

Re: Naming Conventions

Posted: Sun Aug 01, 2010 4:27 pm
by sudip
esgici wrote:
sudip wrote:IMHO, Naming Convention is also related to programming methodology. Structured Programming naming convention may be slightly different from Object Oriented Programming.
May be :?

Sadly, I haven't any experience on OOP :(
...
I think, I also don't have :)

Thanks a lot Esgici for the excellent discussion. :D

Regarding 4 letter commands, it reminds old dbase days :)
I am generally using full commands.

Esgici, please tell us something about indentation. :)

Thanks in advance.

Re: Naming Conventions

Posted: Sun Aug 01, 2010 5:49 pm
by esgici
sudip wrote: please tell us something about indentation. :)
Thanks to warm interest Sudip :)

Sorry, but I suppose that I said everything necessary on indentation :(

Please let me know where left missing, so I'll strive for completion.

Regards

--

Esgici

Re: Naming Conventions

Posted: Mon Aug 02, 2010 4:53 am
by sudip
esgici wrote:...
Please let me know where left missing, so I'll strive for completion.
...
You haven't missed anything :) I perhaps missed it. Now, I like to know:
1. 2/3/4 spaces - which do you prefer?
2. A good indenting tool (like Edit -> Format current Prg source in xMate)
Thanks in advance.

Re: Naming Conventions

Posted: Mon Aug 02, 2010 5:33 am
by mol
About indentations:
I'm using Esgici's style with TAB char. I'm setting editor to TAB=4 spaces
In my opinion, it causes program is very easy to read and search errors, especially when written with a lot of cases, iterations etc.