Quantcast
Channel: Bacon Bits
Viewing all articles
Browse latest Browse all 33

Me vs Hungarian Notation

0
0

Hungarian Notation is a coding convention that many programmers use to (presumably) make their code more understandable.

It involves prefixing variable names with a kind of code that describes the “type” of variable you’re seeing in the code.

For example, if a variable is a Range object, you would name that variable rngSomeName.

Prefixing the variable name with rng allows the reader of the code to immediately know the variable is a range.

Here is a table of a few commonly used Excel objects and the universally agreed upon Hungarian Notation for each.

Variable Type

Hungarian Notation

Boolean

bln

ChartObject

cho

Collection

col

Comment

cmt

Date

dat

Double

dbl

Long

lng

Object

obj

Pivot Table

pvt

Range

rng

Shape

shp

String

str

Variant

var

Workbook

wbk

Worksheet

wks

 

I personally go through periods of really trying to use Hungarian Notation (mainly out of the fear that I’m a hack).

But I inevitably abandon the effort.

Mostly because I just can’t be bothered. I mean let’s face it. I’m not building the next PayPal here. Most of my code is for me to figure out.

Also, I feel as long as my variable declarations are reasonably close to the point where I use them, I can quickly look at the declaration if I have to.

AND

To some extent (like one commenter wrote on Stack Overflow):

“vUsing adjHungarian nNotation vMakes nReading nCode adjDifficult”

 

My Fool-Proof System

I thought it would be fun to list my amazing system of naming variables.

Try not to faint from the brilliance.

I’m a tired 45 years of age (and this table really shows it).

Variable
Type

What I Typically Use

Boolean

blnSomeName

ChartObject

MyChart

Collection

MyCollection

Comment

MyComment

Date

MyDate

Double

x

Long

x

Object

MyObject

Pivot Table

MyPivot

Range

MyRange

Shape

MyShape

String

MyString

Variant

Arr (typically an array)

Workbook

wb

Worksheet

ws

 

Maybe, one day, I’ll come up with a serious naming convention that will change the face of programming. Although, that’s not likely.

Feel free to share any thoughts on the naming conventions you use.

 

 


Viewing all articles
Browse latest Browse all 33

Latest Images

Trending Articles





Latest Images