1. Aesthetically pleasing identifier names

When I was a young and tender programmer, if I wanted to declare a function to,
say, set a menu bar to a certain value, I would probably name the function
something like "smb" which of course, stood for "set menu bar".

After a few years, I decided that that was not very self-documenting, so I would
name such a variable "setmenubar".  This made the code more readable and was
worth the extra typing.

Sometime later, I saw people using underscores in their identifier names, and I
decided to give that a try.  My function would hence be called "set_menu_bar".

Still years later, I began to see people using case to separate the individual
words in an identifier name.  I tried it.  My function would now be called
"SetMenuBar".  I found my code to be more readable and much more aesthetically
pleasing.  In fact, I have become a convert to this way of naming identifiers. 
As a convert, I am now trying to get others to see the light so that it will be
easier to read their code.

What do you think?

Brent

new topic     » topic index » view message » categorize

2. Re: Aesthetically pleasing identifier names

Brent W. Hughes wrote:
> 
> Still years later, I began to see people using case to separate the individual
> words
> in an identifier name.  I tried it.  My function would now be called
> "SetMenuBar".
> I found my code to be more readable and much more aesthetically pleasing.  In
> fact,
> I have become a convert to this way of naming identifiers.  As a convert, I am
> now
> trying to get others to see the light so that it will be easier to read their
> code.

Interesting discussion all over the place...

    http://www.google.com/search?q=variable+names

-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/

new topic     » goto parent     » topic index » view message » categorize

3. Re: Aesthetically pleasing identifier names

Brent W. Hughes wrote:
> 
> 
> Still years later, I began to see people using case to separate the individual
> words
> in an identifier name.  I tried it.  My function would now be called
> "SetMenuBar".
>  I found my code to be more readable and much more aesthetically pleasing.  In
>  fact,
> I have become a convert to this way of naming identifiers.  As a convert, I am
> now
> trying to get others to see the light so that it will be easier to read their
> code.
> 
> What do you think?
> 
> Brent
> 

Hi Brent,

"SetMenuBar"

Yes, that's a good method and there's even a name for it...it's called
"CamelBack" capitalization.
I use this all the time but combine with understores to show higher
level hierarchy.  For example, if i have a lot of buttons in my prog
i might do this:

Button_ExitNumberOne
Button_ResetCalculator

Combined with namespace identifiers you get several levels of
hierarchy without too much effort (as in the WinClass Library).



Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

4. Re: Aesthetically pleasing identifier names

I used to use CamelCaps but now I've switched to foo_bar instead of FooBar for
most identifiers. However, it depends on the language I'm using as I try to keep
a similar naming convention to how the language tends to do it (although I can't
stand fooBar since I think it's stupid to leave the first character of a word
you'd normally capitalize lowercase even though you capitalize everything else,
Java does this). In Euphoria it's almost always foo_bar since all the standard
libraries use this method.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Aesthetically pleasing identifier names

> I used to use CamelCaps but now I've switched to foo_bar instead of FooBar for
> most identifiers. However, it depends on the language I'm using as I try to keep
> a similar naming convention to how the language tends to do it (although I can't
> stand fooBar since I think it's stupid to leave the first character of a word
> you'd normally capitalize lowercase even though you capitalize everything else,
> Java does this). In Euphoria it's almost always foo_bar since all the standard
> libraries use this method.

For me, its not the language I'm using, but the platform (since
Euphoria is cross-platform). For Windows, I tend to use Derek's
Notation, even if I'm not using Win32Lib. Objects, such as control
id's and control type constants, start with a capital letter and use
CamelCaps style. Routines, however start with a lower case letter and
the first letter of every word is capitalized. Of course even Derek
strays from this from time to time...

DN Prefixes:
    k - global constant
    v - global variable
    l - local variable (routine-level)
    p - parameter (routine-level)
    Printer, Screen - Objects
    setHandler(), getCtlSize() - Routines

Again, this is only in Windows. For DOS and Linux, I still uses Robert
Craig's Notation. This is a more simple (can I say that?) notation.
Constants are expressed in all caps, and routines and variables are
all lower case, with each word separated by an underscore. Library
routines may be grouped by using the same prefix (db_) for database.e.

    TRUE, FALSE - constants
    get_vector(), db_fatal_id - routines, variables

~Greg

new topic     » goto parent     » topic index » view message » categorize

6. Re: Aesthetically pleasing identifier names

Brent W. Hughes wrote:
> 
> When I was a young and tender programmer, if I wanted to declare a function
> to, say,
> set a menu bar to a certain value, I would probably name the function
> something like
> "smb" which of course, stood for "set menu bar".
> 
> After a few years, I decided that that was not very self-documenting, so I
> would name
> such a variable "setmenubar".  This made the code more readable and was worth
> the extra
> typing.
> 
> Sometime later, I saw people using underscores in their identifier names, and
> I decided
> to give that a try.  My function would hence be called "set_menu_bar".
> 
> Still years later, I began to see people using case to separate the individual
> words
> in an identifier name.  I tried it.  My function would now be called
> "SetMenuBar".
>  I found my code to be more readable and much more aesthetically pleasing.  In
>  fact,
> I have become a convert to this way of naming identifiers.  As a convert, I am
> now
> trying to get others to see the light so that it will be easier to read their
> code.
> 
> What do you think?
> 
> Brent
> 



this i how i name variables now:

routines: 		setMenuBar()
independant routines:   set_menu_bar()
local variables: 	localVar
global variables: 	GlobalVar
constants: 		MY_CONSTANT

new topic     » goto parent     » topic index » view message » categorize

7. Re: Aesthetically pleasing identifier names

For Win4Eu I started using this naming convention systematically:
- names of classes (types): all words capitalized, no underscores
   (Control, Mouse, Application, SolidBrush, ...)
