Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General Question about programming style

Status
Not open for further replies.

shetlandbob

Programmer
Mar 9, 2004
528
GB
Hi,

I was wondering does everyone program using the "hungarian" notation for variables as I understand its known,
see if you dont know what that is?

I was curious, cause well I never have. I've been programming for about 3 years in total and have always written the whole kit and caboodle myself, i.e. front end, back end, guts and all.
 
Let's forget the hungarian notation...
Let MS men play with it (it's MS invention)...
Well, sometimes we have read MS sources, so it's OK to know anything about these fancy prefixes...
 
It is not a MS invetion, it was invented a long time ago, but MS decided to use that style in MFC, wich was a quite unfortunate descicion.

See the last posts in thread116-712299 on why you should avoid it.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Ah, indeed a very interesting thread!

Plus slap over the wrist for me for not doing a search on the topic!!

I think the general lesson is, as long as you have some format that is consistent then that's the main thing!

I have my own style that I have always used and think it would be hard to change now (not that i was planning on it!)
 
>I think the general lesson is, as long as you have some format that is consistent then that's the main thing!

It is also quite important that all developers twiddling in the same code use the same style.

>I have my own style

Good for you, if you're working solo :)

If you're working in a team of developers I should hope the style is based on some coding guideleines in common for the whole team/project.



/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
I'm working solo, so I get to set the coding guidelines/style (i.e. mine!!)

Yes, I agree if your working as part of a team on a large project(s) then a similar style across the development team would be paramount.

But for the foreseeable future I will be on my own, so for now it'll stay the way it is.
 
>But for the foreseeable future I will be on my own

You don't know how lucky you are....

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
I have to say that for anyone using a modern IDE, the changing data types argument against hungarian notation is lame and irrelivent. Let me teach you something: Ctrl+H = find and replace. If I ever change a variable type, I can change every reference to it in five seconds per file. The vast majority of my variables are only referenced in one file. How often do you people even change data types? I almost never do, because I know what it's supposed to do when I first create it, and that function almost never changes.

Here's another rant based on what PurfNurt said in the other thread about globals. I certainly agree that using globals is generally bad, however, there are times when it is acceptable to use globals IMO. For example, in a game I am writing I could have every class store it's own pointer to the D3D device for rendering. Or I could make it global, which I do. Making it global is totally safe, because creating it is basically the first thing I do and releasing it is the last thing I do. It will never be messed with outside of that, so using it is totally safe. I am by no means advocating the use of globals in general, but there are rare occasions that using them increases productivity and makes the coding easier without making it more accident-prone. By making something like globals taboo in every situation, you are only shooting yourself in the foot.

I use Hungarian notation in my code but only insomuch as it is helpful to others (or myself). You should use any technique that is helpful to you and others, but don't stick to it when it becomes annoying. Many programmers are hardcore one way or another, and both groups suffer because of it.
 
>for anyone using a modern IDE...find and replace

I have to say that for anyone using a modern IDE type information is presented with a hover of the mouse or similar.

>If I ever change a variable type, I can change every reference to it in five seconds per file.

Cool. That is however an issue I dont even have to think about.

>How often do you people even change data types?

It happens. For me its not a big deal. I just change it. In any case I most certainly dont want my code to discourage me from changing it.

>and that function almost never changes.

Ok. Cool. Im my experiance there's a number of reasons for chainging the code:
Requirements change, you fix bugs, you learn better ways to do stuff. Of these 3 reasons only 1 has to to with how correct the function was from the beginning.

I want the code to be as easy to change as possible. There are a lot of "tools" that can be helpful in that where probably the most trivial tool is not coding typeinfo into the variable name.

>By making something like globals taboo in every situation, you are only shooting yourself in the foot.

Another such "tool" is unit testing which helps ensuring that I dont break anything when I fiddle about on the code. And with unit testing comes the requirement that code should be testable. One lesson I've learned (the hard way) is that when you have global dependencies it's difficult to test the code properly.

Example:I want to test the class Foo, preferably in a "Foo only" environment. I want to stub the classes Foo depends on (I test them elsewhere). But I can't really stub whatever "globals" Foo has.

How would you unit test the code that's dependant on the global D3D gizmo without instantiating a real device? My guess is that you don't.

I don't mean to flame, Im sure you know what youre doing and your globals is perfectly fine. Every rule has its exceptions.

Anyway, my prime concern is to make code modifiable and correct (=right functions and bug free) in combination. I've found that H.N. and globals counter that.


/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Good points, Per. You're right about the IDE showing type when hovering the cursor over it, but that takes longer (have to move the mouse and let it sit for a couple seconds), and very often it gets confused and doesn't find it or gives me the same variable name in a different class. Then again, you have far more programming experience than me, and your arguments certainly make sense, so he is probably better off taking your advice over mine :).
 
when working in some development team is very probable what you will have to learn some new coding convention. Anyway, from each convensions you will find which one best fits to you. Maybe you will have to use many conventions for different customers, because often customers require using some coding conventions. These conventions could be negotiated. Easily learning and using required coding conventions is very important. Also very important is you to have your own style. This style may change, improve during the time. If you don't have it, you will not be able to create big projects when is no some convention aggreed to use.

Ion Filipski
1c.bmp
 
Thanks for all the info, I agree with all the statements made.

It is important to have a style that is easy to understand and follow, this is true not only for someone else picking up your code should you move onto brighter and greener pastures but also if you have to go back to a project you worked on say, 6 months ago. Although you would have known the project like the back of your hand when it was being developed, if your anything like me it takes a bit to figure it out again if you havn't had to look at it for 6 months!! So if you have a clear and easy to understand style then it would be far easier to pick up again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top