- names of routines (functions): all words capitalized, except the first,
   no underscores (set, ask, getName, ...)
- names of variables and constants: same as for routines
   (true, false, applicationName, ...)
- names of constants, representing Win32 API constants and function names:
   literal copy of original (WM_PAINT, SetVisible, ...)

Because Win32Lib API functions are usually CamelCased, and routines in Win4Eu
have a lower case first letter, I don't have to worry about using similar
names: I can use both the routine setVisible, and the API constant SetVisible.

--
The Internet combines the excitement of typing 
with the reliability of anonymous hearsay.
tommy online: http://users.telenet.be/tommycarlier
tommy.blog: http://tommycarlier.blogspot.com

new topic     » goto parent     » topic index » view message » categorize

8. Re: Aesthetically pleasing identifier names

> posted by: D. Newhall <derek_newhall at yahoo.com>
>
> I used to use CamelCaps but now I've switched to foo_bar instead of FooBar
for most identifiers. However, it depends on the language I'm using as I try
to keep a similar naming convention to how the language tends to do it
(although I can't stand fooBar since I think it's stupid to leave the first
character of a word you'd normally capitalize lowercase even though you
capitalize everything else, Java does this). In Euphoria it's almost always
foo_bar since all the standard libraries use this method.
>

I usually use fooBar style for variables *local* to a routine, just in case
I (foolishly?) might refer to a non-local variable in the same routine,
which would be FooBar style; that way I can tell at a glance what scope they
have.

Dan Moyer

new topic     » goto parent     » topic index » view message » categorize

9. Re: Aesthetically pleasing identifier names

I try using the following philosophy when programming in Euphoria;
I use these prefixes for the following variable types;
(I use 'CamelBack' naming method)
	c	cVar	Character code. (ATOM)
	h	hVar	Handle
	s	sVar	String / Single line of readable text.
	i	iVar	Single index / pointer
	j	jVar	Sequence of indexes / pointers.
	o	oVar	Object / Sequence of arbitrary data / binary data (ie. a file)
	q	qVar	seQuence of readable text / numbers / Lists
	n	nVar	Number; Atom, integer, single, double, etc. etc.
	b	bVar	Boolean; Yes / True / On, No / False / Off
	d	dVar	Date
	e	eVar	paramEter variable of any type.
	f	fFunc	Function
	p	pProc	Procedure

(For global variables, I add a 'g', ie. qgMyList.)

It might seems like over the top, but I've used it for a long time, and it
helps me paint a good picture when reviewing old code. As for the nVar, I 
decided not to split it into special naming methods for single/double, integers,
etc., because I want the name itself to describe what number type it is, ie.
nMyMoneyAccount (Bill Gates would need a double - and then some, mine just 
signed byte :P)

As for controls and forms for Win32Lib / and other winlib libraries, I use
for example these prefixes;
  frmXXXX    frmLogon
  btnXXXX    btnClose
  lviXXXX    lviMyFiles            lvi - List View
  tcoXXXX    tcoCollection         tco - Tab Control
  tabXXXX    tabFiles
  mnuXXXX    mnuFile               (Main menu)
  mniXXXX    mnuFileLoad           (Menu item)
etc. etc.

If I have several forms in my code, I try (if it's not already too late..)
to include the name of the form in the control, ex. btnLogonClose, where
ofcourse the form is called Logon.. I do try to keep the length of the var
to a minimum, but readablilty comes first..

Kenneth / ZNorQ

Brent W. Hughes wrote:
> 
> When I was a young and tender programmer, if I wanted to declare a function
> to, say,
> set a menu bar to a certain value, I would probably name the function
> something like
> "smb" which of course, stood for "set menu bar".
> 
> After a few years, I decided that that was not very self-documenting, so I
> would name
> such a variable "setmenubar".  This made the code more readable and was worth
> the extra
> typing.
> 
> Sometime later, I saw people using underscores in their identifier names, and
> I decided
> to give that a try.  My function would hence be called "set_menu_bar".
> 
> Still years later, I began to see people using case to separate the individual
> words
> in an identifier name.  I tried it.  My function would now be called
> "SetMenuBar".
>  I found my code to be more readable and much more aesthetically pleasing.  In
>  fact,
> I have become a convert to this way of naming identifiers.  As a convert, I am
> now
> trying to get others to see the light so that it will be easier to read their
> code.
> 
> What do you think?
> 
> Brent
>

new topic     » goto parent     » topic index » view message » categorize

10. Re: Aesthetically pleasing identifier names

Brent W. Hughes wrote:

>When I was a young and tender programmer, if I wanted to declare
>a function to, say, set a menu bar to a certain value, I would
>probably name the function something like "smb" which of course,
>stood for "set menu bar".
>...
>identifier names, and I decided to give that a try.  My function
>would hence be called "set_menu_bar".
>...
>I tried it.  My
>function would now be called "SetMenuBar". I found my code to be
>more readable and much more aesthetically pleasing.  In fact, I
>have become a convert to this way of naming identifiers.
>...
>What do you think?

I've followed a similar path.  In the late 70's I used the smb.
In the 80's I used the set_menu_bar.  In the 90's I went with
SetMenuBar.

Now, since 2000, I've decided that SetMenuBar is ugly, and even
hard to read sometimes, and have gone back to set_menu_bar, which
is much easier for me to read.

For example, look at this function, taken straight from the win32
API:

AddSectionKeyFileToCopyList(szSect, szKey, szSrc, szDest);

vs.

add_section_key_file_to_copy_list(sect, key, src, dst);

It takes me a second to read the first one, but I can immediately
read the 2nd one, as the '_' clearly separates the words.

YMMV, VWP, NW

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu